lazily check if onion or i2p sites exist in instances.json before running jq.

This commit is contained in:
Sahal Ansari 2024-07-25 20:26:15 -05:00
parent f19da6ca8d
commit dfba0f285b

View File

@ -728,14 +728,18 @@ main ()
# (a mapfile would not ideal here since a pipe is required, inducing a
# subshell, meaning nothing will actually get added to
# imported_nonwww)
IFS=$'\n' imported_nonwww=($(jq -Mcer '.instances[] | select(.onion or .i2p)' "${import_nonwww_from_file}"))
rc=$?
if [[ ${rc} -ne 0 ]]
then
echo >&2 "Failed to read onion instances from existing JSON file."
return 1
if grep -q ".onion" "${import_nonwww_from_file}" || grep -q ".i2p" "${import_nonwww_from_file}" ; then
IFS=$'\n' imported_nonwww=($(jq -Mcer '.instances[] | select(.onion or .i2p)' "${import_nonwww_from_file}"))
rc=$?
else
rc=0
fi
if [[ ${rc} -ne 0 ]]
then
echo >&2 "Failed to read onion instances from existing JSON file."
return 1
fi
fi
# Check to see if we have tor. If we don't, then we will have to import