]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Applying shellcheck to bin/update-env.sh
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 16:36:52 +0000 (17:36 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 16:36:52 +0000 (17:36 +0100)
bin/update-env.sh

index 63635fa5988ddabe6356de8e13264528ab7a55fb..049ece893bca7a78e42e871067d9229853c86ac2 100755 (executable)
@@ -7,21 +7,19 @@ VERBOSE="n"
 DEBUG="n"
 QUIET='n'
 
-VERSION="2.1"
+VERSION="2.2"
 
 # console colors:
 RED=""
 YELLOW=""
 GREEN=""
-BLUE=""
+BLUE=""
 CYAN=""
 NORMAL=""
 
-HAS_TTY='y'
-
-BASENAME="$(basename ${0})"
-BASE_DIR=$( dirname $( dirname $0 ) )
-cd ${BASE_DIR}
+BASENAME=$(basename "${0}" )
+BASE_DIR=$( dirname "$( dirname "$0" )" )
+cd "${BASE_DIR}"
 BASE_DIR=$( readlink -f . )
 
 PIP_OPTIONS=
@@ -36,16 +34,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
+        # shellcheck disable=SC2053
         if [[ "${safe_term}" == ${term} || "${TERM}" == ${term} ]] ; then
             use_color="true"
             break
@@ -57,28 +56,24 @@ detect_color() {
         RED="\033[38;5;196m"
         YELLOW="\033[38;5;226m"
         GREEN="\033[38;5;46m"
-        BLUE="\033[38;5;27m"
+        BLUE="\033[38;5;27m"
         CYAN="\033[38;5;36m"
         NORMAL="\033[39m"
-        HAS_COLORS="y"
     else
         RED=""
         YELLOW=""
         GREEN=""
-        BLUE=""
+        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
-        HAS_TTY='n'
-    fi
-
 }
 detect_color
 
@@ -91,7 +86,7 @@ debug() {
     if [[ "${VERBOSE}" != "y" ]] ; then
         return 0
     fi
-    echo -e " * [$(my_date)] [${BASENAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2
+    echo -e " * [$(my_date)] [${BASENAME}:${CYAN}DEBUG${NORMAL}]: $*" >&2
 }
 
 #------------------------------------------------------------------------------
@@ -100,27 +95,27 @@ info() {
         return 0
     fi
     if [[ "${VERBOSE}" == "y" ]] ; then
-        echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $@"
+        echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $*"
     else
-        echo -e " ${GREEN}*${NORMAL} $@"
+        echo -e " ${GREEN}*${NORMAL} $*"
     fi
 }
 
 #------------------------------------------------------------------------------
 warn() {
     if [[ "${VERBOSE}" == "y" ]] ; then
-        echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
+        echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $*" >&2
     else
-        echo -e " ${YELLOW}*${NORMAL} [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
+        echo -e " ${YELLOW}*${NORMAL} [${BASENAME}:${YELLOW}WARN${NORMAL}] : $*" >&2
     fi
 }
 
 #------------------------------------------------------------------------------
 error() {
     if [[ "${VERBOSE}" == "y" ]] ; then
-        echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2
+        echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $*" >&2
     else
-        echo -e " ${RED}*${NORMAL} [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2
+        echo -e " ${RED}*${NORMAL} [${BASENAME}:${RED}ERROR${NORMAL}]: $*" >&2
     fi
 }
 
@@ -178,7 +173,8 @@ get_options() {
 
     set +e
     tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" )
-    if [[ $? != 0 ]] ; then
+    ret="$?"
+    if [[ "${ret}" != 0 ]] ; then
         echo "" >&2
         usage >&2
         exit 1
@@ -203,20 +199,18 @@ get_options() {
                 RED=""
                 YELLOW=""
                 GREEN=""
-                BLUE=""
+                BLUE=""
                 CYAN=""
                 NORMAL=""
-                HAS_COLORS="n"
                 shift
                 ;;
             --nocolor)
                 RED=""
                 YELLOW=""
                 GREEN=""
-                BLUE=""
+                BLUE=""
                 CYAN=""
                 NORMAL=""
-                HAS_COLORS="n"
                 shift
                 ;;
             -h|--help)
@@ -290,12 +284,12 @@ init_venv() {
         for py_version in "${valid_py_versions[@]}" ; do
             python="python${py_version}"
             debug "Testing Python binary '${CYAN}${python}${NORMAL}' …"
-            if type -t ${python} >/dev/null ; then
+            if type -t "${python}" >/dev/null ; then
                 found="y"
                 empty_line
                 info "Found '${GREEN}${python}${NORMAL}'."
                 empty_line
-                virtualenv --python=${python} venv
+                virtualenv --python="${python}" venv
                 break
             fi
         done
@@ -308,6 +302,7 @@ init_venv() {
         fi
     fi
 
+    # shellcheck disable=SC1091
     . venv/bin/activate || exit 5
 
 }