twitch-notify: reduce tmpdir funnies

This commit is contained in:
yosh 2023-07-25 14:34:16 -05:00
parent f6f454e2bd
commit 080cbd3f97
1 changed files with 6 additions and 5 deletions

View File

@ -24,9 +24,9 @@ clean() {
}
# with the sleep 0.5, 2 tries gives like 99.9% accuracy
MAX_TRIES=2
check() {
tmphtml="$2"
max_tries=2
trap 'innerclean "$tmphtml"' INT HUP TERM EXIT
curl -s -o "$2" -L "https://twitch.tv/$1"
if [ -n "$(pup 'script[type="application/ld+json"]' < "$2")" ]; then
@ -43,7 +43,7 @@ check() {
esac
rm -f "$IMG"
fi
elif [ "$i" -lt "$MAX_TRIES" ]; then
elif [ "$i" -lt "$max_tries" ]; then
i=$((i + 1))
sleep 0.5
check "$1" "$2"
@ -56,17 +56,18 @@ check() {
# janky way to do this but fuck it. easiest one that doesn't get race conditioned
# if a file with their name exists in DIR, they're online
DIR="/tmp/twitch-notify-dir-$USER"
DIR="${XDG_RUNTIME_DIR:-"${TMPDIR:-/tmp}"}/twitch-notify-dir-$USER"
while getopts :t:l OPT; do
case "$OPT" in
t) SLEEP_INTERVAL="$OPTARG" ;; # in seconds, default 180
l) [ -d "$DIR" ] && printf 'ONLINE CHANNELS:\n%s\n' "$(ls -1 "$DIR")" ; exit 0 ;;
l) [ -d "$DIR" ] && printf 'ONLINE CHANNELS:\n' && printf '%s\n' "$DIR"/*; exit 0 ;;
*) fail "unknown option: -$OPTARG" ;;
esac
done
shift "$((OPTIND - 1))"
mkdir "$DIR" || exit 1
# this mkdir should prevent any "someone's trying to override this" type beats
mkdir -m 700 -- "$DIR" || fail "$DIR already exists! remove it if no daemon is running"
trap 'clean' INT HUP TERM EXIT
while