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

32 lines
1.0 KiB
Bash
Raw 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 fot this thing to work.
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
mkdir /var/tools/container-expire-notifs
cp /root/container-expire-notifs/notify.sh /var/tools/container-expire-notifs/notify.sh
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 '[^"]*$')
[ if ! grep atd /start.sh ] sed -i -e 's/#s2lmain/atd/g' /start.sh
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"