From: Frank Brehm Date: Thu, 1 Feb 2024 09:34:10 +0000 (+0100) Subject: Reworking usage of DEBUG and SIMULATE X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=e305ec26ba3ad092355109fd511cbd1c763cc574;p=pixelpark%2Fadmin-tools.git Reworking usage of DEBUG and SIMULATE --- diff --git a/bin/manual-backup b/bin/manual-backup index 7cf944d..5fa3e0b 100755 --- a/bin/manual-backup +++ b/bin/manual-backup @@ -86,7 +86,7 @@ TAR() { cmd+=" >/dev/null 2>&1 || true" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -174,7 +174,7 @@ get_options() { # Note the quotes around `$TEMP': they are essential! eval set -- "${tmp}" eval_common_options "$@" - if [[ "${DEBUG}" == 'y' ]] ; then + if [[ "${DEBUG}" ]] ; then declare -p REMAINING_OPTS declare -p REMAINING_ARGS fi @@ -195,7 +195,7 @@ get_options() { exit 2 fi - if [[ "${SIMULATE}" != 'y' ]] ; then + if [[ -z "${SIMULATE}" ]] ; then LOGFILE="${BACKUP_HOSTDIR}/backup.log" fi } @@ -371,7 +371,7 @@ do_mysql_backup(){ cmd+=" --verbose" fi cmd+=" > \"${dumpfile}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -411,7 +411,7 @@ do_postgres_backup() { cmd+=" --verbose" fi cmd+=" > \"${dumpfile}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" else debug "Executing: ${cmd}" @@ -438,7 +438,7 @@ do_postgres_backup() { cmd+=" --verbose" fi cmd+=" > \"${dumpfile}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" continue fi @@ -472,7 +472,7 @@ do_backup_ldap() { cmd+=" --verbose" fi cmd+=" > \"${dumpfile}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" else debug "Executing: ${cmd}" @@ -499,7 +499,7 @@ do_backup_ldap() { cmd+=" --verbose" fi cmd+=" > \"${dumpfile}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" else debug "Executing: ${cmd}" @@ -531,7 +531,7 @@ create_checksums() { cs_file="backup-checksums.${cs_type}" info "Creating '${CYAN}${cs_file}${NORMAL}' ..." cmd="${cs_type}sum *.gz > \"${cs_file}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" continue fi @@ -607,7 +607,7 @@ sync_to_remote() { else cmd+=" 2>&1 | tee -a \"${LOGFILE}\"" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" continue fi diff --git a/bin/pull-known-hosts b/bin/pull-known-hosts index cc084ce..c313204 100755 --- a/bin/pull-known-hosts +++ b/bin/pull-known-hosts @@ -128,7 +128,7 @@ get_options() { # Note the quotes around `$TEMP': they are essential! eval set -- "${tmp}" eval_common_options "$@" - if [[ "${DEBUG}" == 'y' ]] ; then + if [[ "${DEBUG}" ]] ; then declare -p REMAINING_OPTS declare -p REMAINING_ARGS fi diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn index 63e74b4..f6c4e46 100755 --- a/bin/start-openfortivpn +++ b/bin/start-openfortivpn @@ -69,7 +69,7 @@ get_options() { # Note the quotes around `$TEMP': they are essential! eval set -- "${tmp}" eval_common_options "$@" - if [[ "${DEBUG}" == 'y' ]] ; then + if [[ "${DEBUG}" ]] ; then declare -p REMAINING_OPTS declare -p REMAINING_ARGS fi diff --git a/bin/update-minecraft-server-jar b/bin/update-minecraft-server-jar index cb2fa20..7a8f006 100755 --- a/bin/update-minecraft-server-jar +++ b/bin/update-minecraft-server-jar @@ -83,7 +83,7 @@ get_options() { # Note the quotes around `$TEMP': they are essential! eval set -- "${tmp}" eval_common_options "$@" - if [[ "${DEBUG}" == 'y' ]] ; then + if [[ "${DEBUG}" ]] ; then declare -p REMAINING_OPTS declare -p REMAINING_ARGS fi @@ -237,7 +237,7 @@ do_download() { fi local cmd="curl -o \"${TARGET_JAR}\" -s \"${DOWNLOAD_URL}\"" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" else debug "Executing: ${cmd}" @@ -260,7 +260,7 @@ check_sha1() { info "Checking SHA1 sum integrety of '${CYAN}${TARGET_JAR}${NORMAL}' ..." if [[ ! -f "${TARGET_JAR}" ]] ; then - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then debug "Simulation mode - jar file must not exists." return 0 fi @@ -356,13 +356,13 @@ restart_service() { empty_line for service in "${services[@]}" ; do info "Restarting '${CYAN}${service}${NORMAL}' ..." - if [[ "${SIMULATE}" != "y" ]] ; then + if [[ -z "${SIMULATE}" ]] ; then systemctl restart "${service}" fi MAIL_BODY+="$( my_date ): Restarted service '${service}'.\n" done - if [[ "${SIMULATE}" != "y" ]] ; then + if [[ -z "${SIMULATE}" ]] ; then debug "Sleeping for 15 seconds ..." sleep 15 fi @@ -393,7 +393,7 @@ check_and_send_mail() { MAIL_BODY+="With best regards\n\n" MAIL_BODY+="Your ${BASE_NAME}" - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then local msg="Following mail should be sent:\n" msg+="From: <${MAIL_FROM_ADDRESS}>\n" msg+="To: <${MAIL_TO_ADDRESS}>\n" diff --git a/bin/update-nextcloud b/bin/update-nextcloud index c393702..3b1b9fb 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -88,7 +88,7 @@ get_options() { # Note the quotes around `$TEMP': they are essential! eval set -- "${tmp}" eval_common_options "$@" - if [[ "${DEBUG}" == 'y' ]] ; then + if [[ "${DEBUG}" ]] ; then declare -p REMAINING_OPTS declare -p REMAINING_ARGS fi diff --git a/lib/functions.rc b/lib/functions.rc index d2f242d..879f839 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -29,9 +29,9 @@ STD_USAGE_MSG=$( cat <<-EOF # Standard global variables VERBOSE="" -DEBUG="n" -DO_ASK="n" -SIMULATE="n" +DEBUG="" +DO_ASK="" +SIMULATE="" QUIET="n" LOGFILE= @@ -191,7 +191,7 @@ eval_common_options() { exit 1 fi - if [[ "${DEBUG}" = "y" ]] ; then + if [[ "${DEBUG}" ]] ; then set -x fi @@ -203,7 +203,7 @@ eval_common_options() { done fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then echo echo -e "${CYAN}Simulation mode!${NORMAL}" echo "Nothing is really done." @@ -380,7 +380,7 @@ RM() { if [[ "${VERBOSE}" ]] ; then cmd="rm --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -411,7 +411,7 @@ MKDIR() { if [[ "${VERBOSE}" ]] ; then cmd="mkdir --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -426,7 +426,7 @@ CP() { if [[ "${VERBOSE}" ]] ; then cmd="cp --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -446,7 +446,7 @@ MV() { if [[ "${VERBOSE}" ]] ; then cmd="mv --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -466,7 +466,7 @@ CHOWN() { if [[ "${VERBOSE}" ]] ; then cmd="chown --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -486,7 +486,7 @@ CHMOD() { if [[ "${VERBOSE}" ]] ; then cmd="chmod --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi @@ -506,7 +506,7 @@ LN() { if [[ "${VERBOSE}" ]] ; then cmd="ln --verbose $*" fi - if [[ "${SIMULATE}" == "y" ]] ; then + if [[ "${SIMULATE}" ]] ; then info "Executing: ${cmd}" return fi