#!/bin/bash
#
#if ifconfig -a | grep -q 'wlan0' ; then
#   echo "Esta Tudo ok com WIFI!!"
#else
#   echo "Reiniciando o WIFI ok!!"
#   /usr/sbin/usb_modeswitch -KW -v 0bda -p 1a2b
#fi
#
#sleep 5
#
if ! /usr/bin/systemctl status nmbd smbd | grep -Eq "failed|inactive"; then 
   echo "Esta Tudo ok com Samba!!"
else
   echo "Reiniciando o Samba ok!!"
   /usr/bin/systemctl restart nmbd smbd
fi
#
sleep 5
#
if /usr/bin/systemctl status tailscaled | grep -q 'inactive'; then 
   echo "Iniciando o TailScale!!"
   /usr/bin/systemctl restart tailscaled
else
   if /usr/bin/tailscale funnel status | grep -q '8443'; then
      echo "Esta Tudo ok com TailScale!!"
   else
      echo "Reiniciando o TailScale!!"
      /usr/bin/tailscale funnel --bg --https=8443 localhost:1080
   fi
fi
#
sleep 5
#
#/usr/bin/curl -s http://radiom7b.dyndns.org:1010 -o /tmp/log.txt
#
/usr/bin/curl -s http://localhost:1080 -o /tmp/log.txt
#
if /usr/bin/systemctl status ezstream | grep -q 'inactive'; then 
   echo "Iniciando o EzStream ok!!"
   /usr/bin/systemctl restart ezstream
else
   if ! /usr/bin/grep -q 'Unspecified description' /tmp/log.txt; then
      echo "Esta Tudo ok com EzStream!!"
   else
      echo "Reiniciando o EzStream ok!!"
      /usr/bin/systemctl restart ezstream
   fi
fi
#
sleep 5
#
#if /usr/bin/mount | grep -q '/dev/sda1 on'; then
#   echo "Esta Tudo ok com USB!!"
#else
#   echo "Reiniciando o USB!!"
#   /usr/bin/mount -a
#fi
#
