refactor: update skeleton and scripts
This commit is contained in:
parent
fad2dcf339
commit
07994c11c5
7 changed files with 18 additions and 24 deletions
100
skel/opt/scripts/ntfy.sh
Normal file
100
skel/opt/scripts/ntfy.sh
Normal file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ntfy_username=""
|
||||
ntfy_password=""
|
||||
ntfy_token=""
|
||||
|
||||
help()
|
||||
{
|
||||
echo "Options:"
|
||||
echo "-t Set the title of a message."
|
||||
echo "-m Your message."
|
||||
echo "-p Notification priority, 1-5, 5 is the highest. (Optional)"
|
||||
echo "-e Choose emoji. (https://ntfy.sh/docs/emojis/?h=emo)"
|
||||
echo "-s Set the token for a message from a file"
|
||||
echo "-u specify url"
|
||||
echo "-h Print this help."
|
||||
echo
|
||||
echo "If you want to show if the last command was successful or not, you can do something like this:"
|
||||
echo "yourcommand ; export le=$? ; /path/to/ntfy.sh"
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
while getopts "t:m:p:e:s:u:h" option; do
|
||||
case $option in
|
||||
t) ntfy_topic="$OPTARG";;
|
||||
m) ntfy_message="$OPTARG";;
|
||||
p) ntfy_prio="$OPTARG";;
|
||||
e) ntfy_emoji="$OPTARG";;
|
||||
s) ntfy_token="$(cat $OPTARG)";;
|
||||
u) ntfy_url="$OPTARG";;
|
||||
h) help
|
||||
exit;;
|
||||
\?)
|
||||
echo "Error: Invalid option"
|
||||
exit;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [ -z "$ntfy_message" ]; then
|
||||
ntfy_message="Done"
|
||||
fi
|
||||
|
||||
if [ "$ntfy_prio" == "1" ]; then
|
||||
ntfy_prio="min"
|
||||
ntfy_tag="white_small_square"
|
||||
elif [ "$ntfy_prio" == "2" ]; then
|
||||
ntfy_prio="low"
|
||||
ntfy_tag="computer"
|
||||
elif [ "$ntfy_prio" == "3" ]; then
|
||||
ntfy_prio="default"
|
||||
ntfy_tag="computer"
|
||||
elif [ "$ntfy_prio" == "4" ]; then
|
||||
ntfy_prio="high"
|
||||
ntfy_tag="warning"
|
||||
elif [ "$ntfy_prio" == "5" ]; then
|
||||
ntfy_prio="max"
|
||||
ntfy_tag="rotating_light"
|
||||
else
|
||||
ntfy_prio="default"
|
||||
ntfy_tag="computer"
|
||||
fi
|
||||
|
||||
if [ -n "$ntfy_emoji" ]; then
|
||||
ntfy_tag="$ntfy_emoji"
|
||||
fi
|
||||
|
||||
if [ -n "$le" ]; then
|
||||
if [ "$le" == "0" ]; then
|
||||
ntfy_tag="heavy_check_mark"
|
||||
else
|
||||
ntfy_tag="x"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$ntfy_topic" ]; then
|
||||
ntfy_topic="$HOSTNAME"
|
||||
fi
|
||||
|
||||
if [[ -n $ntfy_password && -n $ntfy_token ]]; then
|
||||
echo "Use ntfy_username and ntfy_password OR ntfy_token"
|
||||
exit 1
|
||||
elif [ -n "$ntfy_password" ]; then
|
||||
ntfy_base64=$( echo -n "$ntfy_username:$ntfy_password" | base64 )
|
||||
ntfy_auth="Authorization: Basic $ntfy_base64"
|
||||
elif [ -n "$ntfy_token" ]; then
|
||||
ntfy_auth="Authorization: Bearer $ntfy_token"
|
||||
else
|
||||
ntfy_auth=""
|
||||
fi
|
||||
|
||||
curl \
|
||||
-X POST \
|
||||
-H "$ntfy_auth" \
|
||||
-H "Title: $ntfy_topic" \
|
||||
-H "Tags: $ntfy_tag" \
|
||||
-H "Priority: $ntfy_prio" \
|
||||
-d "$ntfy_message" \
|
||||
"$ntfy_url"
|
17
skel/opt/scripts/restic/backup.sh
Normal file
17
skel/opt/scripts/restic/backup.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
ntfy() {
|
||||
sh /opt/scripts/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
ntfy -m "performing backup..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//$(hostname)" \
|
||||
-p "/neb/secrets/restic/$(hostname).secret" \
|
||||
backup \
|
||||
--tag auto \
|
||||
/srv /home /etc; then
|
||||
ntfy -m "backup succeeded"
|
||||
else
|
||||
ntfy -m "backup failed" -e "warning,skull"
|
||||
fi
|
21
skel/opt/scripts/restic/forget.sh
Normal file
21
skel/opt/scripts/restic/forget.sh
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
ntfy() {
|
||||
sh /opt/scripts/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
ntfy -m "forgetting old backups..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//$(hostname)" \
|
||||
-p "/etc/ixvd/secrets/restic/$(hostname).secret" \
|
||||
forget \
|
||||
--keep-last 10 \
|
||||
--keep-tag keep \
|
||||
--keep-daily 20 \
|
||||
--keep-weekly 20 \
|
||||
--keep-monthly 6 \
|
||||
--keep-yearly 10; then
|
||||
ntfy -m "forget succeeded"
|
||||
else
|
||||
ntfy -m "forget failed" -e "warning,skull"
|
||||
fi
|
15
skel/opt/scripts/restic/prune.sh
Normal file
15
skel/opt/scripts/restic/prune.sh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
ntfy() {
|
||||
sh /opt/scripts/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
ntfy -m "pruning old backups..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//$(hostname)" \
|
||||
-p "/etc/ixvd/secrets/restic/$(hostname).secret" \
|
||||
prune; then
|
||||
notify -m "pruning succeeded"
|
||||
else
|
||||
notify -m "prune failed" -e "warning,skull"
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue