diff --git a/common/ntfy.sh b/common/ntfy.sh index 6fddb7d..01048c4 100644 --- a/common/ntfy.sh +++ b/common/ntfy.sh @@ -7,9 +7,12 @@ 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:" @@ -18,12 +21,14 @@ help() } -while getopts "t:m:p:e:h" option; do +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};; + 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;; \?) @@ -85,10 +90,11 @@ else ntfy_auth="" fi -curl -s \ +curl \ + -X POST \ -H "$ntfy_auth" \ -H "Title: $ntfy_topic" \ -H "Tags: $ntfy_tag" \ -H "Priority: $ntfy_prio" \ -d "$ntfy_message" \ - "$1" > /dev/null \ No newline at end of file + "$ntfy_url" \ No newline at end of file diff --git a/common/restic/backup.sh b/common/restic/backup.sh index d7434d7..eded6dd 100644 --- a/common/restic/backup.sh +++ b/common/restic/backup.sh @@ -1,13 +1,17 @@ #!/bin/sh -/neb/common/ntfy.sh -m "performing backup..." -e "warning" https://push.ixvd.net/infra-backups +ntfy() { + sh /neb/common/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//backups/restic-$(hostname)" \ -p "/neb/secrets/restic/$(hostname).secret" \ backup \ --tag auto \ /srv /home /etc; then - /neb/common/ntfy.sh -m "backup succeeded" -e "warning" https://push.ixvd.net/infra-backups + ntfy -m "backup succeeded" else - /neb/common/ntfy.sh -p "urgent" -m "backup failed" -e "warning,skull" https://push.ixvd.net/infra-backups + ntfy -m "backup failed" -e "warning,skull" fi \ No newline at end of file diff --git a/common/restic/forget.sh b/common/restic/forget.sh index 6d14cc4..8119eb0 100644 --- a/common/restic/forget.sh +++ b/common/restic/forget.sh @@ -1,14 +1,10 @@ #!/bin/sh -notify() { - curl \ - -X POST \ - -H "Authorization: $(cat ${NTFY_SECRET_FILE:-/etc/ixvd/secrets/ntfy/infra-backups})" \ - -d "$(hostname): $@" \ - https://push.ixvd.net/infra-backups +ntfy() { + sh /neb/common/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@" } -notify "forgetting old backups..." +ntfy -m "forgetting old backups..." if restic \ -r "sftp://ixvd_backup_storage//backups/restic-$(hostname)" \ -p "/etc/ixvd/secrets/restic/$(hostname).secret" \ @@ -19,7 +15,7 @@ if restic \ --keep-weekly 20 \ --keep-monthly 6 \ --keep-yearly 10; then - notify "forget succeeded" + ntfy -m "forget succeeded" else - notify "forget failed" + ntfy -m "forget failed" -e "warning,skull" fi diff --git a/common/restic/prune.sh b/common/restic/prune.sh index 409523c..b62b874 100644 --- a/common/restic/prune.sh +++ b/common/restic/prune.sh @@ -1,13 +1,15 @@ #!/bin/sh -notify() { - curl \ - -X POST \ - -H "Title: $0" \ - -H "Priority: urgent" \ - -H "Tags: warning" \ - -d "$(hostname): $@" \ - https://push.ixvd.net/infra-backups +ntfy() { + sh /neb/common/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@" } -notify "pruning old backups..." +ntfy -m "pruning old backups..." +if restic \ + -r "sftp://ixvd_backup_storage//backups/restic-$(hostname)" \ + -p "/etc/ixvd/secrets/restic/$(hostname).secret" \ + prune; then + notify -m "pruning succeeded" +else + notify -m "prune failed" -e "warning,skull" +fi \ No newline at end of file diff --git a/setup.sh b/setup.sh index 7145bd3..18a4446 100644 --- a/setup.sh +++ b/setup.sh @@ -26,4 +26,7 @@ if ! [ -d "/neb" ]; then fi if ! [ -d "/etc/cron.d/restic.crontab" ]; then - echo "setting up \ No newline at end of file + echo "setting up restic cron" + mkdir -p /etc/cron.d/ + cp /neb/common/restic/restic.crontab /etc/cron.d/restic.crontab +fi \ No newline at end of file