From 522522bf90533d28d979afe3c0cbe5b1c2e3ddf0 Mon Sep 17 00:00:00 2001 From: mollusk Date: Thu, 7 Jul 2016 18:45:08 -0700 Subject: [PATCH] [Updated] idd.sh: Added confirmation prompt before writing to device --- idd.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/idd.sh b/idd.sh index 384a32c..ca154ed 100755 --- a/idd.sh +++ b/idd.sh @@ -44,6 +44,24 @@ CheckDev(){ fi } +ConfirmWrite(){ + echo + printf "${YELLOW}Are you sure you want to write changes to${NC} ${LRED}${2}${NC}${YELLOW}?${NC}\n" + printf "${YELLOW}This will overwrite existing data${NC}\n" + printf "${YELLOW}[y/n]: ${NC}" + read choice + + if [ "${choice}" = "n" ];then + echo + printf "${LRED}Aborted!${NC}\n" + exit 0; + else + echo + printf "${YELLOW}Writing data:${NC}\n" + printf "${LGREEN}${1}${NC} --> ${LPURPLE}${2}${NC}\n" + echo + fi +} Quit(){ if [ "${1}" = "q" ];then echo @@ -92,11 +110,10 @@ case "$1" in Quit ${devname} DEVPATH="${DEVICEDIR}/${devname}" CheckDev ${DEVPATH} + ConfirmWrite ${filepath} ${DEVPATH} echo - - printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n" printf "${LCYAN}Please wait ...${NC}\n" echo pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync @@ -144,10 +161,9 @@ case "$1" in Quit ${devname} DEVPATH="${DEVICEDIR}/${devname}" CheckDev ${DEVPATH} - - echo + ConfirmWrite ${filepath} ${DEVPATH} - printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n" + echo printf "${LCYAN}Please wait ...${NC}\n" echo pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync