Commit 7e495678 authored by Natanael Copa's avatar Natanael Copa

setup-disk: allow entering more than one disk at prompt

So you can specify more than one disk
parent 18fec8f8
...@@ -17,6 +17,17 @@ in_list() { ...@@ -17,6 +17,17 @@ in_list() {
return 1 return 1
} }
all_in_list() {
local needle="$1"
local i
[ -z "$needle" ] && return 1
shift
for i in $needle; do
in_list "$i" $@ || return 1
done
return 0
}
# wrapper to only show given device # wrapper to only show given device
_blkid() { _blkid() {
blkid | grep "^$1:" blkid | grep "^$1:"
...@@ -368,7 +379,7 @@ show_disk_info() { ...@@ -368,7 +379,7 @@ show_disk_info() {
vendor=$(cat /sys/block/$d/device/vendor 2>/dev/null) vendor=$(cat /sys/block/$d/device/vendor 2>/dev/null)
model=$(cat /sys/block/$d/device/model 2>/dev/null) model=$(cat /sys/block/$d/device/model 2>/dev/null)
size=$(awk '{gb = ($1 * 512)/1000000000; printf "%.1f GB\n", gb}' /sys/block/$d/size 2>/dev/null) size=$(awk '{gb = ($1 * 512)/1000000000; printf "%.1f GB\n", gb}' /sys/block/$d/size 2>/dev/null)
echo " $d ($size $vendor $model)" echo " $d ($size $vendor $model)"
done done
} }
...@@ -759,21 +770,25 @@ __EOF__ ...@@ -759,21 +770,25 @@ __EOF__
ask_disk() { ask_disk() {
local prompt="$1" local prompt="$1"
local help_func="$2" local help_func="$2"
local i=
shift 2 shift 2
answer= answer=
while ! in_list "$answer" $@ "none" "abort"; do while ! all_in_list "$answer" $@ "none" "abort"; do
echo "Available disks are: $@" echo "Available disks are:"
show_disk_info "$@"
echon "$prompt [$1] " echon "$prompt [$1] "
default_read answer $1 default_read answer $1
case "$answer" in case "$answer" in
'abort') exit 0;; 'abort') exit 0;;
'none') return 0;; 'none') return 0;;
'?') $help_func;; '?') $help_func;;
*) if ! [ -b "/dev/$answer" ]; then *) for i in $answer; do
echo "/dev/$answer is not a block device" >&2 if ! [ -b "/dev/$i" ]; then
answer= echo "/dev/$i is not a block device" >&2
fi;; answer=
fi
done;;
esac esac
done done
} }
...@@ -867,10 +882,12 @@ if [ $# -gt 0 ]; then ...@@ -867,10 +882,12 @@ if [ $# -gt 0 ]; then
diskdevs="$diskdevs /dev/$j" diskdevs="$diskdevs /dev/$j"
done done
else else
ask_disk "Which disk would you like to use? (or '?' for help or 'none')" \ ask_disk "Which disk(s) would you like to use? (or '?' for help or 'none')" \
diskselect_help $disks diskselect_help $disks
if [ "$answer" != none ]; then if [ "$answer" != none ]; then
diskdevs=/dev/$answer for i in $answer; do
diskdevs="$diskdevs /dev/$i"
done
else else
DISK_MODE="none" DISK_MODE="none"
fi fi
...@@ -880,6 +897,7 @@ if [ -n "$diskdevs" ] && [ -z "$DISK_MODE" ]; then ...@@ -880,6 +897,7 @@ if [ -n "$diskdevs" ] && [ -z "$DISK_MODE" ]; then
answer= answer=
disk_is_or_disks_are="disk is" disk_is_or_disks_are="disk is"
it_them="it" it_them="it"
set -- $diskdevs
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
disk_is_or_disks_are="disks are" disk_is_or_disks_are="disks are"
it_them="them" it_them="them"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment