Add warn-git-status script.
This commit is contained in:
parent
7fce61dcc0
commit
0ed6cfeb4a
1 changed files with 37 additions and 0 deletions
37
warn-git-status
Executable file
37
warn-git-status
Executable file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue