]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Applying shellcheck to functions.rc
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 9 Dec 2021 07:25:04 +0000 (08:25 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 9 Dec 2021 07:25:04 +0000 (08:25 +0100)
scripts/functions.rc

index 99a4ee76af0aeeb44bc6a16fd6aa6b86a16b905e..22c47ef36583b48cf936cf858edfafb30af1136a 100644 (file)
@@ -12,8 +12,11 @@ NORMAL=""
 
 VERSION="0.2.1"
 
+# shellcheck disable=SC2034
 STD_SHORT_OPTIONS="sdvhV"
+# shellcheck disable=SC2034
 STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
+# shellcheck disable=SC2034
 STD_USAGE_MSG=$( cat <<-EOF
                -s|--simulate   Simulation mode - dont apply any changes.
                -d|--debug      Debug output (bash -x).
@@ -27,12 +30,14 @@ STD_USAGE_MSG=$( cat <<-EOF
 # Standard global variables
 VERBOSE="n"
 DEBUG="n"
+# shellcheck disable=SC2034
 DO_ASK="n"
 SIMULATE="n"
 
 declare -a REMAINING_ARGS=()
 declare -a REMAINING_OPTS=()
 
+# shellcheck disable=SC2034
 NFS_HOMEDIR_PARENT='/mnt/nfs/home'
 
 DESCRIPTION="${DESCRIPTION:-Failing script description}"
@@ -44,9 +49,12 @@ LDAP_BASE="o=isp"
 LDAP_HOST="ldap.pixelpark.com"
 LDAP_PORT=389
 
+# shellcheck disable=SC2034
 LDAP_STD_OPTS_SHORT="D:y:H:P:b:"
+# shellcheck disable=SC2034
 LDAP_STD_OPTS_LONG="bind-dn:,password-file:,ldap-host:,ldap-port:,base-dn:"
 
+# shellcheck disable=SC2034
 LDAP_USAGE_MSG=$( cat <<-EOF
                -D|--bind-dn DN
                                Use this Distinguished Name DN to bind to the LDAP directory.
@@ -72,17 +80,17 @@ detect_color() {
     local term=
 
     if [[ -f ~/.dir_colors   ]] ; then
-        match_lhs="${match_lhs}$( cat ~/.dir_colors | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')"
+        match_lhs="${match_lhs}$( grep '^TERM ' ~/.dir_colors | sed -e 's/^TERM  *//' -e 's/ .*//')"
     fi
     if [[ -f /etc/DIR_COLORS   ]] ; then
-        match_lhs="${match_lhs}$( cat /etc/DIR_COLORS | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')"
+        match_lhs="${match_lhs}$( grep '^TERM ' /etc/DIR_COLORS | sed -e 's/^TERM  *//' -e 's/ .*//')"
     fi
     if [[ -z ${match_lhs} ]] ; then
         type -P dircolors >/dev/null && \
         match_lhs=$(dircolors --print-database | grep '^TERM ' | sed -e 's/^TERM  *//' -e 's/ .*//')
     fi
     for term in ${match_lhs} ; do
-        if [[ "${safe_term}" == ${term} || "${TERM}" == ${term} ]] ; then
+        if [[ "${safe_term}" == "${term}" || "${TERM}" == "${term}" ]] ; then
             use_color="true"
             break
         fi
@@ -93,6 +101,7 @@ detect_color() {
         RED="\033[38;5;196m"
         YELLOW="\033[38;5;226m"
         GREEN="\033[38;5;46m"
+        # shellcheck disable=SC2034
         BLUE="\033[38;5;27m"
         CYAN="\033[38;5;14m"
         NORMAL="\033[39m"
@@ -100,17 +109,20 @@ detect_color() {
         RED=""
         YELLOW=""
         GREEN=""
+        # shellcheck disable=SC2034
         BLUE=""
         CYAN=""
         NORMAL=""
     fi
 
-    local my_tty=$(tty)
+    local my_tty=
+    my_tty=$(tty)
     if [[ "${my_tty}" =~ 'not a tty' ]] ; then
         my_tty='-'
     fi
 
     if [[ "${my_tty}" = '-' || "${safe_term}" = "dump" ]] ; then
+        # shellcheck disable=SC2034
         HAS_TTY='n'
     fi
 
@@ -146,6 +158,7 @@ eval_common_options() {
                     RED=""
                     YELLOW=""
                     GREEN=""
+                    # shellcheck disable=SC2034
                     BLUE=""
                     CYAN=""
                     NORMAL=""
@@ -164,7 +177,7 @@ eval_common_options() {
                 --) shift
                     break
                     ;;
-                *)  REMAINING_OPTS+=($1)
+                *)  REMAINING_OPTS+=( "$1" )
                     shift
                     ;;
             esac
@@ -178,7 +191,7 @@ eval_common_options() {
     if [[ "$#" -gt "0" ]] ; then
         REMAINING_ARGS=("--")
         while [[ "$#" -gt "0" ]]  ; do
-            REMAINING_ARGS+=($1)
+            REMAINING_ARGS+=( "$1" )
             shift
         done
     fi
@@ -229,7 +242,7 @@ eval_ldap_options() {
                 --) shift
                     break
                     ;;
-                *)  REMAINING_OPTS+=($1)
+                *)  REMAINING_OPTS+=( "$1" )
                     shift
                     ;;
             esac
@@ -239,7 +252,7 @@ eval_ldap_options() {
     if [[ "$#" -gt "0" ]] ; then
         REMAINING_ARGS=("--")
         while [[ "$#" -gt "0" ]]  ; do
-            REMAINING_ARGS+=($1)
+            REMAINING_ARGS+=( "$1" )
             shift
         done
     fi
@@ -266,22 +279,22 @@ debug() {
     if [[ "${VERBOSE}" != "y" ]] ; then
         return 0
     fi
-    echo -e " * [$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2
+    echo -e " * [$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $*" >&2
 }
 
 #------------------------------------------------------------------------------
 info() {
-    echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2
+    echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $*" >&2
 }
 
 #------------------------------------------------------------------------------
 warn() {
-    echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
+    echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $*" >&2
 }
 
 #------------------------------------------------------------------------------
 error() {
-    echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2
+    echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $*" >&2
 }
 
 #------------------------------------------------------------------------------
@@ -328,11 +341,17 @@ set_locale() {
         LC_COLLATE="${new_locale}"
         LC_MONETARY="${new_locale}"
         LC_MESSAGES="${new_locale}"
+        # shellcheck disable=SC2034
         LC_PAPER="${new_locale}"
+        # shellcheck disable=SC2034
         LC_NAME="${new_locale}"
+        # shellcheck disable=SC2034
         LC_ADDRESS="${new_locale}"
+        # shellcheck disable=SC2034
         LC_TELEPHONE="${new_locale}"
+        # shellcheck disable=SC2034
         LC_MEASUREMENT="${new_locale}"
+        # shellcheck disable=SC2034
         LC_IDENTIFICATION="${new_locale}"
     fi