]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Reworking meaning of VERBOSE
authorFrank Brehm <frank@brehm-online.com>
Thu, 1 Feb 2024 09:23:28 +0000 (10:23 +0100)
committerFrank Brehm <frank@brehm-online.com>
Thu, 1 Feb 2024 09:23:28 +0000 (10:23 +0100)
bin/manual-backup
bin/update-nextcloud
lib/functions.rc

index 17dedc53e1cd3de7e1c2bf39b224c05684246ea1..7cf944d13e8fe0867245ec009bdd8a3145695005 100755 (executable)
@@ -71,7 +71,7 @@ usage() {
 TAR() {
 
     local cmd="tar --create --gzip"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" --file $1"
@@ -80,7 +80,7 @@ TAR() {
         cmd+=" \"$1\""
         shift
     done
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" 2>&1 | tee -a \"${LOGFILE}\" || true"
     else
         cmd+=" >/dev/null 2>&1 || true"
@@ -362,12 +362,12 @@ do_mysql_backup(){
 
     local cmd="mysqldump --all_databases --routines --triggers --add-drop-database"
     cmd+=" --add-drop-table --complete-insert --extended-insert --lock-tables"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" --log-error=\"${errorlog}\""
     cmd+=" | gzip -9"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" > \"${dumpfile}\""
@@ -380,7 +380,7 @@ do_mysql_backup(){
     if [[ -e "${errorlog}" ]] ; then
         if [[ -s "${errorlog}" ]] ; then
             cmd="gzip -9 \"${errorlog}\""
-            if [[ "${VERBOSE}" == "y" ]] ; then
+            if [[ "${VERBOSE}" ]] ; then
                 cmd="gzip -9 --verbose \"${errorlog}\""
             fi
             info "Executing: ${cmd}"
@@ -402,12 +402,12 @@ do_postgres_backup() {
     debug "Dumping PostgreSQL globals ..."
     local dumpfile="${BACKUP_DIR}/postgres.@globals.dump.sql.gz"
     local cmd="su - postgres -c \"pg_dumpall"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" --globals-only --clean --encoding=utf-8 --disable-triggers --if-exists\""
     cmd+=" | gzip -9"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" > \"${dumpfile}\""
@@ -429,12 +429,12 @@ do_postgres_backup() {
         debug "Dumping PostgreSQL database '${CYAN}${db}${NORMAL}' ..."
         dumpfile="${BACKUP_DIR}/postgres.${db}.dump.sql.gz"
         cmd="su - postgres -c \"pg_dump"
-        if [[ "${VERBOSE}" == "y" ]] ; then
+        if [[ "${VERBOSE}" ]] ; then
             cmd+=" --verbose"
         fi
         cmd+=" --blobs --clean --create --encoding=utf-8 --disable-triggers --if-exists '${db}'\""
         cmd+=" | gzip -9"
-        if [[ "${VERBOSE}" == "y" ]] ; then
+        if [[ "${VERBOSE}" ]] ; then
             cmd+=" --verbose"
         fi
         cmd+=" > \"${dumpfile}\""
@@ -464,11 +464,11 @@ do_backup_ldap() {
     empty_line
     info "Dumping OpenLDAP Config -> '${CYAN}${dumpfile}${NORMAL}' ..."
     local cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:/// -b \"cn=config\""
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" -v"
     fi
     cmd+=" | gzip -9"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" > \"${dumpfile}\""
@@ -491,11 +491,11 @@ do_backup_ldap() {
         info "Dumping OpenLDAP Datenbank '${CYAN}${dn}${NORMAL}' -> '${CYAN}${dumpfile}${NORMAL}' ..."
 
         cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:///"
-        if [[ "${VERBOSE}" == "y" ]] ; then
+        if [[ "${VERBOSE}" ]] ; then
             cmd+=" -v"
         fi
         cmd+=" -b \"${dn}\" '+' '*' | gzip -9"
-        if [[ "${VERBOSE}" == "y" ]] ; then
+        if [[ "${VERBOSE}" ]] ; then
             cmd+=" --verbose"
         fi
         cmd+=" > \"${dumpfile}\""
@@ -598,7 +598,7 @@ sync_to_remote() {
         empty_line
         info "Syncing backup to '${GREEN}${rhost}${NORMAL}:${CYAN}${BACKUP_HOSTDIR}${NORMAL}' ..."
         cmd="rsync --archive --hard-links --delete --stats"
-        if [[ "${VERBOSE}" == "y" ]] ; then
+        if [[ "${VERBOSE}" ]] ; then
             cmd+=" --verbose"
         fi
         cmd+=" \"${BACKUP_HOSTDIR}\" \"${rhost}:${BACKUP_PARENTDIR}\""
index 27aa4bcdd761db2a8c98f44c9182c69b6d203b06..c393702d0300051b74bd258f8188f6b9bb484d97 100755 (executable)
@@ -132,7 +132,7 @@ WGET() {
 
     info "Downloading '${CYAN}${url}${NORMAL}' ..."
 
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         wget "${url}"
     else
         wget -q "${url}"
@@ -201,7 +201,7 @@ do_backup() {
     cd "${WWW_BASE}"
 
     local cmd="tar -c"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" && "${VERBOSE}" -gt '1' ]] ; then
         cmd+=" --verbose"
     fi
     cmd+=" --file \"${backup_file}\" --bzip2 nextcloud"
@@ -282,7 +282,7 @@ unpack_archive() {
 
     cd "${TEMP_DIR}"
     info "Unpacking '${GREEN}${archive}${NORMAL}' ..."
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" && "${VERBOSE}" -gt '1' ]] ; then
         tar xfvj "${archive}"
     else
         tar xfj "${archive}"
@@ -384,7 +384,7 @@ stop_service() {
 
     info "Stopping '${CYAN}${SERVICE_NAME}${NORMAL}' ..."
     systemctl stop "${SERVICE_NAME}"
-    if [[ "${VERBOSE}" == 'y' ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         systemctl status "${SERVICE_NAME}" || true
     fi
 
@@ -418,7 +418,7 @@ start_service() {
 
     info "Starting '${CYAN}${SERVICE_NAME}${NORMAL}' ..."
     systemctl start "${SERVICE_NAME}"
-    if [[ "${VERBOSE}" == 'y' ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         systemctl status "${SERVICE_NAME}" || true
     fi
 
index 8147c267b33b136e30327341f6465d5045fcf20a..d2f242d86810ffeca53aad267455cf587486e1e1 100644 (file)
@@ -28,7 +28,7 @@ STD_USAGE_MSG=$( cat <<-EOF
     )
 
 # Standard global variables
-VERBOSE="n"
+VERBOSE=""
 DEBUG="n"
 DO_ASK="n"
 SIMULATE="n"
@@ -145,7 +145,10 @@ eval_common_options() {
                     shift
                     ;;
                 -v|--verbose)
-                    VERBOSE="y"
+                    if [[ -z "${VERBOSE}" ]] ; then
+                        VERBOSE='0'
+                    fi
+                    VERBOSE=$(( VERBOSE + 1 ))
                     shift
                     ;;
                 -q|--quiet)
@@ -181,7 +184,7 @@ eval_common_options() {
         done
     fi
 
-    if [[ "${VERBOSE}" == "y" && "${QUIET}" == "y" ]] ; then
+    if [[ "${VERBOSE}" && "${QUIET}" == "y" ]] ; then
         error "The options '${RED}--verbose${NORMAL}' and '${RED}--quiet${NORMAL}' are mutually exclusive."
         echo
         usage >&2
@@ -280,7 +283,7 @@ my_date() {
 
 #------------------------------------------------------------------------------
 debug() {
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         return 0
     fi
     local ts=$(my_date)
@@ -374,7 +377,7 @@ empty_line() {
 RM() {
 
     local cmd="rm $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="rm --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -382,7 +385,7 @@ RM() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         rm "$@"
     else
         rm --verbose "$@"
@@ -393,7 +396,7 @@ RM() {
 #------------------------------------------------------------------------------
 purge() {
 
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         rm "$@"
     else
         rm --verbose "$@"
@@ -405,7 +408,7 @@ purge() {
 MKDIR() {
 
     local cmd="mkdir $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="mkdir --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -420,7 +423,7 @@ MKDIR() {
 CP() {
 
     local cmd="cp $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="cp --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -428,7 +431,7 @@ CP() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         cp "$@"
     else
         cp --verbose "$@"
@@ -440,7 +443,7 @@ CP() {
 MV() {
 
     local cmd="mv $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="mv --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -448,7 +451,7 @@ MV() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         mv "$@"
     else
         mv --verbose "$@"
@@ -460,7 +463,7 @@ MV() {
 CHOWN() {
 
     local cmd="chown $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="chown --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -468,7 +471,7 @@ CHOWN() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -n "${VERBOSE}" ]] ; then
         chown "$@"
     else
         chown --verbose "$@"
@@ -480,7 +483,7 @@ CHOWN() {
 CHMOD() {
 
     local cmd="chmod $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="chmod --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -488,7 +491,7 @@ CHMOD() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         chmod "$@"
     else
         chmod --verbose "$@"
@@ -500,7 +503,7 @@ CHMOD() {
 LN() {
 
     local cmd="ln $*"
-    if [[ "${VERBOSE}" == "y" ]] ; then
+    if [[ "${VERBOSE}" ]] ; then
         cmd="ln --verbose $*"
     fi
     if [[ "${SIMULATE}" == "y" ]] ; then
@@ -508,7 +511,7 @@ LN() {
         return
     fi
     debug "Executing: ${cmd}"
-    if [[ "${VERBOSE}" != "y" ]] ; then
+    if [[ -z "${VERBOSE}" ]] ; then
         ln "$@"
     else
         ln --verbose "$@"