commit 056c4635291194c245622afadb9e989f8959332b
parent 03ff4a68a3c9083f20c5a27fa0da133d64945e55
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Fri,  4 Sep 2020 20:06:57 +0200

Design notify to be an executable on PATH

Rename notify.sh to notify and add it to your PATH (or copy it to
/usr/local/bin/notify).

Diffstat:
Mcheck-changes-website.sh | 7++++---
Mlogin-notify.sh | 8+++++---
Mnotify.sh | 17+++++++----------
Mwebsite-backup.sh | 6++++--
4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/check-changes-website.sh b/check-changes-website.sh @@ -16,9 +16,10 @@ # Script that notifies through Gotify when a website has changed. -# File must implement notify funtion -FILE_DIR="$(dirname "$(realpath "$0")")" -. "$FILE_DIR/notify.sh" +# This scripts assumes there is an executable called "notify" in your PATH that +# takes two arguments (the first one is the notification title and the second +# one is the message). + URLS="${XDG_CONFIG_HOME:-$HOME/.config}/osf/urls-check-changes.txt" [ ! -f "$URLS" ] && echo "Error: $URLS is not a file." && exit 1 diff --git a/login-notify.sh b/login-notify.sh @@ -14,10 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -# Script that notifies Gotify when someone logs in through SSH to a computer/server. +# Script that sends a notification when someone logs in through SSH to a +# computer/server. -# File must implement notify funtion -. "$(dirname "$(realpath "$0")")/notify.sh" +# This scripts assumes there is an executable called "notify" in your PATH that +# takes two arguments (the first one is the notification title and the second +# one is the message). if [ "$PAM_TYPE" != "close_session" ]; then TITLE="SSH login: ${PAM_USER}@$(hostname)" diff --git a/notify.sh b/notify.sh @@ -15,14 +15,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -# Implements notify function, that notifies admin through Gotify. This file is -# imported by other scripts, but it could easily be used on its own adding lines -# that call the function. +# Notifies user using a Gotify instance. -notify() { - GOTIFY_DOMAIN="gotify.oscarbenedito.com" - GOTIFY_TOKEN="$(cat "$(dirname "$(realpath "$0")")/gotify_token.txt")" - curl -X POST "https://$GOTIFY_DOMAIN/message?token=$GOTIFY_TOKEN" \ - -F "title=$1" -F "message=$2" -F "priority=${3:-5}" \ - >/dev/null 2>&1 -} +GOTIFY_DOMAIN="<redacted>" +GOTIFY_TOKEN="<redacted>" + +curl -X POST "https://$GOTIFY_DOMAIN/message?token=$GOTIFY_TOKEN" \ + -F "title=$1" -F "message=$2" -F "priority=${3:-5}" \ + >/dev/null 2>&1 diff --git a/website-backup.sh b/website-backup.sh @@ -18,8 +18,10 @@ # destination files and puts each document in the corresponding file, # adding a date to the filename. -FILE_DIR="$(dirname "$(realpath "$0")")" -. "$FILE_DIR/notify.sh" +# This scripts assumes there is an executable called "notify" in your PATH that +# takes two arguments (the first one is the notification title and the second +# one is the message). + URLS="${XDG_CONFIG_HOME:-$HOME/.config}/osf/urls-backup.txt" BACKUPS="${XDG_DATA_HOME:-$HOME/.local/share}/osf/website-backup"