system-configs/etc/cron.daily/warn-git-status
2023-11-06 19:23:41 +00:00

38 lines
1.1 KiB
Bash
Executable file

#!/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
}
# Send the message.
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