From 0ed6cfeb4abc0fb93a86b5960d495be12027a693 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Mon, 6 Nov 2023 17:12:55 +0000 Subject: [PATCH] Add warn-git-status script. --- warn-git-status | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 warn-git-status diff --git a/warn-git-status b/warn-git-status new file mode 100755 index 0000000..931504f --- /dev/null +++ b/warn-git-status @@ -0,0 +1,37 @@ +#!/bin/bash + +CHECK_DIRS=( '/' '/etc/slackpkg/templates' ) +OUTPUT_FILE="/tmp/${0##*/}-$$-$RANDOM" + +# Remove the OUTPUT_FILE when done. +trap 'rm -f "$OUTPUT_FILE"' EXIT + +# Source the mail configuration. +source /etc/mail.conf "git-status" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "Failed to source /etc/mail.conf" >&2 + exit 1 +} + +# Loop through the list and process. +for DIR in "${CHECK_DIRS[@]}"; do + [[ ! -e "$DIR" ]] || [[ ! -d "$DIR" ]] && continue + TMP_OUTPUT="$(cd "$DIR" && [[ "$(git rev-parse --show-toplevel)" == "$PWD" ]] && git status | grep -E -ve "^(On branch|Your branch|No commits|nothing|$)" -e "\(use")" + [[ -n "$TMP_OUTPUT" ]] && printf "%s:\\n%s\\n\\n" "$DIR" "$TMP_OUTPUT" >>"$OUTPUT_FILE" + unset TMP_OUTPUT +done + +[[ ! -s "$OUTPUT_FILE" ]] && { + exit 0 +} + +if [[ -n "${EMAIL_TO[*]}" ]]; then + mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "Git statuses" "${EMAIL_TO[@]}" <<<"$(cat "$OUTPUT_FILE")" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2 + exit 1 + } +else + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 + exit 1 +fi + +exit 0