Compare commits

...

4 Commits

Author SHA1 Message Date
f2471555fd Merge branch 'master' of github.com:brunofontes/linuxShortcuts 2022-03-04 14:07:50 -03:00
7a381cea26 yay: including the more than necessary diff of pkgbuild files 2022-02-20 10:27:22 -03:00
2964dc1404 Generic updates on laptop
Again, I don't need to keep track of the changes. Just a matter of
having them here.
2021-12-24 11:01:28 -03:00
70ad44ed59 Renaming testDNS to fix-dns as it were not working properly
It appears systemd does not like upcase names. systemctl status were not
working with the uppercase name, but it worked with the lowercase one
2019-04-29 10:32:19 -03:00
6 changed files with 47 additions and 13 deletions

View File

@ -5,7 +5,7 @@ OnFailure=logErrors@%n.service
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/bin/systemctl restart openvpn-client@privatvpn.service ExecStart=/bin/sh /home/bruno/Apps/linuxShortcuts/Services/afterWakeUp.sh
[Install] [Install]
WantedBy=suspend.target 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,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() { function isDNSWorking() {
dnsWorking=$(dig brunofontes.net | grep "ANSWER: 0") return $(dig brunofontes.net | grep "ANSWER: 0")
} }
logfile="/var/log/bfontes" logfile="/var/log/bfontes"
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" >> "$logfile" sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" | sudo tee -a "$logfile"
isDNSWorking dnsWorking=`isDNSWorking`
echo "$dnsWorking"
if [ "$dnsWorking" ]; then 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 chattr -i /etc/resolv.conf
sudo sed -i 's/127.0.0.2/9.9.9.9/' /etc/resolv.conf 2>>"$logfile" sudo sed -i 's/127.0.0.2/9.9.9.9/' /etc/resolv.conf 2>>"$logfile"
sudo chattr +i /etc/resolv.conf 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 online 2>"$logfile"
sudo chronyc -a 'burst 4/4' sudo chronyc -a 'burst 4/4'
i=0 i=0
while [ "$dnsWorking" -a $i -le 4 ]; do 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 sleep 20
isDNSWorking dnsWorking=`isDNSWorking`
i=$(( "$i" + 1 )) i=$(( "$i" + 1 ))
done done
if [ -z "$dnsWorking" ]; then 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 else
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Script has failed..." >> "$logfile" 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" >> ~/.log_error sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Fixing DNS script has failed. More details on $logfile" | sudo tee -a ~/.log_error
fi 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 chattr -i /etc/resolv.conf
sudo sed -i 's/9.9.9.9/127.0.0.2/' /etc/resolv.conf sudo sed -i 's/9.9.9.9/127.0.0.2/' /etc/resolv.conf
sudo chattr +i /etc/resolv.conf sudo chattr +i /etc/resolv.conf
fi 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"