]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Refactoring common functions in scripts/functions.rc
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 30 Nov 2022 09:27:17 +0000 (10:27 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 30 Nov 2022 09:27:17 +0000 (10:27 +0100)
scripts/functions.rc

index 0b4de87a416ce140513cc9aadfeecbae7a929cca..daf6ab2034aeec5f4084517cbb80b9857330a7b3 100644 (file)
@@ -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} "$@"
 
 }