summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2020-10-26 20:06:25 -0400
committerGordon GECOS <u@adam>2020-10-27 19:17:41 -0400
commit47c9811c7af21714898d9916922353745b90f585 (patch)
tree318d1bb33d96b7d4d7e93eec3eb3b67edf599381 /src
parent009e95ed6d8757b0f55f9b65c8ae92d678aee53f (diff)
usb.sh
Diffstat (limited to 'src')
-rwxr-xr-xsrc/usb.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/usb.sh b/src/usb.sh
new file mode 100755
index 0000000..cd80d8f
--- /dev/null
+++ b/src/usb.sh
@@ -0,0 +1,53 @@
1#!/bin/bash
2
3die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }
4
5whole_device()
6{
7 case "$1" in
8 *-part?) false ;;
9 *-part??) false ;;
10 *-part???) false ;;
11 */usb\*) false ;;
12 *) true ;;
13 esac
14}
15
16confirm_usb()
17{
18 local msg="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? "
19 printf "$msg" "$1" >&2
20 read line
21 case "$line" in
22 [yY][eE][sS]) return ;;
23 *) die "Aborted by user." ;;
24 esac
25}
26
27choose_usb()
28{
29 local devs maj
30 set -- /dev/disk/by-id/usb*
31 for dev; do
32 shift
33 whole_device "$dev" || continue
34 set -- "$@" "$dev"
35 done
36 if [ $# = 0 ]; then
37 die "no usb device found"
38 elif [ $# = 1 ]; then
39 confirm_usb "$1" || die impossible
40 USB="$1"
41 else
42 die "multiple USB devices connected and choice between them is unimplemented. ($*)"
43 fi
44}
45
46choose_cdrom()
47{
48 die 'choose_cdrom: unimplemented; specify cdrom device with --out'
49}
50
51choose_usb
52echo USB=$USB
53