From 153ec73aa350c5633d1ef2b1e1d7d3dde8e92b7e Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 31 Jul 2019 13:10:28 +0200 Subject: [PATCH] add shellcheck compliance --- bin/vhost-add | 27 +++++++++++++++++++-------- share/bin/form_choices | 4 +--- share/bin/form_input | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/vhost-add b/bin/vhost-add index 90c6d19..f17f814 100755 --- a/bin/vhost-add +++ b/bin/vhost-add @@ -1,8 +1,12 @@ #!/bin/sh -export SCRIPT_NAME="$(realpath "$0")" -export SCRIPT_PATH="$(dirname "$SCRIPT_NAME")" -export PATH="$SCRIPT_PATH/../share/bin/:$PATH" +SCRIPT_NAME="$(realpath "$0")" +SCRIPT_PATH="$(dirname "$SCRIPT_NAME")" +PATH="$SCRIPT_PATH/../share/bin/:$PATH" + +export SCRIPT_NAME +export SCRIPT_PATH +export PATH cd "$SCRIPT_PATH/../" @@ -11,7 +15,7 @@ cd "$SCRIPT_PATH/../" exit_if_empty() { if [ -z "$1" ]; then if [ -n "$2" ]; then - printf "$2\n" + printf "%s\\n" "$2" fi exit 1 @@ -33,7 +37,7 @@ DOMAIN_ALIASES="$(form_input -t "$TITLE" -l "Aliase(s)")" WEB_HTTP="$(form_yes_no -t "$TITLE" -l "Support of HTTP (recommanded)")" WEB_HTTPS="$(form_yes_no -t "$TITLE" -l "Support of HTTPS (recommanded)")" -if [ "$WEB_HTTP" = "yes" -a "$WEB_HTTPS" = "yes" ]; then +if [ "$WEB_HTTP" = "yes" ] && [ "$WEB_HTTPS" = "yes" ]; then WEB_HTTPS_FORCE="$(form_yes_no -t "$TITLE" -l "Redirect HTTP to HTTPS (recommanded)")" fi @@ -61,7 +65,14 @@ USER_PASSWORD="$(tr -dc "12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urando SYSTEM_USER_USERNAME="$(form_input -t "$TITLE" -l "System username" -d "web" -r)" SYSTEM_USER_GROUP="webgroup" -SYSTEM_USER_PASSWORD=$(export PASSWORD="$USER_PASSWORD"; export SALT=$(date +'%S'); crypt) + +SYSTEM_USER_PASSWORD=$( + PASSWORD="$USER_PASSWORD" + SALT=$(date +'%S') + export PASSWORD + export SALT + crypt +) exit_if_empty "$SYSTEM_USER_USERNAME" "Aborded! (SYSTEM_USERNAME_EMPTY)" @@ -89,7 +100,7 @@ rm "$TMP_FILE" CONTINUE="$(form_yes_no -t "$TITLE" -l "Do you confirm?")" if [ "$CONTINUE" = "no" ]; then - printf "Aborded!\n" + printf "Aborded!\\n" exit 0 fi @@ -109,7 +120,7 @@ chmod o-r "/services/web/www/$DOMAIN" SERVICES_TO_RELOAD="apache2" SYSTEM_USER_ID="$(id -u "$SYSTEM_USER_USERNAME")" -PHP_FPM_PORT=$(($SYSTEM_USER_ID + 12000)) +PHP_FPM_PORT=$((SYSTEM_USER_ID + 12000)) if [ "$WEB_HTTP" = "yes" ]; then VHOST_FILE_SA="/etc/apache2/sites-available/${DOMAIN}.${WEB_HTTP_PORT}.conf" diff --git a/share/bin/form_choices b/share/bin/form_choices index e522481..c7f27bd 100755 --- a/share/bin/form_choices +++ b/share/bin/form_choices @@ -7,8 +7,6 @@ HEIGHT=25 MENU_HEIGHT=16 WIDTH=50 -PARAMS= - while getopts "t:l:d:h:w:m:r" option; do case "$option" in l) LABEL="$OPTARG";; @@ -27,4 +25,4 @@ fi shift $((OPTIND-1)) -echo "$(whiptail --title "$TITLE" --menu "$LABEL" $HEIGHT $WIDTH $MENU_HEIGHT "$@" 3>&1 1>&2 2>&3)" +whiptail --title "$TITLE" --menu "$LABEL" $HEIGHT $WIDTH $MENU_HEIGHT "$@" 3>&1 1>&2 2>&3 diff --git a/share/bin/form_input b/share/bin/form_input index 8305480..fac177b 100755 --- a/share/bin/form_input +++ b/share/bin/form_input @@ -33,7 +33,7 @@ while [ $DO_ASK -eq 1 ]; do STATUS=$? if [ $STATUS -eq 0 ]; then - if [ $REQUIRED -eq 1 -a -z "$VALUE" ]; then + if [ $REQUIRED -eq 1 ] && [ -z "$VALUE" ]; then DO_ASK=1 else DO_ASK=0