Generic updates on laptop

Again, I don't need to keep track of the changes. Just a matter of
having them here.
This commit is contained in:
Bruno F. Fontes 2021-12-24 11:01:28 -03:00
parent 70ad44ed59
commit 2964dc1404
7 changed files with 47 additions and 24 deletions

View File

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

11
Services/afterWakeUp.sh Executable file
View File

@ -0,0 +1,11 @@
#/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

@ -0,0 +1,10 @@
[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

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

4
Services/enableDongleWifi.sh Executable file
View File

@ -0,0 +1,4 @@
#/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,11 +0,0 @@
[Unit]
Description=Test and fix DNS update with wrong time
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart = /bin/bash /home/bruno/Apps/linuxShortcuts/Services/fixDNS.sh
[Install]
WantedBy=multi-user.target

View File

@ -1,37 +1,41 @@
#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() {
dnsWorking=$(dig brunofontes.net | grep "ANSWER: 0")
return $(dig brunofontes.net | grep "ANSWER: 0")
}
logfile="/var/log/bfontes"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" >> "$logfile"
isDNSWorking
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" | sudo tee -a "$logfile"
dnsWorking=`isDNSWorking`
echo "$dnsWorking"
if [ "$dnsWorking" ]; then
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." | sudo tee -a "$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" >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Forcing time to sync" | sudo tee -a "$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..." >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Waiting..." | sudo tee -a "$logfile"
sleep 20
isDNSWorking
dnsWorking=`isDNSWorking`
i=$(( "$i" + 1 ))
done
if [ -z "$dnsWorking" ]; then
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" | sudo tee -a "$logfile"
else
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
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
fi
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." | sudo tee -a "$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" >> "$logfile"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Done" | sudo tee -a "$logfile"