diff options
author | Jonas Smedegaard <dr@jones.dk> | 2007-02-22 10:48:04 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2007-02-22 10:48:04 +0000 |
commit | 6c8edcbc1061717cb9e0716636b8a4b92cd5117c (patch) | |
tree | f24a6b3e6c3abb2a6ce40dd27a8b4a0942b9bf3a | |
parent | bbda3a37acd5a3d3e1c98e695b3dcd20c336b72e (diff) |
Support options --target and --force (using getopt).
-rwxr-xr-x | savelocaltweaks | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/savelocaltweaks b/savelocaltweaks index 3ce2bd0..aff588a 100755 --- a/savelocaltweaks +++ b/savelocaltweaks @@ -2,12 +2,38 @@ set -e +PRG=$(basename "$0") + +TEMP="`getopt -s sh -o t:f -l target:,force -n "$PRG" -- "$@"`" +if [ $? != 0 ] ; then echo >&2 "ERROR: Internal getopt error." ; exit 1 ; fi +eval set -- "$TEMP" + +realtargetdir='' +force='no' +while true ; do + case "$1" in + -t|--target) realtargetdir="$2" ; shift 2 ;; + -f|--force) force="yes" ; shift ;; + --) shift ; break ;; + *) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;; + esac +done + basedir="/etc" targetdir="$(mktemp -td localtweaks.XXXXXX)" includefile="/etc/local/localtweaks.include" excludefile="/etc/local/localtweaks.exclude" extensions=".orig .old" +if [ -n "$realtargetdir" ] && [ -e "$realtargetdir" ]; then + if [ "$force" = "yes" ]; then + rm -rf "$realtargetdir" + else + echo >&2 "Error: Target directory exists already." + exit 1 + fi +fi + for ext in $extensions; do extfiles="$(find $basedir -name "*$ext")" for extfile in $extfiles; do @@ -63,3 +89,8 @@ for file in $files; do chmod a-x "$targetdir/$basedir/$file.diff" fi done + +if [ -n "$realtargetdir" ]; then + mv "$targetdir" "$realtargetdir" + rm -rf "$targetdir" +fi |