From 49b4b007bd59a6aecd04626ac61c25c9cd9edd10 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 3 Apr 2020 16:58:36 +0900 Subject: [PATCH] scripts: tizen: sd_fusing: Check requested device 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 --- scripts/tizen/sd_fusing_rpi3.sh | 26 +++++++++++++++++++++++++- scripts/tizen/sd_fusing_xu4.sh | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/scripts/tizen/sd_fusing_rpi3.sh b/scripts/tizen/sd_fusing_rpi3.sh index de4c98e..406bae6 100755 --- a/scripts/tizen/sd_fusing_rpi3.sh +++ b/scripts/tizen/sd_fusing_rpi3.sh @@ -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/]" + 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 diff --git a/scripts/tizen/sd_fusing_xu4.sh b/scripts/tizen/sd_fusing_xu4.sh index 6c804a9..a3fbe69 100755 --- a/scripts/tizen/sd_fusing_xu4.sh +++ b/scripts/tizen/sd_fusing_xu4.sh @@ -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/]" + 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 -- 2.7.4