diff options
Diffstat (limited to 'src/usb.sh')
-rwxr-xr-x | src/usb.sh | 39 |
1 files changed, 28 insertions, 11 deletions
@@ -17,20 +17,34 @@ whole_device() | |||
17 | esac | 17 | esac |
18 | } | 18 | } |
19 | 19 | ||
20 | confirm_usb() | 20 | confirm_usb_strict() |
21 | { | 21 | { |
22 | local msg="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? " | 22 | CONFIRM_MSG="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? " |
23 | PRINTF "$msg" "$1" | 23 | CONFIRM_WITH_ONE_LETTER= |
24 | confirm_helper "$@" | ||
25 | } | ||
26 | |||
27 | confirm_usb_lax() | ||
28 | { | ||
29 | CONFIRM_MSG="The device used will be:\n\n\t%s\n\nType 'y' to confirm.\nContinue? " | ||
30 | CONFIRM_WITH_ONE_LETTER=y | ||
31 | confirm_helper "$@" | ||
32 | } | ||
33 | |||
34 | confirm_helper() | ||
35 | { | ||
36 | PRINTF "$CONFIRM_MSG" "$1" | ||
24 | read line | 37 | read line |
25 | case "$line" in | 38 | case "$line" in |
26 | [yY][eE][sS]) return ;; | 39 | [yY][eE][sS]) return ;; |
27 | *) die "Aborted by user." ;; | 40 | [yY]) [ "$CONFIRM_WITH_ONE_LETTER" ] && return || : ;; |
28 | esac | 41 | esac |
42 | die "Aborted by user." | ||
29 | } | 43 | } |
30 | 44 | ||
31 | choose_usb() | 45 | choose_usb() |
32 | { | 46 | { |
33 | local devs maj | 47 | local devs maj USB |
34 | set -- /dev/disk/by-id/usb* | 48 | set -- /dev/disk/by-id/usb* |
35 | for dev; do | 49 | for dev; do |
36 | shift | 50 | shift |
@@ -40,7 +54,8 @@ choose_usb() | |||
40 | if [ $# = 0 ]; then | 54 | if [ $# = 0 ]; then |
41 | die "no usb device found" | 55 | die "no usb device found" |
42 | elif [ $# = 1 ]; then | 56 | elif [ $# = 1 ]; then |
43 | confirm_usb "$1" || die impossible | 57 | [ "$NO_ACT" ] && confirm=confirm_usb_lax || confirm=confirm_usb_strict |
58 | $confirm "$1" || exit | ||
44 | USB=$1 | 59 | USB=$1 |
45 | else | 60 | else |
46 | ECHO | 61 | ECHO |
@@ -60,14 +75,16 @@ choose_usb() | |||
60 | ;; | 75 | ;; |
61 | *) die "Invalid argument: $line" ;; | 76 | *) die "Invalid argument: $line" ;; |
62 | esac | 77 | esac |
78 | confirm_usb_lax | ||
63 | fi | 79 | fi |
80 | [ "$USB" ] && readlink -f "$USB" | ||
64 | } | 81 | } |
65 | 82 | ||
66 | choose_cdrom() | 83 | NO_ACT= |
67 | { | 84 | case "$1" in |
68 | die 'choose_cdrom: unimplemented; specify cdrom device with --out' | 85 | -n) NO_ACT=y;; |
69 | } | 86 | -*) exit 1;; |
87 | esac | ||
70 | 88 | ||
71 | choose_usb | 89 | choose_usb |
72 | [ "$USB" ] && readlink -f "$USB" | ||
73 | 90 | ||