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)
38 lines
986 B
Bash
Executable File
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
|