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-common/recipes-phosphor/flash/phosphor-software-manager/firmware_update.sh b/meta-ampere/meta-common/recipes-phosphor/flash/phosphor-software-manager/firmware_update.sh
index af3e2be..cc39f30f 100755
--- a/meta-ampere/meta-common/recipes-phosphor/flash/phosphor-software-manager/firmware_update.sh
+++ b/meta-ampere/meta-common/recipes-phosphor/flash/phosphor-software-manager/firmware_update.sh
@@ -21,31 +21,29 @@
 
 usage () {
 	echo "Usage:"
-	echo "	$(basename $0) <image path> "
+	echo "      $(basename "$0") <image path> "
 	echo "Where:"
 	echo "	<image path>: the path link to folder, which include image file and MANIFEST"
 	echo "Example:"
-	echo "	$(basename $0) /tmp/images/ghdh1393"
+	echo "     $(basename "$0") /tmp/images/ghdh1393"
 }
 
 
 IMG_PATH="$1"
-if [ ! -d $IMG_PATH ]; then
-	echo $IMG_PATH
+if [ ! -d "$IMG_PATH" ]; then
 	echo "The folder $IMG_PATH does not exist"
 	usage
 	exit 1
 fi
 
 MANIFEST_PATH="${IMG_PATH}/MANIFEST"
-if [ ! -f $MANIFEST_PATH ]; then
-	echo $MANIFEST_PATH
+if [ ! -f "$MANIFEST_PATH" ]; then
 	echo "The MANIFEST file $MANIFEST_PATH does not exist"
 	usage
 	exit 1
 fi
 
-EXTENDED_VERSION=$(awk '/ExtendedVersion/ {print}' ${MANIFEST_PATH} | cut -d "=" -f 2)
+EXTENDED_VERSION=$(awk '/ExtendedVersion/ {print}' "${MANIFEST_PATH}" | cut -d "=" -f 2)
 
 # If the ExtendedVersion is empty, set default to update UEFI/EDKII on primary device
 if [ -z "$EXTENDED_VERSION" ]
@@ -56,28 +54,28 @@
 # Assign the command based on the ExtendedVersion
 case ${EXTENDED_VERSION} in
 	"primary")
-		export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \))
-		export CMD='/usr/sbin/ampere_flash_bios.sh $IMAGE 1'
+		IMAGE=$(find "${IMG_PATH}" -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \))
+		CMD="/usr/sbin/ampere_flash_bios.sh $IMAGE 1"
 		;;
 
 	"secondary")
-		export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \))
-		export CMD='/usr/sbin/ampere_flash_bios.sh $IMAGE 2'
+		IMAGE=$(find "${IMG_PATH}" -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \))
+		CMD="/usr/sbin/ampere_flash_bios.sh $IMAGE 2"
 		;;
 
 	"scp-primary")
-		export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \))
-		export CMD='/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 1'
+		IMAGE=$(find "${IMG_PATH}" -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \))
+		CMD="/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 1"
 		;;
 
 	"scp-secondary")
-		export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \))
-		export CMD='/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 2'
+		IMAGE=$(find "${IMG_PATH}" -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \))
+		CMD="/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 2"
 		;;
 
 	"fru")
-		export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.bin" \))
-		export CMD='/usr/sbin/ampere_firmware_upgrade.sh fru $IMAGE'
+		IMAGE=$(find "${IMG_PATH}" -type f \( -name "*.bin" \))
+		CMD="/usr/sbin/ampere_firmware_upgrade.sh fru $IMAGE"
 		;;
 
 	*)
@@ -91,11 +89,10 @@
 then
 	echo "ERROR: The image file: No such file or directory"
 	exit 1
-else
-	eval $CMD
 fi
 
-if [[ $? -ne 0 ]]; then
+if ! eval "$CMD";
+then
 	echo "ERROR: The firmware update not successfull"
 	exit 1
 fi
diff --git a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
index 7a9ace3..b7f4bc5 100755
--- a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
@@ -18,7 +18,7 @@
         OFFSET=$1
 
 	# Check the PNOR partition available
-	HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
+	HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
 	if [ -z "$HOST_MTD" ];
 	then
 		# If the PNOR partition is not available, then bind again driver
@@ -26,7 +26,7 @@
 		echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/bind
 		sleep 2
 
-		HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
+		HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
 		if [ -z "$HOST_MTD" ];
 		then
 			echo "Fail to probe Host SPI-NOR device"
@@ -35,18 +35,17 @@
 	fi
 
 	echo "--- Flashing firmware to @/dev/$HOST_MTD offset=$OFFSET"
-	flashcp -v $IMAGE /dev/$HOST_MTD $OFFSET
+	flashcp -v "$IMAGE" /dev/"$HOST_MTD" "$OFFSET"
 }
 
 
 if [ $# -eq 0 ]; then
-	echo "Usage: $(basename $0) <BIOS image file>"
+	echo "Usage: $(basename "$0") <BIOS image file>"
 	exit 0
 fi
 
 IMAGE="$1"
-if [ ! -f $IMAGE ]; then
-	echo $IMAGE
+if [ ! -f "$IMAGE" ]; then
 	echo "The image file $IMAGE does not exist"
 	exit 1
 fi
@@ -70,9 +69,7 @@
 
 # Switch the host SPI bus to BMC"
 echo "--- Switch the host SPI bus to BMC."
-gpioset 0 226=0
-
-if [[ $? -ne 0 ]]; then
+if ! gpioset 0 226=0; then
 	echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state"
 	exit 1
 fi
@@ -82,9 +79,7 @@
 
 # Switch the host SPI bus to HOST."
 echo "--- Switch the host SPI bus to HOST."
-gpioset 0 226=1
-
-if [[ $? -ne 0 ]]; then
+if ! gpioset 0 226=1; then
 	echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state"
 	exit 1
 fi
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh
index 4e4d6f3..8182b4c 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh
@@ -5,43 +5,44 @@
 ETHERNET_INTERFACE="eth1"
 ETHERNET_NCSI="eth0"
 ENV_ETH="eth1addr"
-ENV_MAC_ADDR=`fw_printenv | grep $ENV_ETH`
+ENV_MAC_ADDR=$(fw_printenv | grep $ENV_ETH)
 
 # Workaround to dhcp NC-SI eth0 interface when BMC boot up
 ifconfig ${ETHERNET_NCSI} down
 ifconfig ${ETHERNET_NCSI} up
 
 # Read FRU Board Custom Field 1 to get the MAC address
-CUSTOM_FIELD_1=`busctl get-property xyz.openbmc_project.FruDevice /xyz/openbmc_project/FruDevice/Mt_Jade_Motherboard xyz.openbmc_project.FruDevice BOARD_INFO_AM1`
-MAC_ADDR=`echo $CUSTOM_FIELD_1 | cut -d "\"" -f 2`
+CUSTOM_FIELD_1=$(busctl get-property xyz.openbmc_project.FruDevice /xyz/openbmc_project/FruDevice/Mt_Jade_Motherboard xyz.openbmc_project.FruDevice BOARD_INFO_AM1)
+MAC_ADDR=$(echo "$CUSTOM_FIELD_1" | cut -d "\"" -f 2)
 
 # Check if BMC MAC address is exported
 if [ -z "${MAC_ADDR}" ]; then
-    echo "ERROR: No BMC MAC address is detected from FRU Inventory information!"
-    # Return 1 so that systemd knows the service failed to start
-    exit 1
+	echo "ERROR: No BMC MAC address is detected from FRU Inventory information!"
+	# Return 1 so that systemd knows the service failed to start
+	exit 1
 fi
 
 # Check if BMC MAC address is exported
 if [[ $ENV_MAC_ADDR =~ $MAC_ADDR ]]; then
-    echo "WARNING: BMC MAC address already exist!"
-    exit 0
+	echo "WARNING: BMC MAC address already exist!"
+	exit 0
 fi
 
 # Request to update the MAC address
-fw_setenv ${ENV_ETH} ${MAC_ADDR}
+fw_setenv ${ENV_ETH} "${MAC_ADDR}"
 
-if [[ $? -ne 0 ]]; then
-   echo "ERROR: Fail to set MAC address to ${ENV_ETH}"
-   exit 1
+if fw_setenv ${ENV_ETH} "${MAC_ADDR}";
+then
+	echo "ERROR: Fail to set MAC address to ${ENV_ETH}"
+	exit 1
 fi
 
 # Request to restart the service
 ifconfig ${ETHERNET_INTERFACE} down
-ifconfig ${ETHERNET_INTERFACE} hw ether ${MAC_ADDR}
-if [[ $? -ne 0 ]]; then
-   echo "ERROR: Can not update MAC ADDR to ${ETHERNET_INTERFACE}"
-   exit 1
+if ! ifconfig ${ETHERNET_INTERFACE} hw ether "${MAC_ADDR}";
+then
+	echo "ERROR: Can not update MAC ADDR to ${ETHERNET_INTERFACE}"
+	exit 1
 fi
 ifconfig ${ETHERNET_INTERFACE} up
 
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
index a2578fa..c3772fb 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
@@ -1,5 +1,6 @@
 #!/bin/bash
 
+# shellcheck source=/dev/null
 source /usr/sbin/gpio-lib.sh
 
 # GPIOAC3 BMC_SPI0_BACKUP_SEL Boot from MAIN SPI-HOST
@@ -29,7 +30,7 @@
 # =======================================================
 # Below GPIOs are controlled by other services so just
 # initialize in A/C power only.
-cmdline=`cat /proc/cmdline`
+cmdline=$(cat /proc/cmdline)
 if [[ $cmdline == *resetreason=power* ]]; then
 	# BMC_GPIOR2_EXT_HIGHTEMP_L
 	gpio_configure_output 138 1
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
index 8e4f455..1a098f4 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
@@ -1,43 +1,45 @@
 #!/bin/bash
+
+# shellcheck source=/dev/null
 source /usr/sbin/gpio-defs.sh
 source /usr/sbin/gpio-lib.sh
 
 function usage() {
-    echo "usage: ampere_gpio_utils.sh [power] [on|off]";
+	echo "usage: ampere_gpio_utils.sh [power] [on|off]";
 }
 
 set_gpio_power_off() {
-    echo "Setting GPIO before Power off"
-    gpio_configure_output $OCP_AUX_PWREN 1
-    gpio_configure_output $OCP_MAIN_PWREN 0
-    gpio_configure_output $SPI0_PROGRAM_SEL 0
+	echo "Setting GPIO before Power off"
+	gpio_configure_output "$OCP_AUX_PWREN" 1
+	gpio_configure_output "$OCP_MAIN_PWREN" 0
+	gpio_configure_output "$SPI0_PROGRAM_SEL" 0
 }
 
 set_gpio_power_on() {
-    echo "Setting GPIO before Power on"
-    gpio_configure_output $OCP_AUX_PWREN 1
-    gpio_configure_output $OCP_MAIN_PWREN 1
-    gpio_configure_output $SPI0_PROGRAM_SEL 1
-    gpio_configure_output $SPI0_BACKUP_SEL 0
+	echo "Setting GPIO before Power on"
+	gpio_configure_output "$OCP_AUX_PWREN" 1
+	gpio_configure_output "$OCP_MAIN_PWREN" 1
+	gpio_configure_output "$SPI0_PROGRAM_SEL" 1
+	gpio_configure_output "$SPI0_BACKUP_SEL" 0
 }
 
 if [ $# -lt 2 ]; then
-    echo "Total number of parameter=$#"
-    echo "Insufficient parameter"
-    usage;
-    exit 0;
+	echo "Total number of parameter=$#"
+	echo "Insufficient parameter"
+	usage;
+	exit 0;
 fi
 
-if [ $1 == "power" ]; then
-    if [ $2 == "on" ]; then
-        set_gpio_power_on
-    elif [ $2 == "off" ]; then
-        set_gpio_power_off
-    fi
-    exit 0;
+if [ "$1" == "power" ]; then
+	if [ "$2" == "on" ]; then
+		set_gpio_power_on
+	elif [ "$2" == "off" ]; then
+		set_gpio_power_off
+	fi
+	exit 0;
 else
-    echo "Invalid parameter1=$1"
-    usage;
-    exit 0;
+	echo "Invalid parameter1=$1"
+	usage;
+	exit 0;
 fi
 exit 0;
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh
index 9eeeeca..024336d 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh
@@ -1,45 +1,38 @@
 #!/bin/bash
 
+# shellcheck source=/dev/null
 source /usr/sbin/gpio-defs.sh
 source /usr/sbin/gpio-lib.sh
 
-host_status() {
-    st=$(busctl get-property xyz.openbmc_project.State.Host /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host CurrentHostState | cut -d"." -f6)
-    if [ "$st" == "Running\"" ]; then
-        echo "on"
-    else
-        echo "off"
-    fi
-}
-
 createFile=$1
-setState=$2
 
-if [ $(host_status) == "on" ]; then
-    exit 0
+# Check current Host status. Do nothing when the Host is currently ON
+st=$(busctl get-property xyz.openbmc_project.State.Host \
+	/xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host \
+	CurrentHostState | cut -d"." -f6)
+if [ "$st" == "Running\"" ]; then
+	exit 0
 fi
 
 # Time out to check S0_FW_BOOT_OK is 60 seconds
 cnt=60
 val=0
-while [ $cnt -gt 0 ];
+while [ "$cnt" -gt 0 ];
 do
-    val=$(gpio_get_val $S0_CPU_FW_BOOT_OK)
-    cnt=$((cnt - 1))
-    echo "$cnt S0_CPU_FW_BOOT_OK = $val"
-    if [ $val == 1 ]; then
-        # Sleep 5 second before the host is ready
-        sleep 5
-        if [ $createFile == 1 ]; then
-            if [ ! -d "/run/openbmc" ]; then
-                mkdir -p /run/openbmc
-            fi
-            echo "Creating /run/openbmc/host@0-on"
-            touch /run/openbmc/host@0-on
-        fi
-        exit 0
-    fi
-    sleep 1
+	val=$(gpio_get_val "$S0_CPU_FW_BOOT_OK")
+	cnt=$((cnt - 1))
+	echo "$cnt S0_CPU_FW_BOOT_OK = $val"
+	if [ "$val" == 1 ]; then
+		# Sleep 5 second before the host is ready
+		sleep 5
+		if [ "$createFile" == 1 ]; then
+			mkdir -p /run/openbmc
+			echo "Creating /run/openbmc/host@0-on"
+			touch /run/openbmc/host@0-on
+		fi
+		exit 0
+	fi
+	sleep 1
 done
 
 exit 1
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh
index 2c8ba3d91..d9ca2ed 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh
@@ -1,131 +1,120 @@
 #!/bin/bash
-#ampere_platform_config.sh is platform configuration file
+
+# shellcheck source=/dev/null
 source /usr/sbin/gpio-defs.sh
 
 # Usage of this utility
 function usage() {
-  echo "usage: power-util mb [status|shutdown_ack|force_reset|soft_off]";
+	echo "Usage:"
+	echo "  ampere_power_util.sh mb [status|shutdown_ack|force_reset|soft_off]";
 }
 
 power_status() {
-  st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6)
-  if [ "$st" == "On\"" ]; then
-  echo "on"
-  else
-  echo "off"
-  fi
+	st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6)
+	if [ "$st" == "On\"" ]; then
+		echo "on"
+	else
+		echo "off"
+	fi
 }
 
 shutdown_ack() {
-  if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
-    echo "Receive shutdown ACK triggered after softportoff the host."
-    touch /run/openbmc/host@0-softpoweroff-shutdown-ack
-  else
-    echo "Receive shutdown ACK triggered"
-    sleep 3
-    systemctl start obmc-chassis-poweroff@0.target
-  fi
+	if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
+		echo "Receive shutdown ACK triggered after softportoff the host."
+		touch /run/openbmc/host@0-softpoweroff-shutdown-ack
+	else
+		echo "Receive shutdown ACK triggered"
+		sleep 3
+		systemctl start obmc-chassis-poweroff@0.target
+	fi
 }
 
 soft_off() {
-  # Trigger shutdown_req
-  touch /run/openbmc/host@0-softpoweroff
-  gpioset -l $GPIO_CHIP0_IDX $S0_SHD_REQ_L=1
-  sleep 1s
-  gpioset -l $GPIO_CHIP0_IDX $S0_SHD_REQ_L=0
+	# Trigger shutdown_req
+	touch /run/openbmc/host@0-softpoweroff
+	gpioset -l 0 "$S0_SHD_REQ_L"=1
+	sleep 1s
+	gpioset -l 0 "$S0_SHD_REQ_L"=0
 
-  # Wait for shutdown_ack from the host in 30 seconds
-  cnt=30
-  while [ $cnt -gt 0 ];
-  do
-    # Wait for SHUTDOWN_ACK and create the host@0-softpoweroff-shutdown-ack
-    if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
-      break
-    fi
-    sleep 1
-    cnt=$((cnt - 1))
-  done
-  # Softpoweroff is successed
-  sleep 2
-  rm -rf /run/openbmc/host@0-softpoweroff
-  if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
-    rm -rf /run/openbmc/host@0-softpoweroff-shutdown-ack
-  fi
-  echo 0
+	# Wait for shutdown_ack from the host in 30 seconds
+	cnt=30
+	while [ $cnt -gt 0 ];
+	do
+		# Wait for SHUTDOWN_ACK and create the host@0-softpoweroff-shutdown-ack
+		if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
+			break
+		fi
+		sleep 1
+		cnt=$((cnt - 1))
+	done
+	# Softpoweroff is successed
+	sleep 2
+	rm -rf /run/openbmc/host@0-softpoweroff
+	if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
+		rm -rf /run/openbmc/host@0-softpoweroff-shutdown-ack
+	fi
+	echo 0
 }
 
 force_reset() {
-  if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
-    # In graceful host reset, after trigger os shutdown,
-    # the phosphor-state-manager will call force-warm-reset
-    # in this case the force_reset should wait for shutdown_ack from host
-    cnt=30
-    while [ $cnt -gt 0 ];
-    do
-      if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
-        break
-      fi
-      echo "Waiting for shutdown-ack count down $cnt"
-      sleep 1
-      cnt=$((cnt - 1))
-    done
-    # The host OS is failed to shutdown
-    if [ $cnt == 0 ]; then
-      echo "Shutdown-ack time out after 30s."
-      exit 0
-    fi
-  fi
-  echo "Triggering sysreset pin"
-  gpioset -l $GPIO_CHIP0_IDX $S0_SYSRESET_L=1
-  sleep 1
-  gpioset -l $GPIO_CHIP0_IDX $S0_SYSRESET_L=0
+	if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
+		# In graceful host reset, after trigger os shutdown,
+		# the phosphor-state-manager will call force-warm-reset
+		# in this case the force_reset should wait for shutdown_ack from host
+		cnt=30
+		while [ $cnt -gt 0 ];
+		do
+			if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
+				break
+			fi
+			echo "Waiting for shutdown-ack count down $cnt"
+			sleep 1
+			cnt=$((cnt - 1))
+		done
+		# The host OS is failed to shutdown
+		if [ $cnt == 0 ]; then
+			echo "Shutdown-ack time out after 30s."
+			exit 0
+		fi
+	fi
+	echo "Triggering sysreset pin"
+	gpioset -l 0 "$S0_SYSRESET_L"=1
+	sleep 1
+	gpioset -l 0 "$S0_SYSRESET_L"=0
 }
 
 if [ $# -lt 2 ]; then
-  echo "Total number of parameter=$#"
-  echo "Insufficient parameter"
-  usage;
-  exit 0;
+	echo "Total number of parameter=$#"
+	echo "Insufficient parameter"
+	usage;
+	exit 0;
 fi
 
-if [ $1 != "mb" ]; then
-  echo "Invalid parameter1=$1"
-  usage;
-  exit 0;
+if [ "$1" != "mb" ]; then
+	echo "Invalid parameter1=$1"
+	usage;
+	exit 0;
 fi
 
-# check if power guard enabled
-dir="/run/systemd/system/"
-file="reboot-guard.conf"
-units=("reboot" "poweroff" "halt")
-for unit in "${units[@]}"; do
-  if [ -f ${dir}${unit}.target.d/${file} ]; then
-    echo "PowerGuard enabled, cannot do power control, exit!!!"
-    exit -1
-  fi
-done
+mkdir -p /run/openbmc/
 
-if [ ! -d "/run/openbmc/" ]; then
-  mkdir -p "/run/openbmc/"
-fi
-
-if [ $2 == "shutdown_ack" ]; then
-  shutdown_ack
-elif [ $2 == "status" ]; then
-  power_status
-elif [ $2 == "force_reset" ]; then
-  force_reset
-elif [ $2 == "soft_off" ]; then
-  ret=$(soft_off)
-  if [ $ret == 0 ]; then
-    echo "The host is already softoff"
-  else
-    echo "Failed to softoff the host"
-  fi
-  exit $ret;
+if [ "$2" == "shutdown_ack" ]; then
+	shutdown_ack
+elif [ "$2" == "status" ]; then
+	power_status
+elif [ "$2" == "force_reset" ]; then
+	force_reset
+elif [ "$2" == "soft_off" ]; then
+	ret=$(soft_off)
+	if [ "$ret" == 0 ]; then
+		echo "The host is already softoff"
+	else
+		echo "Failed to softoff the host"
+	fi
+	exit "$ret";
 else
-  echo "Invalid parameter2=$2"
-  usage;
+	echo "Invalid parameter2=$2"
+	usage;
 fi
 
 exit 0;
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh
index 7c887d4..fc0edd6 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh
@@ -1,3 +1,6 @@
+#!/bin/sh
+
+# shellcheck disable=SC2034
 # Index of GPIO device in gpioget/gpioset
 GPIO_CHIP0_IDX=0
 GPIO_CHIP1_IDX=1
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh
index 8d1aa61..c8721fe 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh
@@ -1,31 +1,33 @@
 #!/bin/bash
+
+# shellcheck source=/dev/null
 source /usr/sbin/gpio-defs.sh
 
 function gpio_number() {
-	GPIO_BASE=$(cat /sys/class/gpio/gpiochip$GPIO_CHIP0_BASE/base)
-	echo $((${GPIO_BASE} + $1))
+	GPIO_BASE=$(cat /sys/class/gpio/gpiochip"$GPIO_CHIP0_BASE"/base)
+	echo $((GPIO_BASE + $1))
 }
 
 # Configure GPIO as output and set its value
 function gpio_configure_output() {
-	gpioId=$(gpio_number $1)
-	echo $gpioId > /sys/class/gpio/export
-	echo out > /sys/class/gpio/gpio${gpioId}/direction
-	echo $2 > /sys/class/gpio/gpio${gpioId}/value
-	echo $gpioId > /sys/class/gpio/unexport
+	gpioId=$(gpio_number "$1")
+	echo "$gpioId" > /sys/class/gpio/export
+	echo out > /sys/class/gpio/gpio"${gpioId}"/direction
+	echo "$2" > /sys/class/gpio/gpio"${gpioId}"/value
+	echo "$gpioId" > /sys/class/gpio/unexport
 }
 
 function gpio_get_val() {
-	gpioId=$(gpio_number $1)
-	echo $gpioId > /sys/class/gpio/export
-	echo $(cat /sys/class/gpio/gpio$gpioId/value)
-	echo $gpioId > /sys/class/gpio/unexport
+	gpioId=$(gpio_number "$1")
+	echo "$gpioId" > /sys/class/gpio/export
+	cat /sys/class/gpio/gpio"$gpioId"/value
+	echo "$gpioId" > /sys/class/gpio/unexport
 }
 
 # Configure GPIO as input
 function gpio_configure_input() {
-	gpioId=$(gpio_number $1)
-	echo $gpioId > /sys/class/gpio/export
-	echo "in" > /sys/class/gpio/gpio${gpioId}/direction
-	echo $gpioId > /sys/class/gpio/unexport
+	gpioId=$(gpio_number "$1")
+	echo "$gpioId" > /sys/class/gpio/export
+	echo "in" > /sys/class/gpio/gpio"${gpioId}"/direction
+	echo "$gpioId" > /sys/class/gpio/unexport
 }
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