X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=carnet-tools-cn.git;a=blobdiff_plain;f=functions.sh;fp=functions.sh;h=47ad62f0e3be17026aac7ff9fee678468bb1e67a;hp=0813756bdba0af4984b923a141c4644b87428852;hb=53e4a56a246421d5ec52c23135661e9b7d7ddb63;hpb=6747fddc8ece9e748a8624cb55828465bdb3ba1c diff --git a/functions.sh b/functions.sh index 0813756..47ad62f 100644 --- a/functions.sh +++ b/functions.sh @@ -159,7 +159,7 @@ cp_check_and_backup() { cp_backup_conffile() { [ "$CP_SCRIPT_DEBUG" ] && set -vx - local dir ext file_bak check did + local dir ext file_bak check did opt_p opt_d dir=/var/backups ext=.bak @@ -170,25 +170,37 @@ cp_backup_conffile() { shift check=1 ;; + -p) + shift + opt_p=1 -d) shift - # is argument to -d full path or relative? + opt_d=1 + # 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 [ "$opt_d" ]; then + if [ ! -e "$dir" -a "$opt_p" ]; then + mkdir "$dir" + if [ $? -ne 0 ]; then + echo "cp_backup_conffile: Error creating backup directory $dir" 1>&2 + return 3 + fi + fi + if [ ! -d "$dir" ]; then + echo "cp_backup_conffile: Invalid backup directory $dir" 1>&2 + return 3 + fi if [ -z "$1" ]; then return 1 fi