From a2dddcf7652633776d547a241892e9b781e90d42 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Fri, 21 Oct 2022 17:07:37 +0200 Subject: [PATCH] restore - init vars; shell fixes --- restore.sh | 55 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/restore.sh b/restore.sh index 2ed932e..ea4b4ac 100755 --- a/restore.sh +++ b/restore.sh @@ -22,7 +22,7 @@ # 2018-08-27 ah,ds v1.2 fix restore target with a given selection; handle '*' placeholder # 2019-06-05 ah,ds v1.3 add custom cache dir # 2021-05-19 ah,ds, v2.0 plugin driven -# 2022-10-21 ah v2.1 init vars +# 2022-10-21 ah v2.1 init vars; shell fixes # ================================================================================ @@ -32,11 +32,11 @@ # . `dirname $0`/inc_config.sh - . `dirname $0`/jobhelper.sh - . `dirname $0`/inc_bash.sh + . $(dirname $0)/jobhelper.sh + . $(dirname $0)/inc_bash.sh # --- load a transfer plugin - STORAGE_BIN=`_j_getvar ${STORAGEFILE} "bin"` + STORAGE_BIN=$(_j_getvar ${STORAGEFILE} "bin") if [ -z "$STORAGE_BIN" ]; then if ! id -u | grep '^0$' @@ -50,20 +50,20 @@ CFGPREFIX=${STORAGE_BIN}_ - . `dirname $0`/plugins/transfer/$STORAGE_BIN.sh || exit 1 + . $(dirname $0)/plugins/transfer/$STORAGE_BIN.sh || exit 1 # --- get backend url of backup data - STORAGE_BASEDIR=`_j_getvar ${STORAGEFILE} "storage"` + STORAGE_BASEDIR=$(_j_getvar ${STORAGEFILE} "storage") if [ -z $STORAGE_BASEDIR ]; then - echo ERROR: missing config for backup target. - echo There must be an entry storage in ${STORAGEFILE} + echo "ERROR: missing config for backup target." + echo "There must be an entry storage in ${STORAGEFILE}" exit 1 fi # target directory of directory specific repository STORAGE_TARGETPATH= - PASSPHRASE=`_j_getvar ${STORAGEFILE} "passphrase"` + PASSPHRASE=$(_j_getvar "${STORAGEFILE}" "passphrase") # timestamp or snapshot id RESTORE_ITEM= @@ -72,7 +72,7 @@ RESTORE_FILTER= # full path of restore data - RESTORE_BASEDIR=`_j_getvar ${STORAGEFILE} "restore-path"` + RESTORE_BASEDIR=$(_j_getvar "${STORAGEFILE}" "restore-path") RESTORE_TARGETPATH= # set vars for transfer plugin @@ -80,15 +80,16 @@ # ----- Create default command line parameters + export ARGS_DEFAULT ARGS_DEFAULT="$( t_getParamDefault $1 $2 )" - sFileSshPrivkey=`_j_getvar ${STORAGEFILE} "ssh-privatekey"` - if [ ! -z $sFileSshPrivkey ]; then + sFileSshPrivkey=$(_j_getvar "${STORAGEFILE}" "ssh-privatekey") + if [ -n "$sFileSshPrivkey" ]; then ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamSshKey $sFileSshPrivkey )" fi # task#3046 - add custom cache dir - sCacheDir=`_j_getvar ${STORAGEFILE} "cachedir"` + sCacheDir=$(_j_getvar "${STORAGEFILE}" "cachedir") ARGS_DEFAULT="${ARGS_DEFAULT} $( t_getParamCacheDir $sCacheDir )" @@ -115,7 +116,7 @@ function enterBackupDir(){ echo "Enter the full path; marked entries with (*) do not exist on this machine" echo - local sDirs="`j_getDirs2Backup`" + local sDirs="$(j_getDirs2Backup)" for mydir in $sDirs do if [ ! -d "$mydir" ]; then @@ -130,7 +131,7 @@ function enterBackupDir(){ color input echo -n "[$BACKUP_DIR] >" color reset - read myinput + read -r myinput setBackupDir "${myinput}" @@ -143,7 +144,7 @@ function enterBackupDir(){ # ---------------------------------------------------------------------- function setBackupDir(){ if [ ! -z $1 ]; then - sDirs2Backup="`j_getDirs2Backup`" + sDirs2Backup="$(j_getDirs2Backup)" bFound=0 for mydir in ${sDirs2Backup} do @@ -176,7 +177,7 @@ function setBackupDir(){ # set backup url and local restore path (based on given backup directory) function setVars(){ - local sSafeName=`j_getSafename "$BACKUP_DIR"` + local sSafeName=$(j_getSafename "$BACKUP_DIR") RESTORE_TARGETPATH="${RESTORE_BASEDIR}/${sSafeName}" STORAGE_TARGETPATH="$( t_backupDirGetTarget $BACKUP_DIR )" } @@ -193,7 +194,7 @@ function doRestore(){ fi mkdir -p "${RESTORE_TARGETPATH}" - echo $restorecmd + echo "$restorecmd" color cmd $restorecmd fetchrc @@ -205,9 +206,9 @@ function doRestore(){ echo echo Restore is finished. echo Have look to the output above. - echo "The restore path has `find ${RESTORE_TARGETPATH} | wc -l` items (`du -hs ${RESTORE_TARGETPATH} | awk '{ print $1 }'`)" + echo "The restore path has $(find ${RESTORE_TARGETPATH} | wc -l) items ($(du -hs ${RESTORE_TARGETPATH} | awk '{ print $1 }'))" echo - echo find ${RESTORE_TARGETPATH} + echo "find ${RESTORE_TARGETPATH}" exit } @@ -222,14 +223,10 @@ function doRestore(){ t_checkRequirements setBackupDir $1 - if [ -z $BACKUP_DIR ]; then + if [ -z "$BACKUP_DIR" ]; then enterBackupDir fi - # init vars of the backup tool - t_getParamDefault >/dev/null - - # ----- menu and loop while true @@ -257,7 +254,7 @@ function doRestore(){ echo " restore to : $RESTORE_TARGETPATH" echo -n " " if [ -n "$RESTORE_TARGETPATH" ]; then - ls -d $RESTORE_TARGETPATH >/dev/null 2>&1 + ls -d "$RESTORE_TARGETPATH" >/dev/null 2>&1 if [ $? -eq 0 ]; then color error echo "WARNING: directory already exists! Backup will fail." @@ -274,7 +271,7 @@ function doRestore(){ echo showPrompt "Select (not case sensitive) --> " - read action + read -r action echo case $action in @@ -296,7 +293,7 @@ function doRestore(){ h2 "Search a file" filefilter=".*" showPrompt "Regex for filefilter; ${filefilter} for all >" - read filefilter + read -r filefilter test -z "${filefilter}" || t_restoreDoSearchFile "${filefilter}" ;; # v|V) @@ -306,7 +303,7 @@ function doRestore(){ h2 "Shell" echo "HINT: type exit in the subshell to return to the menu." echo - export PS1="RESTIC [`basename $0` \u@\h \w]\$ " + export PS1="RESTIC [$(basename $0) \u@\h \w]\$ " bash --noprofile ;; f|F) -- GitLab