improve check for whether removed hosts are still online

This commit is contained in:
nervuri 2023-04-18 15:12:10 +00:00
parent 3ccabfabef
commit 6017c6bbd2
Signed by: nervuri
GPG Key ID: C4769EEA7BA61672
1 changed files with 14 additions and 2 deletions

View File

@ -69,14 +69,26 @@ finish() {
}
trap finish EXIT
# Check connection to host.
# $1: "" or "tor"
# $2: host[:port]
test_host() {
host="$2"
tor=""
if [ "$1" = "tor" ]; then
tor="--socks 127.0.0.1:9050"
fi
agunua $tor --no-tofu --accept-expired-certificate --ignore-missing-tls-close \
--maximum-time 20 "gemini://$host/" >/dev/null 2>&1
}
# Test if removed hosts are still online.
if [ -f hosts ]; then
echo "Testing removed hosts..."
for removed_host in $(diff hosts "$tempfile" | grep ^\< | cut -c 3-); do
printf "%s" "$removed_host"
# If direct connection fails, try to connect through Tor.
if agunua --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1 || \
agunua --socks 127.0.0.1:9050 --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1; then
if test_host "" "$removed_host" || test_host "tor" "$removed_host"; then
echo " - ONLINE"
# Add removed host back.
hosts="$hosts