From 5e16ae4af26b91460dca95afef4e67034835c672 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Sat, 23 Jan 2021 12:40:16 -0500 Subject: [PATCH] mount-external-storage: move mount-usb to mount-external-storage and change all references in codebase. --- initrd/.ash_history | 2 +- initrd/bin/mount-usb | 132 ----------------------------------- initrd/bin/oem-factory-reset | 8 +-- initrd/etc/gui_functions | 4 +- 4 files changed, 7 insertions(+), 139 deletions(-) delete mode 100755 initrd/bin/mount-usb diff --git a/initrd/.ash_history b/initrd/.ash_history index 996900531..2b07ffa08 100644 --- a/initrd/.ash_history +++ b/initrd/.ash_history @@ -1,7 +1,7 @@ #remove invalid kexec_* signed files mount /dev/sda1 /boot && mount -o remount,rw /boot && rm /boot/kexec* && mount -o remount,ro /boot #Generate keys from GPG smartcard: -mount-usb && gpg --home=/.gnupg/ --card-edit +mount-external-storage && gpg --home=/.gnupg/ --card-edit #Copy generated public key, private_subkey, trustdb and artifacts to external media for backup: mount -o remount,rw /media && mkdir -p /media/gpg_keys; gpg --export-secret-keys --armor email@address.com > /media/gpg_keys/private.key && gpg --export --armor email@address.com > /media/gpg_keys/public.key && gpg --export-ownertrust > /media/gpg_keys/otrust.txt && cp -r ./.gnupg/* /media/gpg_keys/ 2> /dev/null #Insert public key and trustdb export into reproducible rom: diff --git a/initrd/bin/mount-usb b/initrd/bin/mount-usb deleted file mode 100755 index 610d08893..000000000 --- a/initrd/bin/mount-usb +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh -# Mount a external storage device -. /etc/functions - -unlock_remap_luks_dev() -{ - cryptsetup isLuks $EXTERNAL_STORAGE_MOUNT_DEVICE - if [ $(echo $?) == 0 ]; then - echo -e "\n\nExternal Storage drive $EXTERNAL_STORAGE_MOUNT_DEVICE is encrypted.\n" - - cryptsetup luksOpen $EXTERNAL_STORAGE_MOUNT_DEVICE external_storage_dev - - if [ $(echo $?) == 0 ]; then - EXTERNAL_STORAGE_MOUNT_DEVICE="/dev/mapper/external_storage_dev" - else - echo -e "\n\nFailed to unlock External Storage drive $EXTERNAL_STORAGE_MOUNT_DEVICE with provided passphrase.\n" - fi - fi -} - -enable_usb -enable_mmc - -if ! lsmod | grep -q usb_storage; then - count=$(ls /dev/sd* /dev/mmc* 2>/dev/null | wc -l) - timeout=0 - echo "Scanning for external storage devices..." - insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \ - || die "usb_storage: module load failed" - while [[ $count == $(ls /dev/sd* /dev/mmc* 2>/dev/null | wc -l) ]]; do - [[ $timeout -ge 4 ]] && break - sleep 1 - timeout=$(($timeout+1)) - done -fi - -if [ ! -d /media ]; then - mkdir /media -fi - -stat -c %N /sys/block/sd* /sys/block/mmcblk0* 2>/dev/null | grep -e usb -e mmc | cut -f1 -d ' ' | sed "s/[']//g;s|/sys/block|/dev|" > /tmp/external_block_devices -if [ -z `cat /tmp/external_block_devices` ]; then - if [ -x /bin/whiptail ]; then - whiptail --title 'External Storage Drive Missing' \ - --msgbox "Insert your External Storage drive and press Enter to continue." 16 60 - else - echo "+++ External Storage Drive Missing! Insert your External Storage drive and press Enter to continue." - read - fi - sleep 1 - stat -c %N /sys/block/sd* /sys/block/mmcblk0* 2>/dev/null | grep -e usb -e mmc | cut -f1 -d ' ' | sed "s/[']//g;s|/sys/block|/dev|" > /tmp/external_block_devices - if [ -z `cat /tmp/external_block_devices` ]; then - if [ -x /bin/whiptail ]; then - whiptail $BG_COLOR_ERROR --title 'External Storage Drive Missing' \ - --msgbox "Insert your External Storage drive and press Enter to continue." 16 60 - else - echo "!!! ERROR: External Storage Drive Missing! Aborting mount. Press Enter to continue." - fi - exit 1 - fi -fi - -EXTERNAL_STORAGE_MOUNT_DEVICE="" -# Check for the common case: a single External disk with one partition -if [ `cat /tmp/external_block_devices | wc -l` -eq 1 ]; then - EXTERNAL_STORAGE_BLOCK_DEVICE=`cat /tmp/external_block_devices` - # Subtract out block device - let EXTERNAL_STORAGE_NUM_PARTITIONS=`ls -1 ${EXTERNAL_STORAGE_BLOCK_DEVICE}* | wc -l`-1 - if [ ${EXTERNAL_STORAGE_NUM_PARTITIONS} -eq 0 ]; then - EXTERNAL_STORAGE_MOUNT_DEVICE=${EXTERNAL_STORAGE_BLOCK_DEVICE} - elif [ ${EXTERNAL_STORAGE_NUM_PARTITIONS} -eq 1 ]; then - EXTERNAL_STORAGE_MOUNT_DEVICE=`ls -1 ${EXTERNAL_STORAGE_BLOCK_DEVICE}* | tail -n1` - fi -fi -# otherwise, let the user pick -if [ -z ${EXTERNAL_STORAGE_MOUNT_DEVICE} ]; then - > /tmp/external_storage_disk_list - for i in `cat /tmp/external_block_devices`; do - # remove block device from list if numeric partitions exist, since not bootable - let EXTERNAL_STORAGE_NUM_PARTITIONS=`ls -1 $i* | wc -l`-1 - if [ ${EXTERNAL_STORAGE_NUM_PARTITIONS} -eq 0 ]; then - echo $i $(blkid | grep $i | grep -o 'LABEL=".*"' | cut -f2 -d '"') >> /tmp/external_storage_disk_list - else - for j in $(ls $i* | tail -${EXTERNAL_STORAGE_NUM_PARTITIONS}); do - echo $j $(blkid | grep $j | grep -o 'LABEL=".*"' | cut -f2 -d '"') >> /tmp/external_storage_disk_list - done - fi - done - - if [ -x /bin/whiptail ]; then - MENU_OPTIONS="" - n=0 - while read option - do - n=`expr $n + 1` - option=$(echo $option | tr " " "_") - MENU_OPTIONS="$MENU_OPTIONS $n ${option}" - done < /tmp/external_storage_disk_list - - MENU_OPTIONS="$MENU_OPTIONS a Abort" - whiptail --clear --title "Select your External disk" \ - --menu "Choose your External disk [1-$n, a to abort]:" 20 120 8 \ - -- $MENU_OPTIONS \ - 2>/tmp/whiptail - - option_index=$(cat /tmp/whiptail) - else - echo "+++ Select your External disk:" - n=0 - while read option - do - n=`expr $n + 1` - echo "$n. $option" - done < /tmp/external_storage_disk_list - - read \ - -p "Choose your External disk [1-$n, a to abort]: " \ - option_index - fi - - if [ "$option_index" = "a" ]; then - exit 5 - fi - EXTERNAL_STORAGE_MOUNT_DEVICE=`head -n $option_index /tmp/external_storage_disk_list | tail -1 | sed 's/\ .*$//'` -fi - -unlock_remap_luks_dev -if [ "$1" = "rw" ]; then - mount -o rw $EXTERNAL_STORAGE_MOUNT_DEVICE /media -else - mount -o ro $EXTERNAL_STORAGE_MOUNT_DEVICE /media -fi diff --git a/initrd/bin/oem-factory-reset b/initrd/bin/oem-factory-reset index 9b58a2a7c..7cbc1dee5 100755 --- a/initrd/bin/oem-factory-reset +++ b/initrd/bin/oem-factory-reset @@ -365,20 +365,20 @@ if [ "$prompt_output" == "y" \ echo -e "\nChecking for USB media...\n" # ensure /media not mounted umount /media 2>/dev/null - # mount-usb will detect and prompt if no USB inserted - if ! mount-usb rw 2>/tmp/error; then + # mount-external-storage will detect and prompt if no USB inserted + if ! mount-external-storage rw 2>/tmp/error; then ERROR=$(tail -n 1 /tmp/error | fold -s) whiptail_error_die "Unable to mount USB on /media:\n\n${ERROR}" fi else GPG_EXPORT=0 - # needed for USB Security dongle below and is ensured via mount-usb in case of GPG_EXPORT=1 + # needed for USB Security dongle below and is ensured via mount-external-storage in case of GPG_EXPORT=1 enable_usb fi # ensure USB Security Dongle connected echo -e "\nChecking for USB Security Dongle...\n" -# USB kernel modules already loaded via mount-usb +# USB kernel modules already loaded via mount-external-storage if ! gpg --card-status >/dev/null 2>&1 ; then whiptail_error "Can't access USB Security Dongle; \nPlease remove and reinsert, then press Enter." if ! gpg --card-status >/dev/null 2>/tmp/error ; then diff --git a/initrd/etc/gui_functions b/initrd/etc/gui_functions index fcec7078b..d48a5d401 100755 --- a/initrd/etc/gui_functions +++ b/initrd/etc/gui_functions @@ -8,11 +8,11 @@ mount_usb() umount /media || die "Unable to unmount /media" fi # Mount the USB boot device - mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 ) + mount-external-storage && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 ) if [ $USB_FAILED -ne 0 ]; then whiptail --title 'USB Drive Missing' \ --msgbox "Insert your USB drive and press Enter to continue." 16 60 - mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 ) + mount-external-storage && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 ) if [ $USB_FAILED -ne 0 ]; then whiptail $BG_COLOR_ERROR --title 'ERROR: Mounting /media Failed' \ --msgbox "Unable to mount USB device" 16 60