flasher: tune error handling and display
authorGrazvydas Ignotas <notasas@gmail.com>
Wed, 9 Feb 2011 14:07:35 +0000 (16:07 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 9 Feb 2011 14:07:35 +0000 (16:07 +0200)
flasher/rootfs/etc/init.d/rc
flasher/rootfs/etc/updater.sh
flasher/rootfs/etc/updater_funcs.sh

index efeddcf..e259af8 100755 (executable)
@@ -19,9 +19,9 @@ then
        log "Update FINISHED"
        log "---------------------------------------------"
 else
-       log "---------------------------------------------"
-       log "Update FAILED"
-       log "---------------------------------------------"
+       log_err "---------------------------------------------"
+       log_err "Update FAILED"
+       log_err "---------------------------------------------"
        mkdir -p /mnt/log 2> /dev/null
        if mount /dev/mmcblk0p1 /mnt/log
        then
index cc4ad6f..6c89886 100755 (executable)
@@ -12,6 +12,19 @@ status_uboot_env="already empty"
 status_uimage="missing"
 status_rootfs="missing"
 
+cleanup()
+{
+       cd /tmp
+       if [ -n "$finalize_mpoint" ]
+       then
+               umount $finalize_mpoint 2> /dev/null || true
+       fi
+       if [ -n "$rootfs_mpoint" ]
+       then
+               umount $rootfs_mpoint 2> /dev/null || true
+       fi
+}
+
 mkdir /mnt/ubifs 2> /dev/null || true
 
 if [ ! -e /dev/mmcblk0p1 ]
@@ -37,6 +50,21 @@ do
                continue;
        fi
 
+       if [ -x $mpoint/initialize.sh ]
+       then
+               log ""
+               log "running init script.."
+               cd $mpoint
+               if ! ./initialize.sh
+               then
+                       log "initialize.sh failed."
+                       cleanup
+                       false
+               fi
+               log "done."
+               cd /tmp
+       fi
+
        for bf in $bootfiles
        do
                if [ -e $mpoint/$bf ]
@@ -127,6 +155,7 @@ then
                log $real_md5
        else
                log "INCORRECT"
+               cleanup
                false
        fi
 
@@ -160,16 +189,12 @@ then
        if ! ./finalize.sh
        then
                log "finalize.sh failed."
+               cleanup
                false
        fi
        log "done."
-       cd /tmp
-       umount $finalize_mpoint
 fi
 
-if [ -n "$rootfs_mpoint" ]
-then
-       umount $rootfs_mpoint 2> /dev/null || true
-fi
+cleanup
 
 exit 0
index a13fe4b..ab2c3a3 100644 (file)
@@ -7,3 +7,14 @@ log()
        echo "$@" > $LOG_DEVICE
 }
 
+log_err()
+{
+       echo -en "\033[1;31m"
+       echo "$@"
+       echo -en "\033[0m"
+
+       echo -en "\033[1;31m" > $LOG_DEVICE
+       echo "$@" > $LOG_DEVICE
+       echo -en "\033[0m" > $LOG_DEVICE
+}
+