refactoring changes from sequpgrade (endReturn, ...) and some modernizations

This commit is contained in:
2023-01-03 15:49:08 +01:00
parent 215135e8aa
commit 3c22d5729f
69 changed files with 553 additions and 654 deletions

View File

@@ -15,7 +15,7 @@ seq_config() {
else
dry || return 1
fi
## Apt cmdline option to suppress user interaction
interactive || sq_aptOpt="-y"
@@ -24,7 +24,7 @@ seq_config() {
return 0
}
step_1_info() {
step_1_info() {
echo -n "Backup "
if contextHelp ; then
echo "selected profile"
@@ -58,18 +58,18 @@ step_1() {
done
if [ -z $EBU_TARGET ] || [ -z $EBU_SOURCE ] ; then
echo " [I] Nothing to do. Check $seq_configFile"
info "Nothing to do. Check $seq_configFile"
return 1
fi
if [ -n "${1:-}" ] && ( [ "$1" == "full" ] || [ "$1" == "incremental" ] ) ; then
dupArgs+=("$1")
elif [ -n "${1:-}" ] ; then
echo " [W] $toolName command \"$1\" not recognized"
warning "$toolName command \"$1\" not recognized"
return 1
fi
echo " [I] Running backup profile [$seq_profileName]"
info "Running backup profile [$seq_profileName]"
if [ "${dupArgs[0]:-}" != "full" ] && [ -n "$EBU_MAX_FULLBKP_AGE" ] ; then
dupArgs+=(--full-if-older-than "$EBU_MAX_FULLBKP_AGE")
@@ -79,7 +79,7 @@ step_1() {
fi
checkInstalled
setPassphrase
setPassphrase
exe $toolBin "${dupArgs[@]:-}" "${EBU_SOURCE:?}" "${EBU_TARGET:?}"
retVal=$?
unsetPassphrase
@@ -97,7 +97,7 @@ step_3() {
shift
if [ -z $EBU_TARGET ] || [ -z $EBU_SOURCE ] ; then
echo " [I] Nothing to do. Check $seq_configFile"
info "Nothing to do. Check $seq_configFile"
return 1
fi
@@ -107,7 +107,7 @@ step_3() {
unsetPassphrase
}
step_5_info() {
step_5_info() {
echo "Restore files from backup"
echoinfo " [OPTIONS]"
echoinfo " --file-to-restore, -f <RELPATH> : Relative path within backup"
@@ -148,7 +148,7 @@ step_5() {
fi
checkInstalled
setPassphrase
setPassphrase
exe $toolBin restore "${restoreOpt[@]}" "$EBU_TARGET" "$ebuLocalTarget"
unsetPassphrase
}
@@ -166,9 +166,9 @@ step_7() {
if [ ! -z "$EBU_MAX_AGE" ] ; then
dupCommand+="remove-older-than $EBU_MAX_AGE "
elif [ ! -z "$EBU_MAX_FULL_BACKUPS" ] ; then
elif [ ! -z "$EBU_MAX_FULL_BACKUPS" ] ; then
dupCommand+="remove-all-but-n-full $EBU_MAX_FULL_BACKUPS "
elif [ ! -z "$EBU_MAX_FULLS_WITH_INCRS" ] ; then
elif [ ! -z "$EBU_MAX_FULLS_WITH_INCRS" ] ; then
dupCommand+="remove-all-inc-of-but-n-full $EBU_MAX_FULLS_WITH_INCRS "
else
if interactive ; then warning -e "No purge option configured" ; fi
@@ -176,7 +176,7 @@ step_7() {
fi
checkInstalled
setPassphrase
setPassphrase
exe $toolBin $dupCommand --force "$ebuTarget"
unsetPassphrase
}
@@ -215,13 +215,13 @@ step_22() {
fi
checkInstalled
setPassphrase
setPassphrase
exe $toolBin list-current-files "$ebuTarget"
unsetPassphrase
}
step_70_info() {
step_70_info() {
echo -n "Manage cron file for "
if contextHelp ; then
echo -n "selected profile"
@@ -260,16 +260,16 @@ step_70() {
cronEntry+=" >$cronLog"
if [ -z "$EBU_CRONTIME" ] || [ $cronRemove -ne 0 ] ; then
echo " [I] Removing cron for profile $seq_profileName"
info "Removing cron for profile $seq_profileName"
exe rm -r "$cronScript"
else
checkFileHead "$cronScript" "$cronEntry"
if [ $? -ne 0 ] ; then
echo " [I] Update cron for profile $seq_profileName"
info "Update cron for profile $seq_profileName"
exep "sudo echo \"$cronEntry\" > \"$cronScript\""
syslogEntry "Cron file update complete [$EBU_CRONTIME]"
else
echo " [I] Cron for profile $seq_profileName is up to date"
info "Cron for profile $seq_profileName is up to date"
fi
fi
}
@@ -291,14 +291,14 @@ step_100() {
}
setPassphrase() {
if [ -z "${PASSPHRASE:-}" ] && [ -n "${EBU_PASSPHRASE:-}" ] ; then
if [ -z "${PASSPHRASE:-}" ] && [ -n "${EBU_PASSPHRASE:-}" ] ; then
export PASSPHRASE="$EBU_PASSPHRASE"
fi
}
unsetPassphrase() {
unset PASSPHRASE
}
}
checkFileHead() {
local readChar
@@ -307,7 +307,7 @@ checkFileHead() {
return 1
fi
read -r -n ${#2} readChar < "$1"
if [ "$readChar" == "$2" ] ; then
if [ "$readChar" == "$2" ] ; then
return 0
fi
return 1
@@ -325,7 +325,7 @@ checkInstalled() {
step install
fi
toolBin="${EBU_PRECMD:-} $(escpath "$(command -v $toolName)")"
fi
fi
}
# shellcheck disable=SC2034 # Appears unused