From 353412f8c908138f81ec64a191a965845cbd8f01 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 30 Oct 2020 17:20:09 -0400 Subject: ui improvement --- Makefile | 4 +++- src/parted-usb.sh | 3 ++- src/usb.sh | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 633dc1e..453b315 100644 --- a/Makefile +++ b/Makefile @@ -167,9 +167,11 @@ FORCE: $(btrfs_images): FORCE $(MAKE) -C rootfs $(notdir $@) -.PHONY: usb +.PHONY: usb key usb: rootfs sudo ROOTFS=rootfs/$(rootfs) ./src/parted-usb.sh USB +key: + sudo ROOTFS= ./src/parted-usb.sh USB boot: rootfs sudo ./src/mkinitramfs-samizdat diff --git a/src/parted-usb.sh b/src/parted-usb.sh index 1c0219d..1a7ec7a 100755 --- a/src/parted-usb.sh +++ b/src/parted-usb.sh @@ -316,7 +316,8 @@ if [ "$1" ] then if [ "$1" = USB ] then - target=$(./src/usb.sh) || exit 1 + [ "$DO_BUILD" ] && arg= || arg=-n + target=$(./src/usb.sh $arg) || exit 1 elif [ -f "$1" ] then case "$1" in diff --git a/src/usb.sh b/src/usb.sh index 991f553..a8fd5fb 100755 --- a/src/usb.sh +++ b/src/usb.sh @@ -17,20 +17,34 @@ whole_device() esac } -confirm_usb() +confirm_usb_strict() { - local msg="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? " - PRINTF "$msg" "$1" + CONFIRM_MSG="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? " + CONFIRM_WITH_ONE_LETTER= + confirm_helper "$@" +} + +confirm_usb_lax() +{ + CONFIRM_MSG="The device used will be:\n\n\t%s\n\nType 'y' to confirm.\nContinue? " + CONFIRM_WITH_ONE_LETTER=y + confirm_helper "$@" +} + +confirm_helper() +{ + PRINTF "$CONFIRM_MSG" "$1" read line case "$line" in [yY][eE][sS]) return ;; - *) die "Aborted by user." ;; + [yY]) [ "$CONFIRM_WITH_ONE_LETTER" ] && return || : ;; esac + die "Aborted by user." } choose_usb() { - local devs maj + local devs maj USB set -- /dev/disk/by-id/usb* for dev; do shift @@ -40,7 +54,8 @@ choose_usb() if [ $# = 0 ]; then die "no usb device found" elif [ $# = 1 ]; then - confirm_usb "$1" || die impossible + [ "$NO_ACT" ] && confirm=confirm_usb_lax || confirm=confirm_usb_strict + $confirm "$1" || exit USB=$1 else ECHO @@ -60,14 +75,16 @@ choose_usb() ;; *) die "Invalid argument: $line" ;; esac + confirm_usb_lax fi + [ "$USB" ] && readlink -f "$USB" } -choose_cdrom() -{ - die 'choose_cdrom: unimplemented; specify cdrom device with --out' -} +NO_ACT= +case "$1" in + -n) NO_ACT=y;; + -*) exit 1;; +esac choose_usb -[ "$USB" ] && readlink -f "$USB" -- cgit v1.2.3