[Updated] idd.sh: Added checks for file and block devices

This commit is contained in:
mollusk 2016-07-07 18:08:42 -07:00
parent fb08632381
commit 0cff8f4962

21
idd.sh
View File

@ -30,6 +30,20 @@ Options(){
printf "${BWHITE}[Q]${NC} - Quit\n" 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(){ Quit(){
if [ "${1}" = "q" ];then if [ "${1}" = "q" ];then
echo echo
@ -63,6 +77,7 @@ case "$1" in
printf "${YELLOW}Copy & paste full file path here: ${NC}" printf "${YELLOW}Copy & paste full file path here: ${NC}"
read filepath read filepath
CheckFile ${filepath}
Quit ${filepath} Quit ${filepath}
clear clear
Options Options
@ -74,6 +89,8 @@ case "$1" in
echo echo
printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): " printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): "
read devname read devname
DEVPATH="${DEVICEDIR}/${devname}"
CheckDev ${DEVPATH}
Quit ${devname} Quit ${devname}
echo echo
@ -109,6 +126,7 @@ case "$1" in
printf "${YELLOW}Copy & paste full file path here: ${NC}" printf "${YELLOW}Copy & paste full file path here: ${NC}"
read filepath read filepath
CheckFile ${filepath}
Quit ${filepath} Quit ${filepath}
@ -122,6 +140,9 @@ case "$1" in
echo echo
printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): " printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): "
read devname read devname
DEVPATH="${DEVICEDIR}/${devname}"
CheckDev ${DEVPATH}
Quit ${devname} Quit ${devname}
echo echo