From 7470ff4fc2279b53a542a5b87ad6df26635427ad Mon Sep 17 00:00:00 2001
From: John Klug <john.klug@multitech.com>
Date: Mon, 7 May 2018 10:39:15 -0500
Subject: Upgrade Fix model file check and symlink issue for external device

---
 recipes-core/initscripts/initscripts-1.0/umountfs | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/recipes-core/initscripts/initscripts-1.0/umountfs b/recipes-core/initscripts/initscripts-1.0/umountfs
index 5229646..9c36bd3 100644
--- a/recipes-core/initscripts/initscripts-1.0/umountfs
+++ b/recipes-core/initscripts/initscripts-1.0/umountfs
@@ -83,7 +83,8 @@ flash_upgrade() {
     return
   fi
   # flash_root must be a mountpoint that is not the rootfs and be mounted rw
-  local flash_root=${1}
+  # External mount may be on symlink.
+  local flash_root=$(readlink -f ${1})
 
   local flash_dir=${flash_root}/flash-upgrade
   local upgrade_file=${flash_dir}/upgrade.bin
@@ -182,12 +183,15 @@ flash_upgrade() {
     shopt -s nocasematch
     local hw_version=$(cat /sys/devices/platform/mts-io/hw-version)
     local firmware_model=$(tar -xO -f ${upgrade_file} model)
-    if [[ ! "${hw_version}" =~ ^${firmware_model}- ]]; then
+    # Do case insensity character match.
+    shopt -s nocasematch
+    if [[ ! "${hw_version}" =~ ^(${firmware_model})- ]]; then
       echo "Wrong firmware for this hardware"
       echo "hw version: ${hw_version}"
       echo "firmware model: ${firmware_model}"
       return
     fi
+    shopt -u nocasematch
 
     echo "Checking MD5s"
     ((upgrade_script=0))
@@ -207,11 +211,6 @@ flash_upgrade() {
           ((upgrade_script=1))
         fi
       fi
-      # Extract files early if we are going to
-      # execute the upgrade script.
-      if [[ ${file} == ${install_file} ]] ; then
-        ((upgrade_script=1))
-      fi
     done
   fi
 
@@ -331,6 +330,14 @@ if [[ -f ${upgrade_fname} ]] ; then
     if ((${#owner} > 0)) && ((owner == 0)) ; then
       flash_upgrade /var/volatile
       flash_upgrade /media/card
+      # Look for upgrade on external media besides
+      # SD card.
+      cd /run/media
+      # See if there is a USB driver
+      last=$(dirname $(ls -d */flash-upgrade))
+      if ((${#last} > 0)) ; then
+        flash_upgrade "/run/media/${last}"
+      fi
     fi
 fi
 
-- 
cgit v1.2.3