2024-09-07 19:38:07 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-09-08 00:33:13 -07:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2024-09-07 19:38:07 -07:00
|
|
|
BASE_URL=https://archive.is/timegate
|
2024-09-08 00:33:13 -07:00
|
|
|
ARCHIVE_URL=https://archive.is/?url
|
2024-09-07 19:38:07 -07:00
|
|
|
BROWSER=firefox
|
|
|
|
|
|
|
|
check() {
|
|
|
|
article="$1"
|
|
|
|
if [ -z "$article" ]; then
|
|
|
|
echo "Please provide an article to archive" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-09-08 00:33:13 -07:00
|
|
|
if https --verify no "$BASE_URL/$article" | grep -iq "archive this url"; then
|
|
|
|
echo "Article not found in archive... archiving now" >&2
|
|
|
|
$BROWSER "$ARCHIVE_URL=$article"
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-09-07 19:38:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while getopts "o:p:" opt; do
|
|
|
|
case $opt in
|
|
|
|
o)
|
|
|
|
article="$OPTARG"
|
|
|
|
check "$article"
|
|
|
|
$BROWSER "$BASE_URL/$article"
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
article="$OPTARG"
|
|
|
|
check "$article"
|
|
|
|
printf "%s\n" "$BASE_URL/$article"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: $OPTARG" >&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|