Compare commits

..

No commits in common. "f2471555fd1ac4192249d35fc8d04a92fb41ebfe" and "b926a7c2b4e0cd5afbe511fcc09b76239f4f4568" have entirely different histories.

6 changed files with 13 additions and 47 deletions

View File

@ -5,7 +5,7 @@ OnFailure=logErrors@%n.service
[Service]
Type=simple
ExecStart=/bin/sh /home/bruno/Apps/linuxShortcuts/Services/afterWakeUp.sh
ExecStart=/usr/bin/systemctl restart openvpn-client@privatvpn.service
[Install]
WantedBy=suspend.target

View File

@ -1,11 +0,0 @@
#/bin/sh
sleep 10s
wifi=$(iwconfig 2>/dev/null | grep Quasimodo)
if [[ -z $wifi ]]; then
echo "Starting OPEN VPN"
/usr/bin/systemctl restart openvpn-client@archerc6.service
else
echo "At home, no VPN for you"
/usr/bin/systemctl stop openvpn-client@archerc6.service
fi

View File

@ -1,10 +0,0 @@
[Unit]
Description=Manages Dongle Wifi, DNS and VPN
After=network-online.target
[Service]
Type=oneshot
ExecStart=/bin/bash /home/bruno/Apps/linuxShortcuts/Services/bruno-network-manager.sh
[Install]
WantedBy=network-online.target

View File

@ -1,5 +0,0 @@
#/bin/sh
cd /home/bruno/Apps/linuxShortcuts/Services/
source ./enableDongleWifi.sh
source ./afterWakeUp.sh
source ./fixDNS.sh

View File

@ -1,4 +0,0 @@
#/bin/sh
dongleWifi=$(ip link | grep wlp | grep DOWN | awk '{ print $2 }' | tr -d :)
[ "$dongleWifi" ] && wpa_supplicant -B -i "$dongleWifi" -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

View File

@ -1,41 +1,37 @@
#Aparentemente tem um momento em que quando o dns não está funcionando o dig também não retorna nada, então para o script a conexão está funcionando
source /home/bruno/enableDongleWifi.sh
function isDNSWorking() {
return $(dig brunofontes.net | grep "ANSWER: 0")
dnsWorking=$(dig brunofontes.net | grep "ANSWER: 0")
}
logfile="/var/log/bfontes"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" | sudo tee -a "$logfile"
dnsWorking=`isDNSWorking`
echo "$dnsWorking"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" >> "$logfile"
isDNSWorking
if [ "$dnsWorking" ]; then
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." >> "$logfile"
sudo chattr -i /etc/resolv.conf
sudo sed -i 's/127.0.0.2/9.9.9.9/' /etc/resolv.conf 2>>"$logfile"
sudo chattr +i /etc/resolv.conf
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Forcing time to sync" | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Forcing time to sync" >> "$logfile"
sudo chronyc online 2>"$logfile"
sudo chronyc -a 'burst 4/4'
i=0
while [ "$dnsWorking" -a $i -le 4 ]; do
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Waiting..." | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Waiting..." >> "$logfile"
sleep 20
dnsWorking=`isDNSWorking`
isDNSWorking
i=$(( "$i" + 1 ))
done
if [ -z "$dnsWorking" ]; then
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" >> "$logfile"
else
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Script has failed..." | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Fixing DNS script has failed. More details on $logfile" | sudo tee -a ~/.log_error
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Script has failed..." >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Fixing DNS script has failed. More details on $logfile" >> ~/.log_error
fi
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." >> "$logfile"
sudo chattr -i /etc/resolv.conf
sudo sed -i 's/9.9.9.9/127.0.0.2/' /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
fi
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Done" | sudo tee -a "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Done" >> "$logfile"