[2/2] fff-sysupgrade: fixes shellcheck errors and warnings

Submitted by Tim Niemeyer on July 2, 2017, 8:41 a.m.

Details

Message ID 1498984901-3769-2-git-send-email-tim@tn-x.org
State Accepted
Headers show

Commit Message

Tim Niemeyer July 2, 2017, 8:41 a.m.
Signed-off-by: Tim Niemeyer <tim@tn-x.org>
---
Die Ă„nderungen sind noch nicht auf einem Knoten getestet worden.

 .../fff/fff-sysupgrade/files/etc/sysupgrade.sh     | 54 +++++++++++++++-------
 1 file changed, 37 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
index 1680378..df9d519 100755
--- a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
+++ b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
@@ -14,7 +14,8 @@  case $BOARD in
     * )
         SOC="ar71xx" ;;
 esac
-echo -ne "\nHardware: $BOARD\n"
+echo ""
+echo "Hardware: $BOARD"
 
 #rewrite BOARD
 case $BOARD in
@@ -36,22 +37,24 @@  esac
 
 wget "${UPGRADE_PATH}/release.nfo"
 if [ ! -f release.nfo ]; then
-  echo -ne "Latest release information not found. Please try to update manually.\n\n"
+  echo "Latest release information not found. Please try to update manually."
+  echo ""
   exit 1
 fi
-VERSION=$(cat release.nfo|awk -F: '/VERSION:/ { print $2 }')
+VERSION=$(awk -F: '/VERSION:/ { print $2 }' release.nfo)
 rm -f release.nfo
-echo -ne "Firmware found on server: $VERSION\n"
+echo "Firmware found on server: $VERSION"
 
-if [ $VERSION -eq $FIRMWARE_VERSION ]; then
-  echo -ne "The installed firmware version is already the current version.\n\n"
+if [ "$VERSION" -eq "$FIRMWARE_VERSION" ]; then
+  echo "The installed firmware version is already the current version."
+  echo ""
 
   if [ "$1" = "--script" ]; then
     exit 1
   fi
 
   while true; do
-    echo -ne "Do you want to reinstall the current version? [y/N]\n"
+    echo "Do you want to reinstall the current version? [y/N]"
     read DO_UPDATE
     case $DO_UPDATE in
       [yY]*|[Jj]*)
@@ -67,33 +70,50 @@  if [ $VERSION -eq $FIRMWARE_VERSION ]; then
   done
 fi
 
-if [ "$FIRMWARE_COMMUNITY" == "franken" ]; then
+if [ "$FIRMWARE_COMMUNITY" = "franken" ]; then
     FIRMWARE_COMMUNITY="fff"
 fi
 
 FILE="${FIRMWARE_COMMUNITY}-${VERSION}-${SOC}-g-${BOARD}-squashfs-sysupgrade.bin"
-echo -ne "Downloading $FILE\n\n"
+echo "Downloading $FILE"
+echo ""
 wget "${UPGRADE_PATH}/${FILE}"
 wget "${UPGRADE_PATH}/${FILE}.sha256"
 
-echo -ne "\ndone. Comparing sha256 sums: "
-sha256sum -c ${FILE}.sha256
+sum=$(sha256sum -c "${FILE}.sha256")
 ret=$?
+echo ""
+echo "done. Comparing sha256 sums: $sum"
 echo
 if [ $ret -ne 0 ]; then
-  echo -ne "sha256 sums do not match. Try restarting this script to redownload the firmware.\n\n"
-  rm -f ${FILE}*
+  echo "sha256 sums do not match. Try restarting this script to redownload the firmware."
+  echo ""
+  rm -f "${FILE}" "${FILE}.sha256"
   exit 1
 else
   if [ "$1" = "--script" ]; then
-    echo -ne "\nStarting firmware upgrade. Don't touch me until I reboot.\n\n\n"
-    sysupgrade ${FILE}
+    echo ""
+    echo "Starting firmware upgrade. Don't touch me until I reboot."
+    echo ""
+    echo ""
+    sysupgrade "${FILE}"
   fi
   while true; do
     read -p "sha256 sums correct. Should I start upgrading the firmware (y/N)? " yn
     case $yn in
-        [Yy]*|[Jj]*) echo -ne "\nStarting firmware upgrade. Don't touch me until I reboot.\n\n\n"; sysupgrade ${FILE}; break;;
-        *) echo -ne "\nAborting firmware upgrade.\n\n"; rm -f ${FILE}*; exit 0;;
+        [Yy]*|[Jj]*)
+            echo ""
+            echo "Starting firmware upgrade. Don't touch me until I reboot."
+            echo ""
+            echo ""
+            sysupgrade "${FILE}"
+            break;;
+        *)
+            echo ""
+            echo "Aborting firmware upgrade."
+            echo ""
+            rm -f "${FILE}" "${FILE}.sha256"
+            exit 0;;
     esac
   done
 fi

Comments

Adrian Schmutzler July 22, 2017, 10:37 p.m.
Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Tim Niemeyer
> Sent: Sonntag, 2. Juli 2017 10:42
> To: franken-dev@freifunk.net
> Subject: [PATCH 2/2] fff-sysupgrade: fixes shellcheck errors and warnings
> 
> Signed-off-by: Tim Niemeyer <tim@tn-x.org>
> ---
> Die Ă„nderungen sind noch nicht auf einem Knoten getestet worden.
> 
>  .../fff/fff-sysupgrade/files/etc/sysupgrade.sh     | 54
+++++++++++++++-----
> --
>  1 file changed, 37 insertions(+), 17 deletions(-)
> 
> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
> b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
> index 1680378..df9d519 100755
> --- a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
> +++ b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.sh
> @@ -14,7 +14,8 @@ case $BOARD in
>      * )
>          SOC="ar71xx" ;;
>  esac
> -echo -ne "\nHardware: $BOARD\n"
> +echo ""
> +echo "Hardware: $BOARD"
> 
>  #rewrite BOARD
>  case $BOARD in
> @@ -36,22 +37,24 @@ esac
> 
>  wget "${UPGRADE_PATH}/release.nfo"
>  if [ ! -f release.nfo ]; then
> -  echo -ne "Latest release information not found. Please try to update
> manually.\n\n"
> +  echo "Latest release information not found. Please try to update
> manually."
> +  echo ""
>    exit 1
>  fi
> -VERSION=$(cat release.nfo|awk -F: '/VERSION:/ { print $2 }')
> +VERSION=$(awk -F: '/VERSION:/ { print $2 }' release.nfo)
>  rm -f release.nfo
> -echo -ne "Firmware found on server: $VERSION\n"
> +echo "Firmware found on server: $VERSION"
> 
> -if [ $VERSION -eq $FIRMWARE_VERSION ]; then
> -  echo -ne "The installed firmware version is already the current
> version.\n\n"
> +if [ "$VERSION" -eq "$FIRMWARE_VERSION" ]; then
> +  echo "The installed firmware version is already the current version."
> +  echo ""
> 
>    if [ "$1" = "--script" ]; then
>      exit 1
>    fi
> 
>    while true; do
> -    echo -ne "Do you want to reinstall the current version? [y/N]\n"
> +    echo "Do you want to reinstall the current version? [y/N]"
>      read DO_UPDATE
>      case $DO_UPDATE in
>        [yY]*|[Jj]*)
> @@ -67,33 +70,50 @@ if [ $VERSION -eq $FIRMWARE_VERSION ]; then
>    done
>  fi
> 
> -if [ "$FIRMWARE_COMMUNITY" == "franken" ]; then
> +if [ "$FIRMWARE_COMMUNITY" = "franken" ]; then
>      FIRMWARE_COMMUNITY="fff"
>  fi
> 
>  FILE="${FIRMWARE_COMMUNITY}-${VERSION}-${SOC}-g-${BOARD}-
> squashfs-sysupgrade.bin"
> -echo -ne "Downloading $FILE\n\n"
> +echo "Downloading $FILE"
> +echo ""
>  wget "${UPGRADE_PATH}/${FILE}"
>  wget "${UPGRADE_PATH}/${FILE}.sha256"
> 
> -echo -ne "\ndone. Comparing sha256 sums: "
> -sha256sum -c ${FILE}.sha256
> +sum=$(sha256sum -c "${FILE}.sha256")
>  ret=$?
> +echo ""
> +echo "done. Comparing sha256 sums: $sum"
>  echo
>  if [ $ret -ne 0 ]; then
> -  echo -ne "sha256 sums do not match. Try restarting this script to
> redownload the firmware.\n\n"
> -  rm -f ${FILE}*
> +  echo "sha256 sums do not match. Try restarting this script to
redownload
> the firmware."
> +  echo ""
> +  rm -f "${FILE}" "${FILE}.sha256"
>    exit 1
>  else
>    if [ "$1" = "--script" ]; then
> -    echo -ne "\nStarting firmware upgrade. Don't touch me until I
> reboot.\n\n\n"
> -    sysupgrade ${FILE}
> +    echo ""
> +    echo "Starting firmware upgrade. Don't touch me until I reboot."
> +    echo ""
> +    echo ""
> +    sysupgrade "${FILE}"
>    fi
>    while true; do
>      read -p "sha256 sums correct. Should I start upgrading the firmware
(y/N)?
> " yn
>      case $yn in
> -        [Yy]*|[Jj]*) echo -ne "\nStarting firmware upgrade. Don't touch
me
> until I reboot.\n\n\n"; sysupgrade ${FILE}; break;;
> -        *) echo -ne "\nAborting firmware upgrade.\n\n"; rm -f ${FILE}*;
exit 0;;
> +        [Yy]*|[Jj]*)
> +            echo ""
> +            echo "Starting firmware upgrade. Don't touch me until I
reboot."
> +            echo ""
> +            echo ""
> +            sysupgrade "${FILE}"
> +            break;;
> +        *)
> +            echo ""
> +            echo "Aborting firmware upgrade."
> +            echo ""
> +            rm -f "${FILE}" "${FILE}.sha256"
> +            exit 0;;
>      esac
>    done
>  fi
> --
> 2.1.4
> 
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net