From f8e149f5d8d2d8a658c309e5f286e9336b6def1a Mon Sep 17 00:00:00 2001 From: ke hu <ke.hu@iopsys.eu> Date: Mon, 27 May 2019 16:47:53 +0200 Subject: [PATCH] sysupgrade: on usb-upgrade do not modify image refs #17396 When upgrading from usb storage, do not modify the image on the storage device --- base-files/iop-files/lib/upgrade/iopsys.sh | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/base-files/iop-files/lib/upgrade/iopsys.sh b/base-files/iop-files/lib/upgrade/iopsys.sh index be79cfc6..d8fc5580 100644 --- a/base-files/iop-files/lib/upgrade/iopsys.sh +++ b/base-files/iop-files/lib/upgrade/iopsys.sh @@ -296,7 +296,41 @@ check_sig() { return 1 } +#if user upg by command line sysupgrade, so need to check image in usb disk + +image_in_usb() +{ + local from=$1 + local file_name=$(basename $from) + local file_path + file_path="$(mount -t vfat | awk '{print $3}')" + if [ -z "$file_path" ];then + echo 0 + else + find /mnt/ -name "$file_name" | grep -q mnt && echo 1 || echo 0 + fi +} + + +do_usb_image_op(){ + case "$1" in + save) + #check if the file exist in the usb disk + [ "$(image_in_usb $2)" == "1" ] && cp -f $2 $2.bak + ;; + restore) + if [ -f $2.bak ] ;then + mv $2.bak $2 + fi + ;; + clean) + if [ -f $2.bak ] ;then + rm -f $2.bak + fi + ;; + esac +} #-------------------------------------------------------------- # Verify an Iopsys image is good for writing @@ -326,6 +360,8 @@ iopsys_check_image() { ;; esac + do_usb_image_op "save" $from + [ "$(check_crc $from)" == "CRC_OK" ] || { echo "CRC check failed" return 1 @@ -444,7 +480,8 @@ iopsys_upgrade() { fi # Product specific low level write to flash - target_upgrade $from || return + target_upgrade $from || ( do_usb_image_op "clean" $from ; return ) + do_usb_image_op "restore" $from } -- GitLab