From 63b74b789b809cca0c58f27424f80f04d459e80b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 30 Nov 2022 10:27:17 +0100 Subject: [PATCH] Refactoring common functions in scripts/functions.rc --- scripts/functions.rc | 56 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 11 deletions(-) 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} "$@" } -- 2.39.5