X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=functions.sh;h=0813756bdba0af4984b923a141c4644b87428852;hb=6747fddc8ece9e748a8624cb55828465bdb3ba1c;hp=8ef825431168896f839b84c23eaf89c1f46589ef;hpb=5d2f462427acf38aafc0e2d3a203ce0197b3eafc;p=carnet-tools-cn.git diff --git a/functions.sh b/functions.sh index 8ef8254..0813756 100644 --- a/functions.sh +++ b/functions.sh @@ -1,3 +1,9 @@ +# Initialize "public" CP_ECHO_RETURN variable once +if [ -z "$_CP_INIT_ECHO_RETURN" ]; then + _CP_INIT_ECHO_RETURN=1 + CP_ECHO_RETURN="" +fi + # by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100 cp_get_ifaddr() { [ "$CP_SCRIPT_DEBUG" ] && set -vx @@ -153,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 @@ -167,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