2024-07-11 22:39:14 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
function waitNetwork -a witness
|
|
|
|
set -l timeout (math 10 \* 60)
|
|
|
|
set -l codeFile (mktemp)
|
|
|
|
|
2024-07-14 19:37:39 +00:00
|
|
|
function testNetwork
|
|
|
|
# Ping digitalcourage DNS server
|
|
|
|
# https://digitalcourage.de/
|
2024-10-06 19:25:34 +00:00
|
|
|
ping -q -c1 5.9.164.112 >/dev/null
|
2024-07-14 19:37:39 +00:00
|
|
|
end
|
|
|
|
|
2024-07-11 22:39:14 +00:00
|
|
|
if [ -z "$witness" ]
|
2024-10-31 14:06:58 +00:00
|
|
|
if not testNetwork &>/dev/null
|
2024-10-31 14:16:25 +00:00
|
|
|
tmux new-session -s network -d 'cat /etc/motd; echo "$(tput bold)Please establish an internet connection...$(tput sgr0)"; $SHELL'
|
2024-07-11 22:39:14 +00:00
|
|
|
fish (status filename) true &
|
|
|
|
set -l pid "$last_pid"
|
|
|
|
|
|
|
|
function witnessHandler -V codeFile --on-process-exit "$pid" -a event pid code
|
2024-10-06 19:25:34 +00:00
|
|
|
echo "$code" >"$codeFile"
|
2024-07-11 22:39:14 +00:00
|
|
|
|
|
|
|
if [ "$code" -gt 0 ]
|
|
|
|
echo "Unable to connect to the internet!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-31 14:16:51 +00:00
|
|
|
TMUX="" tmux attach -t network
|
2024-07-11 22:39:14 +00:00
|
|
|
wait "$pid"
|
|
|
|
return "$(cat "$codeFile")"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
set -l x 0
|
|
|
|
|
|
|
|
while true
|
|
|
|
set x (math $x + 1)
|
|
|
|
|
2024-10-31 14:06:58 +00:00
|
|
|
if testNetwork &>/dev/null
|
2024-10-31 14:16:25 +00:00
|
|
|
tmux kill-session -t network &>/dev/null
|
2024-07-11 22:39:14 +00:00
|
|
|
break
|
|
|
|
else
|
2024-10-31 14:16:25 +00:00
|
|
|
not tmux list-sessions -f "#{==:#S,network}" &>/dev/null
|
2024-10-31 14:16:41 +00:00
|
|
|
or test "$x" -gt 120
|
2024-07-11 22:39:14 +00:00
|
|
|
and begin
|
2024-10-31 14:16:25 +00:00
|
|
|
tmux kill-session -t network &>/dev/null
|
2024-07-11 22:39:14 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ -n "$argv" ]
|
|
|
|
waitNetwork $argv
|
|
|
|
end
|