]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding quiet mode.
authorFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 12:47:45 +0000 (14:47 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 12:47:45 +0000 (14:47 +0200)
bin/update-minecraft-server-jar
lib/functions.rc

index 04a9cdbb3cebe232ee648bf853e3818271e4ecfa..17f6fb935c91d55a178d8ba6869372414801e327 100755 (executable)
@@ -34,6 +34,8 @@ DESCRIPTION=$( cat <<-EOF
        EOF
 )
 
+detect_color
+
 #------------------------------------------------------------------------------
 usage() {
     cat <<-EOF
@@ -84,9 +86,7 @@ get_options() {
         exit 2
     fi
 
-    check_for_root
-
-    LOGFILE="/var/log/${BASE_NAME}.log"
+    LOGFILE="${MC_ROOT_DIR}/${BASE_NAME}.log"
 
 }
 
@@ -111,7 +111,7 @@ check_preferences() {
     done
 
     for folder in "${MC_BACKUP_DIR}" "${MC_SERVER_DIR}" ; do
-        debug "Checking for directory '${folder}' ..."
+        debug "Checking for directory '${CYAN}${folder}${NORMAL}' ..."
         if [[ ! -d "${folder}" ]]; then
             all_ok="n"
             error "Did not found directory '${RED}${folder}${NORMAL}'."
index 4b44c67859d87bea955bd6eda961be9771ba6810..43edcc60f3a99291f351050bdb22e52294b6fa6a 100644 (file)
@@ -12,12 +12,15 @@ NORMAL=""
 
 VERSION="0.4.0"
 
-STD_SHORT_OPTIONS="sdvhV"
-STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
+STD_SHORT_OPTIONS="sdvqhV"
+STD_LONG_OPTIONS="simulate,debug,verbose,quiet,nocolor,help,version"
 STD_USAGE_MSG=$( cat <<-EOF
                -s|--simulate   Simulation mode - dont apply any changes.
                -d|--debug      Debug output (bash -x).
                -v|--verbose    Set verbosity on.
+                               Mutually exclusive to '--quiet'.
+               -q|--quiet      Quiet mode, no output except errors.
+                               Mutually exclusive to '--verbose'.
                --nocolor       Dont use colors on display.
                -h|--help       Show this output and exit.
                -V|--version    prints out version number of the script and exit
@@ -29,6 +32,7 @@ VERBOSE="n"
 DEBUG="n"
 DO_ASK="n"
 SIMULATE="n"
+QUIET="n"
 
 LOGFILE=
 
@@ -144,6 +148,10 @@ eval_common_options() {
                     VERBOSE="y"
                     shift
                     ;;
+                -q|--quiet)
+                    QUIET="y"
+                    shift
+                    ;;
                 --nocolor)
                     RED=""
                     YELLOW=""
@@ -173,6 +181,13 @@ eval_common_options() {
         done
     fi
 
+    if [[ "${VERBOSE}" == "y" && "${QUIET}" == "y" ]] ; then
+        error "The options '${RED}--verbose${NORMAL}' and '${RED}--quiet${NORMAL}' are mutually exclusive."
+        echo
+        usage >&2
+        exit 1
+    fi
+
     if [[ "${DEBUG}" = "y" ]] ; then
         set -x
     fi
@@ -281,7 +296,9 @@ info() {
     if [[ -n "${LOGFILE}" ]] ; then
         echo -e "[${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >>"${LOGFILE}"
     fi
-    echo -e " ${GREEN}*${NORMAL} [${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2
+    if [[ "${QUIET}" != "y" ]] ; then
+        echo -e " ${GREEN}*${NORMAL} [${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2
+    fi
 }
 
 #------------------------------------------------------------------------------