container-expire-notifs/enable-expire-notifs.sh

29 lines
927 B
Bash
Raw Permalink Normal View History

2024-06-19 01:03:12 -04:00
#!/bin/bash
2024-06-19 01:22:11 -04:00
API_HOST="https://api.ssh.surf"
API_KEY="$1"
[ -z $API_KEY ] && echo "You need to provide your api key for this thing to work.
2024-06-19 01:22:11 -04:00
It is strongly advised enabling privacy mode (\`/privacy\`) for the time of execution" && exit 1
hello=$(curl -w %{http_code} -sH "x-ssh-auth: $API_KEY" $API_HOST/hello -o /dev/null)
if [[ hello -ne 200 ]]; then
echo "token not valid, exiting"
exit 1
fi
2024-06-19 04:35:24 -04:00
echo $API_KEY > /var/tools/container-expire-notifs/.api-key
2024-06-19 04:35:24 -04:00
[ ! which at ] && sudo apt install at
date=$(curl -sH "x-ssh-auth: $API_KEY" $API_HOST/time | grep -o '"expireDate":"[^"]*' | grep -o '[^"]*$')
2024-07-25 02:31:10 -04:00
if ! grep -q "atd" /start.sh; then sed -i -e 's/#s2lmain/atd/g' /start.sh; fi
2024-06-19 04:35:24 -04:00
atd
at -t $(date -d $date +'%Y%m%d%H%M') -f /var/tools/container-expire-notifs/notify.sh
2024-06-19 04:35:24 -04:00
notif "Container expiration notifications brought back successfully!"
2024-06-19 05:08:38 -04:00
notif "**WARNING**: If your container is off you may not receive the reminder"