From 0cff8f49623d624eb07987c545d07b3fbe0bb3fc Mon Sep 17 00:00:00 2001 From: mollusk Date: Thu, 7 Jul 2016 18:08:42 -0700 Subject: [PATCH] [Updated] idd.sh: Added checks for file and block devices --- idd.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/idd.sh b/idd.sh index 44d5aa8..8d2d521 100755 --- a/idd.sh +++ b/idd.sh @@ -30,6 +30,20 @@ Options(){ printf "${BWHITE}[Q]${NC} - Quit\n" } +CheckFile(){ + if [ ! -f "${1}" ];then + printf "${LRED}${1} is not a valid file path${NC}\n" + exit 0; + fi +} + +CheckDev(){ + if [ ! -b "${1}" ];then + printf "${LRED}${1} is not a valid block device${NC}\n" + exit 0; + fi +} + Quit(){ if [ "${1}" = "q" ];then echo @@ -63,6 +77,7 @@ case "$1" in printf "${YELLOW}Copy & paste full file path here: ${NC}" read filepath + CheckFile ${filepath} Quit ${filepath} clear Options @@ -74,6 +89,8 @@ case "$1" in echo printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): " read devname + DEVPATH="${DEVICEDIR}/${devname}" + CheckDev ${DEVPATH} Quit ${devname} echo @@ -109,6 +126,7 @@ case "$1" in printf "${YELLOW}Copy & paste full file path here: ${NC}" read filepath + CheckFile ${filepath} Quit ${filepath} @@ -122,6 +140,9 @@ case "$1" in echo printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): " read devname + + DEVPATH="${DEVICEDIR}/${devname}" + CheckDev ${DEVPATH} Quit ${devname} echo