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"