meta-ampere: fix shellcheck issues

Fix all issues from the shellcheck checked on bash shells under
meta-ampere.

Tested: Verify the following features:
1. Power control (on,off, cycle, graceful shutdown, hard reset).
2. UART switching.
3. UEFI firmware update.

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: Idabf839b7521ecadb642230cc8bb3472c787002e
diff --git a/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh b/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh
index 58fffd8..f285898 100755
--- a/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh
+++ b/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Copyright (c) 2020 Ampere Computing LLC
+# Copyright (c) 2021 Ampere Computing LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -19,24 +19,13 @@
 #        <UARTx_MODE> of 1 sets CPU To HDR_CONN
 #        <UARTx_MODE> of 2 sets BMC to CPU (eg dropbear ssh server on port 2200)
 
+# shellcheck source=/dev/null
+source /usr/sbin/gpio-lib.sh
+
 if [ $# -lt 2 ]; then
 	exit 1
 fi
 
-function set_gpio_active_low() {
-  if [ $# -ne 2 ]; then
-    echo "set_gpio_active_low: need both GPIO# and initial level";
-    return;
-  fi
-
-  if [ ! -d /sys/class/gpio/gpio$1 ]; then
-    echo $1 > /sys/class/gpio/export
-  fi
-  echo $2 > /sys/class/gpio/gpio$1/direction
-}
-
-GPIO_BASE=$(cat /sys/class/gpio/gpio*/base)
-
 case "$1" in
 	1) GPIO_UARTx_MODE0=56
 	   # CPU0 UART0 connects to BMC UART1
@@ -65,17 +54,17 @@
 # of requested console port.
 # Example format:  Accepted: 1; Connected: 1;
 CONNECTED=$(systemctl --no-pager status obmc-console-ttyS${CONSOLE_PORT}-ssh.socket | grep -w Connected | cut -d ':' -f 3 | tr -d ' ;')
-if [ ! $CONNECTED -le 1 ]; then
+if [ ! "$CONNECTED" -le 1 ]; then
 	exit 0
 fi
 
 echo "Ampere UART MUX CTRL UART port $1 to mode $2"
 
 case "$2" in
-	1) set_gpio_active_low $((${GPIO_BASE} + ${GPIO_UARTx_MODE0})) low
+	1) gpio_configure_output "${GPIO_UARTx_MODE0}" 0
 	   exit 0
 	;;
-	2) set_gpio_active_low $((${GPIO_BASE} + ${GPIO_UARTx_MODE0})) high
+	2) gpio_configure_output "${GPIO_UARTx_MODE0}" 1
 	   exit 0
 	;;
 	*) echo "Invalid UART mode selection"
diff --git a/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/obmc-console-server-setup.sh b/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/obmc-console-server-setup.sh
index fe2d5ab..4e0a013 100644
--- a/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/obmc-console-server-setup.sh
+++ b/meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/obmc-console-server-setup.sh
@@ -14,8 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -euo pipefail
-
 tty="$1"
 uart=0
 
@@ -39,4 +37,4 @@
 # this value should be set to 1
 /usr/sbin/ampere_uartmux_ctrl.sh ${uart} 2
 
-/usr/sbin/obmc-console-server --config /etc/obmc-console/server.${tty}.conf ${tty}
+/usr/sbin/obmc-console-server --config /etc/obmc-console/server."${tty}".conf "${tty}"
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh
index 8d3d543..1e1cbc5 100644
--- a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh
@@ -22,14 +22,14 @@
 
 # Get current state
 object=$(busctl tree $SERVICE --list | grep system_fault)
-state=$(busctl get-property $SERVICE $object $INTERFACE $PROPERTY \
+state=$(busctl get-property $SERVICE "$object" $INTERFACE $PROPERTY \
 	  |  awk '{print $NF;}')
 
-if [ "$state" == "false" ]; then
-    target='true'
+if [ "$state" = "false" ]; then
+	target='true'
 else
-    target='false'
+	target='false'
 fi
 
 # Set target state
-busctl set-property $SERVICE $object $INTERFACE $PROPERTY b $target
+busctl set-property $SERVICE "$object" $INTERFACE $PROPERTY b $target
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/id-button/toggle_identify_led.sh b/meta-ampere/meta-jade/recipes-phosphor/gpio/id-button/toggle_identify_led.sh
index d62c84a..06b2d55 100755
--- a/meta-ampere/meta-jade/recipes-phosphor/gpio/id-button/toggle_identify_led.sh
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/id-button/toggle_identify_led.sh
@@ -22,24 +22,24 @@
 
 # Get enclosure_identify state
 identify_object=$(busctl tree $SERVICE --list | grep -m 1 identify)
-identify_state=$(busctl get-property $SERVICE $identify_object $INTERFACE $PROPERTY \
-	  |  awk '{print $NF;}')
+identify_state=$(busctl get-property $SERVICE "$identify_object" $INTERFACE $PROPERTY \
+			|  awk '{print $NF;}')
 
 # Get enclosure_identify_blink state
 identify_blink_object=$(busctl tree $SERVICE --list | grep identify_blink)
-identify_blink_state=$(busctl get-property $SERVICE $identify_blink_object $INTERFACE $PROPERTY \
-	  |  awk '{print $NF;}')
+identify_blink_state=$(busctl get-property $SERVICE "$identify_blink_object" $INTERFACE $PROPERTY \
+			|  awk '{print $NF;}')
 
 # Set state
-if [[ "$identify_state" == "false" && "$identify_blink_state" == "false" ]]; then
+if [ "$identify_state" = "false" ] && [ "$identify_blink_state" = "false" ]; then
     # Turn on the UID LED
-    busctl set-property $SERVICE $identify_object $INTERFACE $PROPERTY b true
-elif [[ "$identify_state" == "false" && "$identify_blink_state" == "true" ]]; then
+    busctl set-property $SERVICE "$identify_object" $INTERFACE $PROPERTY b true
+elif [ "$identify_state" = "false" ] && [ "$identify_blink_state" = "true" ]; then
     # Turn off the UID LED when LED is blinking state
-    busctl set-property $SERVICE $identify_blink_object $INTERFACE $PROPERTY b false
-elif [[ "$identify_state" == "true" && "$identify_blink_state" == "false" ]]; then
+    busctl set-property $SERVICE "$identify_blink_object" $INTERFACE $PROPERTY b false
+elif [ "$identify_state" = "true" ] && [ "$identify_blink_state" = "false" ]; then
     # Turn off the UID LED
-    busctl set-property $SERVICE $identify_object $INTERFACE $PROPERTY b false
+    busctl set-property $SERVICE "$identify_object" $INTERFACE $PROPERTY b false
 else
     echo "Invalid case! When identify_blink_state is true, the identify_state will set to false"
 fi
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset/ampere_psu_reset_hotswap.sh b/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset/ampere_psu_reset_hotswap.sh
old mode 100644
new mode 100755
index 65bff9d..37a3ce3
--- a/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset/ampere_psu_reset_hotswap.sh
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset/ampere_psu_reset_hotswap.sh
@@ -29,10 +29,10 @@
 # $1 will be the name of the psu
 PSU=$1
 
-if [[ $PSU == 1 ]]; then
+if [ "$PSU" = 1 ]; then
 	HSC_PMBUS_NUM=$HSC1_PMBUS_NUM
 	HSC_SLAVE_ADDR=$HSC1_SLAVE_ADDR
-elif [[ $PSU == 2 ]]; then
+elif [ "$PSU" = 2 ]; then
 	HSC_PMBUS_NUM=$HSC2_PMBUS_NUM
 	HSC_SLAVE_ADDR=$HSC2_SLAVE_ADDR
 else
@@ -43,22 +43,20 @@
 
 # Check HOST state
 chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
-if [[ "$chassisstate" == 'Off' ]]; then
+if [ "$chassisstate" = 'Off' ]; then
 	echo "HOST is being OFF, so can't access the i2c $HSC_PMBUS_NUM. Please Turn ON HOST !"
 	exit 1
 fi
 
 # Check FET health problems
-data=$(i2cget -f -y $HSC_PMBUS_NUM $HSC_SLAVE_ADDR $STATUS_MFR_SPECIFIC)
-
-if [[ $? -ne 0 ]]; then
+if ! data=$(i2cget -f -y $HSC_PMBUS_NUM $HSC_SLAVE_ADDR $STATUS_MFR_SPECIFIC); then
 	echo "ERROR: Can't access the i2c. Please check /dev/i2c-$HSC_PMBUS_NUM"
 	exit 1
 fi
 
 psu_sts=$(((data & 0x80) != 0))
 
-if [[ $psu_sts == 1 ]]; then
+if [ $psu_sts = 1 ]; then
 	echo "PSU $PSU: FET health problems have been detected"
 	echo "Reset Hot swap output on PSU $PSU"
 	# Disable Hot swap output
@@ -71,4 +69,4 @@
 
 else
 	echo "PSU $PSU: FET health problems have not been detected"
-fi
\ No newline at end of file
+fi