Files
entropi/src/watchdog.sh
T
Lukas Stancik 8176e71b81 Initial commit
Basic working code that is capable of establishing the Wireguard tunnel given that there is properly configured `.psk` file for at least one known wifi network (see README.md for more details)
2025-02-27 13:59:58 +00:00

38 lines
986 B
Bash
Executable File

#!/bin/sh
current_process=$$
tries=3
some_time=5
kill_child_processes() {
for dir in /proc/[0-9]*; do
process_id=$(cat ${dir}/stat | awk '{print $4}')
child_id=$(cat ${dir}/stat | awk '{print $1}')
if [ ${process_id} -eq $1 ]; then
kill -9 ${child_id}
fi
done
}
trap "kill_child_processes ${current_process} ; kill -9 ${current_process}" SIGTERM SIGINT SIGHUP
while [ $tries -ge 1 ]
do
if ! ping -q -c 1 10.0.22.1 > /dev/null ; then
until ntpd -n -q -p $(nslookup tik.cesnet.cz 1.1.1.1 | grep 'Address' | tail -1 | cut -d ' ' -f 2)
do
rc-service wg-quick.wg0 stop
logger -t ntp_sync "Trying to sync time..."
sleep $some_time &
wait $!
done
rc-service wg-quick.wg0 status | grep "started" || rc-service wg-quick.wg0 start
sleep $some_time &
wait $!
fi
sleep $some_time &
wait $!
tries=$(( $tries - 1 ))
done
exit 0