#!/bin/bash # # etckeeper_notifier.sh # # Copyright (C) 2012, Branko Majic # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # program="etckeeper_notifier.sh" version="0.1" function usage() { cat <. EOF } function version() { cat < | | | | This program is free software: you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | | the Free Software Foundation, either version 3 of the License, or | | (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program. If not, see . | +-----------------------------------------------------------------------+ EOF } # If no arguments were given, just show usage help. if [[ -z $1 ]]; then usage exit 0 fi # Set-up some default values. notificationRecipients="root@localhost" # Location of the etckeeper binary. etckeeper="/usr/bin/etckeeper" # Parse the arguments while getopts "e:m:vh" opt; do case "$opt" in e) etckeeper="$OPTARG";; m) notificationRecipients="$OPTARG";; v) version exit 0;; h) usage exit 0;; *) usage exit 1;; esac done i=$OPTIND shift $(($i-1)) # Read the positional arguments directory="$1" # Verify arguments if [[ ! -d "$directory" ]]; then echo "No such directory: '$directory'" >&2 exit 2 fi # Verify that etckeeper is available. if [[ ! -f $etckeeper ]]; then echo "The etckeeper was not found in location: '$etckeeper'." >&2 exit 2 fi if "$etckeeper" unclean -d "$directory"; then mail -s "Uncommited changes on '$(hostname -f)' in '$directory'" $notificationRecipients <