commit 121c219cd5edea7b9492dca1dd213f43370e8a58
parent e4b72a232df69e8b8a8f16db4beb807cb99a8a5d
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Sat, 13 Dec 2025 01:24:02 +0100
Allow passing options as env variables
Diffstat:
5 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/check-changes-website.sh b/check-changes-website.sh
@@ -8,9 +8,9 @@
# 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"
+URLS_FILE="${URLS_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/osf/urls-check-changes.txt}"
-[ ! -f "$URLS" ] && echo "Error: $URLS is not a file." && exit 1
+[ ! -f "$URLS_FILE" ] && echo "Error: $URLS_FILE is not a file." && exit 1
check_and_notify() {
newhash="$(curl "$1" 2>/dev/null | sha256sum | cut -f 1 -d " ")"
@@ -20,7 +20,7 @@ check_and_notify() {
while read -r url hash title
do
check_and_notify "$url" "$hash" "$title"
-done < "$URLS"
+done < "$URLS_FILE"
# Can also be used by calling check_and_notify directly. Example:
# check_and_notify url hash title
diff --git a/check-disk-usage.sh b/check-disk-usage.sh
@@ -5,7 +5,7 @@
tmp="$(df -Ph | grep ' /$')"
used="$(echo "$tmp" | awk {'print $5'})"
left="$(echo "$tmp" | awk {'print $4'})"
-max=80
+max=${MAX_THRESHOLD:-80}
if [ "${used%?}" -ge "${max}" ]; then
notify "Disk usage warning" "$(hostname) has used $used of its disk space. Space left: $left."
diff --git a/davup.sh b/davup.sh
@@ -4,20 +4,20 @@
# DAVup: back up calendars and contacts from a DAV server (CalDAV and CardDAV).
-domain="<DAV server address>" # example: https://dav.mailbox.org (no trailing "/")
-user="<username>"
-pass="<password>"
+DAV_DOMAIN="${DAV_DOMAIN:-dav_server_address}" # example: https://dav.mailbox.org (no trailing "/")
+DAV_USER="${DAV_USER:-dav_user}"
+DAV_PASS="${DAV_PASS:-dav_pass}"
get_cal() {
- curl -s -X "PROPFIND" -u "${user}:${pass}" -H "Content-Type: text/xml" -H "Depth: 1" \
+ curl -s -X "PROPFIND" -u "${DAV_USER}:${DAV_PASS}" -H "Content-Type: text/xml" -H "Depth: 1" \
--data "<propfind xmlns='DAV:'><prop><calendar-data xmlns='urn:ietf:params:xml:ns:caldav'/></prop></propfind>" \
- "${domain}/${resource}"
+ "${DAV_DOMAIN}/${resource}"
}
get_card() {
- curl -s -X "PROPFIND" -u "${user}:${pass}" -H "Content-Type: text/xml" -H "Depth: 1" \
+ curl -s -X "PROPFIND" -u "${DAV_USER}:${DAV_PASS}" -H "Content-Type: text/xml" -H "Depth: 1" \
--data "<propfind xmlns='DAV:'><prop><address-data xmlns=\"urn:ietf:params:xml:ns:carddav\"/></prop></propfind>" \
- "${domain}/${resource}"
+ "${DAV_DOMAIN}/${resource}"
}
process_cal() {
@@ -57,6 +57,6 @@ process_card() {
done
}
-# examples (resource address will be "${domain}/${resource}"):
+# examples (resource address will be "${DAV_DOMAIN}/${resource}"):
# resource="caldav/mycal" && get_cal | process_cal > calendar_and_todos.ics
# resource="carddav/mycard" && get_card | process_card > contacts.vcf
diff --git a/notify.sh b/notify.sh
@@ -4,9 +4,9 @@
# Gotify notify: notifies user using a Gotify instance.
-GOTIFY_DOMAIN="<redacted>"
-GOTIFY_TOKEN="<redacted>"
+GOTIFY_DOMAIN="${GOTIFY_DOMAIN:-redacted}"
+GOTIFY_TOKEN="${GOTIFY_TOKEN:-redacted}"
curl -X POST "https://$GOTIFY_DOMAIN/message?token=$GOTIFY_TOKEN" \
- -F "title=$1" -F "message=$2" -F "priority=${3:-5}" \
+ -F "title=${1:- }" -F "message=${2:-No message.}" -F "priority=${3:-5}" \
>/dev/null 2>&1
diff --git a/website-backup.sh b/website-backup.sh
@@ -10,15 +10,15 @@
# 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"
+URLS_FILE="${URLS_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/osf/urls-backup.txt}"
+TARGET_DIR="${TARGET_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/osf/website-backup}"
-[ ! -f "$URLS" ] && echo "Error: $URLS is not a file." && exit 1
+[ ! -f "$URLS_FILE" ] && echo "Error: $URLS_FILE is not a file." && exit 1
backup() {
- mkdir -p "$BACKUPS/$2"
- output="$BACKUPS/$2/$(date +"%Y-%m-%d")-$2"
- last="$BACKUPS/$2/$(date --date="yesterday" +"%Y-%m-%d")-$2"
+ mkdir -p "$TARGET_DIR/$2"
+ output="$TARGET_DIR/$2/$(date +"%Y-%m-%d")-$2"
+ last="$TARGET_DIR/$2/$(date --date="yesterday" +"%Y-%m-%d")-$2"
# save new copy
curl -s -X GET -H "X-Auth-Token: $3" "$1" > "$output" \
|| notify "Website backup error" "Error backing up $2"
@@ -29,7 +29,7 @@ backup() {
while read -r url file token
do
backup "$url" "$file" "$token"
-done < "$URLS"
+done < "$URLS_FILE"
# Can also be used by calling backup directly. Example:
# backup url file [token]