X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=functions.sh;h=0813756bdba0af4984b923a141c4644b87428852;hb=6747fddc8ece9e748a8624cb55828465bdb3ba1c;hp=43909786eeff605ffda737f96eaf22950cc24fc8;hpb=a650589630a1059f6184e8a632f47fadc5fab4d1;p=carnet-tools-cn.git diff --git a/functions.sh b/functions.sh index 4390978..0813756 100644 --- a/functions.sh +++ b/functions.sh @@ -159,12 +159,36 @@ cp_check_and_backup() { cp_backup_conffile() { [ "$CP_SCRIPT_DEBUG" ] && set -vx - local file_bak check did + local dir ext file_bak check did - if [ "x$1" = "x-r" ]; then - check=1 - shift - fi + dir=/var/backups + ext=.bak + + while echo "x$1" |grep -q '^x-'; do + case "$1" in + -r) + shift + check=1 + ;; + -d) + shift + # is argument to -d full path or relative? + if echo "$1" |grep -q '^/'; then + dir="$1" + else + dir="$dir/$1" + fi + shift + if [ ! -d "$dir" ]; then + echo "cp_backup_conffile: Invalid backup directory $dir" 1>&2 + return 3 + fi + ;; + -n) + shift + ext= + esac + done if [ -z "$1" ]; then return 1 fi @@ -173,9 +197,9 @@ cp_backup_conffile() { return 2 fi if [ -z "$2" ]; then - file_bak="/var/backups/`basename $1`.bak" + file_bak="$dir/`basename $1`$ext" else - file_bak="/var/backups/`basename $2`.bak" + file_bak="$dir/`basename $2`$ext" fi if [ ! -f "$file_bak" ]; then