X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=functions.sh;h=8c2e0e864459f73659fa92e9093f4678b69ecfdb;hb=9d14d6fd31235bc0c8a6733fcf37cec81879dfcd;hp=0813756bdba0af4984b923a141c4644b87428852;hpb=6747fddc8ece9e748a8624cb55828465bdb3ba1c;p=carnet-tools-cn.git diff --git a/functions.sh b/functions.sh index 0813756..8c2e0e8 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,40 @@ 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" + fi + 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