diff --git a/get-hosts.sh b/get-hosts.sh index 26f7ca8..5cc1b8a 100755 --- a/get-hosts.sh +++ b/get-hosts.sh @@ -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