#!/bin/bash # $Id: visamba,v 1.1 2002/09/24 14:28:22 nturner Exp $ # set -e function usage { ( echo " USAGE: edit-and-reload [OPTION]... DESCRIPTION: Opens for editing and then runs if the file is changed after editing. Uses md5sum to determine if file has changed. OPTIONS: -h, --help: show this help -v, --verbose: output extra stuff when running " ) >&2 } TEMP=`getopt -o hv --long help,verbose -n edit-and-reload -- "$@"` eval set -- "$TEMP" help= verbose= while true; do case "$1" in -h|--help) help=1 ; shift ;; -v|--verbose) verbose=1 ; shift ;; --) shift ; break ;; *) echo "Error" ; exit 1 ;; esac done if [ "$help" ]; then usage exit 0 fi if [ ! "$1" ]; then usage exit 1 fi file="$1"; shift hashBefore=`md5sum $file` sudoedit "$file" || exit 1 if test "`md5sum $file`" != "$hashBefore"; then [ -n "$verbose" ] && echo "Running sudo $@" sudo "$@" else echo "File contents unchanged." fi