From 756093288797a3c484012c5807d038acfc69efd7 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 1 Feb 2024 10:23:28 +0100 Subject: [PATCH] Reworking meaning of VERBOSE --- bin/manual-backup | 28 ++++++++++++++-------------- bin/update-nextcloud | 10 +++++----- lib/functions.rc | 39 +++++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/bin/manual-backup b/bin/manual-backup index 17dedc5..7cf944d 100755 --- a/bin/manual-backup +++ b/bin/manual-backup @@ -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}\"" diff --git a/bin/update-nextcloud b/bin/update-nextcloud index 27aa4bc..c393702 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -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 diff --git a/lib/functions.rc b/lib/functions.rc index 8147c26..d2f242d 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -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 "$@" -- 2.39.5