Files @ 42155469350e
Branch filter:

Location: majic-scripts/configuration/etckeeper_notifier.sh - annotation

branko
Noticket: Added a small script for creating quick backups of files before making changes to them.
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
ee406aac7d24
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
61750d5ab4b2
#!/bin/bash
#
# etckeeper_notifier.sh
#
# Copyright (C) 2012, Branko Majic <branko@majic.rs>
#
# 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 <http://www.gnu.org/licenses/>.
#

program="etckeeper_notifier.sh"
version="0.1"

function usage() {
    cat <<EOF
$program $version, a non-interactive utility for sending-out notifications about
uncommitted changes in etckeeper-controlled directories.

Usage: $program [OPTIONS] directory

$program is a non-interactive utility for sending-out notifications about
uncommitted changes in etckeeper-controlled directories. The script acts as a
small wrapper around the "etckeeper unclean" and "mail" commands. Main use for
the script is for cases where automatic daily commits by etckeeper are disabled,
but the administrator still desires to be notified of uncommitted changes in the
directory (commonly /etc/). The script should be used through a cron job.

The script accepts a single argument which is path to the directory controlled
by etckeeper that should be checked for uncommitted changes.

$program accepts the following options:
    -m mails  Space-separated list of e-mails to send out the mail notification
              to. Default is root@localhost.

    -e etckeeper_path Path to the etckeeper binary.
        

    -v        show script version and licensing information
    -h        show usage help


Please report bugs and send feature requests to <branko@majic.rs>.
EOF
}

function version() {
        cat <<EOF
$program, version $version

+-----------------------------------------------------------------------+
| Copyright (C) 2012, Branko Majic <branko@majic.rs>                    |
|                                                                       |
| 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 <http://www.gnu.org/licenses/>. |
+-----------------------------------------------------------------------+

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 <<EOF
Uncommitted changes have been detected on server $(hostname -f) in directory:

$directory

Please log-in onto the server, and either undo the changes, or commit the
changes using a descriptive comment.

Do not reply to this mail. This is an automated message.
EOF
fi