#!/bin/bash

## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit
shopt -s shift_verbose

while read -r -d $'\n' line ; do
   read -r first_word second_word _ <<< "${line}"
   temp="${first_word}"
   temp="$(printf '%s\n' "${temp}" | str_replace "http://" "")"
   plain_url="$(printf '%s\n' "${temp}" | str_replace "https://" "")"
   ## web.archive.org did not support tlsv1.3 at time of writing.
   if scurl --tlsv1.2 --silent --location "${second_word}" | grep -F -- "${plain_url}" > /dev/null ; then
      continue
   fi
   printf '%s\n' "Failed!"
   printf '%s\n' "scurl --tlsv1.2 --silent --location ${second_word}"
   printf '%s\n' "plain_url: ${plain_url}"
   printf '%s\n' "second_word: ${second_word}"
   printf '%s\n' ""
done < <( /usr/share/sdwdate/onion-list-all )
