summaryrefslogtreecommitdiff
path: root/scripts/disk-util
blob: a4bdaa02390c2f201f6d87f468b1d19cbc6a2708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

# List block devices that are not removable,
# if multiple devices are found, the user will be invited to choose one.
# If no devices are found, the program exit with error code 1

outfile=${1:-/dev/stdout}
utilspath=/usr/lib/system-installer

. $utilspath/dialog-helper

target_array=()
for i in /sys/block/*/device; do
	[ -d "$i/slaves" ] && continue
	dev=$(echo $i | cut -d'/' -f-4)
	outdev=$(echo $i | cut -d'/' -f4)
	grep -q 1 "$dev/removable"
	if [ "$?" = "1" ]; then
		 target_array+=("/dev/$outdev")
	fi
done

if (( "${#target_array[@]}" == "1" )); then
	TARGET="${target_array[0]}"
elif (( "${#target_array[@]}" > "1" )); then
	install_dest="Installation destination device :"
	dialog_helper --no-items --menu "${install_dest}" 10 40 3 $( for i in "${target_array[@]}"; do echo "$i"; done )
	TARGET="$DIALOGRES" 
else
	$DIALOG --msgbox "No devices could be found, no installation possible" 24 70
	exit 1
fi

cat << EOC > $outfile
$TARGET
EOC

exit 0