From fd0d2b95d49ce41a1df69b4f14de0d5e97d29146 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 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/tizen/sd_fusing_rpi3.sh b/scripts/tizen/sd_fusing_rpi3.sh index de4c98e99e..406bae6b54 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 -- 2.34.1