Add input validation to diskpart

This commit is contained in:
Austin Horstman 2022-01-14 19:17:48 -06:00
parent 472ac4e772
commit e4378cd040
1 changed files with 20 additions and 8 deletions

View File

@ -125,8 +125,6 @@ esac
# selection for disk type # selection for disk type
diskpart () { diskpart () {
# show disks present on system
lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print NR,"/dev/"$2" - "$3}' # show disks with /dev/ prefix and size
echo -ne " echo -ne "
------------------------------------------------------------------------ ------------------------------------------------------------------------
THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK
@ -134,10 +132,24 @@ echo -ne "
after formating your disk there is no way to get data back after formating your disk there is no way to get data back
------------------------------------------------------------------------ ------------------------------------------------------------------------
Please enter full path to disk: (example /dev/sda):
" "
read option
echo "DISK=$option" >> setup.conf PS3='
Select the disk to install on: '
options=($(lsblk -n --output TYPE,KNAME,SIZE | awk '$1=="disk"{print "/dev/"$2"|"$3}'))
select opt in "${options[@]}"
do
# Positive check
if echo -e '%s\n' "${options[@]}" | grep -Fqw ${opt} 2> /dev/null; then
echo -e "\n${opt%|*} selected \n"
echo "DISK=${opt%|*}" >> setup.conf
break
else
echo -e "\nInvalid selection, please try again. \n"
fi
done
drivessd drivessd
set_option DISK $option set_option DISK $option