scripts: tizen: sd_fusing: Check requested device 74/229774/2
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 3 Apr 2020 07:58:36 +0000 (16:58 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 6 Apr 2020 01:21:07 +0000 (10:21 +0900)
It is possible to request flashing a device which is non-existent
or unaccessible. Especially, request can flash non-removable
storage disk that user do not really intend. To skip all the case,
Check requested device.
For non removable disk, it will ask user really intended to flash
the device.

Change-Id: I7ee3363fe4075abd7b860acf26b6cbe65e6fa68c
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
scripts/tizen/sd_fusing_rpi3.sh
scripts/tizen/sd_fusing_xu4.sh

index de4c98e..406bae6 100755 (executable)
@@ -299,9 +299,32 @@ function check_args () {
        fi
 }
 
+function check_device () {
+       if [ ! -b "$DEVICE" ]; then
+               echo "No such device: $DEVICE"
+               exit 0
+       fi
+
+       local REMOVABLE=`lsblk $DEVICE -nd -o RM | grep 1 | wc -l`
+       if [ "$REMOVABLE" == "0" ]; then
+               echo ""
+               echo "$(tput setaf 3)$(tput bold)$DEVICE is not a removable disk, Is it OK? [y/<n>]"
+               tput sgr 0
+               read input
+               if [ "$input" != "y" ] && [ "$input" != "Y" ]; then
+                       exit 0
+               fi
+       fi
+
+       if [ ! -w "$DEVICE" ]; then
+               echo "Write not permitted: $DEVICE"
+               exit 0
+       fi
+}
+
 function print_logo () {
        echo ""
-       echo "Raspberry Pi3 downloader, version 1.1"
+       echo "Raspberry Pi3 downloader, version 1.2"
        echo ""
 }
 
@@ -348,5 +371,6 @@ while test $# -ne 0; do
 done
 
 check_args
+check_device
 check_partition_format
 fuse_image
index 6c804a9..a3fbe69 100755 (executable)
@@ -340,9 +340,32 @@ function check_args () {
        fi
 }
 
+function check_device () {
+       if [ ! -b "$DEVICE" ]; then
+               echo "No such device: $DEVICE"
+               exit 0
+       fi
+
+       local REMOVABLE=`lsblk $DEVICE -nd -o RM | grep 1 | wc -l`
+       if [ "$REMOVABLE" == "0" ]; then
+               echo ""
+               echo "$(tput setaf 3)$(tput bold)$DEVICE is not a removable disk, Is it OK? [y/<n>]"
+               tput sgr 0
+               read input
+               if [ "$input" != "y" ] && [ "$input" != "Y" ]; then
+                       exit 0
+               fi
+       fi
+
+       if [ ! -w "$DEVICE" ]; then
+               echo "Write not permitted: $DEVICE"
+               exit 0
+       fi
+}
+
 function print_logo () {
        echo ""
-       echo "[Odroid-XU3/4 downloader version 1.1]"
+       echo "[Odroid-XU3/4 downloader version 1.2]"
        echo "This version also supports Tizen 4.0."
        echo ""
 }
@@ -389,5 +412,6 @@ while test $# -ne 0; do
 done
 
 check_args
+check_device
 check_partition_format
 fuse_image