From: Frank Brehm Date: Wed, 30 Nov 2022 09:27:17 +0000 (+0100) Subject: Refactoring common functions in scripts/functions.rc X-Git-Tag: 0.7.4^2~1^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=63b74b789b809cca0c58f27424f80f04d459e80b;p=pixelpark%2Fpp-admin-tools.git Refactoring common functions in scripts/functions.rc --- diff --git a/scripts/functions.rc b/scripts/functions.rc index 0b4de87..daf6ab2 100644 --- a/scripts/functions.rc +++ b/scripts/functions.rc @@ -342,6 +342,29 @@ check_for_root() { fi } +#------------------------------------------------------------------------------ +CP() { + local cmd="cp" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + if [[ "${SIMULATE}" == "y" ]] ; then + debug "Simulate executing: ${cmd} $*" + return + fi + eval ${cmd} "$@" +} + +#------------------------------------------------------------------------------ +CP_force() { + local cmd="cp" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + debug "Executing: ${cmd} $*" + eval ${cmd} "$@" +} + #------------------------------------------------------------------------------ MV() { local cmd="mv" @@ -349,35 +372,46 @@ MV() { cmd+=" --verbose" fi if [[ "${SIMULATE}" == "y" ]] ; then - info "Executing: ${cmd} $*" + debug "Simulate executing: ${cmd} $*" return fi eval ${cmd} "$@" } +#------------------------------------------------------------------------------ +MV_force() { + local cmd="mv" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + debug "Executing: ${cmd} $*" + eval ${cmd} "$@" +} + #------------------------------------------------------------------------------ RM() { + local cmd="rm" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi if [[ "${SIMULATE}" == "y" ]] ; then - debug "Simulated removing of: $*" + debug "Simulate executing: ${cmd} $*" return fi - if [[ "${VERBOSE}" != "y" ]] ; then - rm "$@" - else - rm --verbose "$@" - fi + eval ${cmd} "$@" } #------------------------------------------------------------------------------ RM_force() { - if [[ "${VERBOSE}" != "y" ]] ; then - rm --force "$@" - else - rm --force --verbose "$@" + local cmd="rm --force" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" fi + debug "Executing: ${cmd} $*" + eval ${cmd} "$@" }