[Updated] idd.sh: Added confirmation prompt before writing to device

This commit is contained in:
mollusk 2016-07-07 18:45:08 -07:00
parent 1df031fe3f
commit 522522bf90

26
idd.sh
View File

@ -44,6 +44,24 @@ CheckDev(){
fi 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(){ Quit(){
if [ "${1}" = "q" ];then if [ "${1}" = "q" ];then
echo echo
@ -92,11 +110,10 @@ case "$1" in
Quit ${devname} Quit ${devname}
DEVPATH="${DEVICEDIR}/${devname}" DEVPATH="${DEVICEDIR}/${devname}"
CheckDev ${DEVPATH} CheckDev ${DEVPATH}
ConfirmWrite ${filepath} ${DEVPATH}
echo echo
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
printf "${LCYAN}Please wait ...${NC}\n" printf "${LCYAN}Please wait ...${NC}\n"
echo echo
pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync
@ -144,10 +161,9 @@ case "$1" in
Quit ${devname} Quit ${devname}
DEVPATH="${DEVICEDIR}/${devname}" DEVPATH="${DEVICEDIR}/${devname}"
CheckDev ${DEVPATH} CheckDev ${DEVPATH}
ConfirmWrite ${filepath} ${DEVPATH}
echo
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n" echo
printf "${LCYAN}Please wait ...${NC}\n" printf "${LCYAN}Please wait ...${NC}\n"
echo echo
pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync