2023-02-08 21:01:48 +00:00
|
|
|
#!/bin/bash
|
2017-07-03 17:07:03 +00:00
|
|
|
# Scan for USB installation options
|
2017-07-12 04:17:45 +00:00
|
|
|
set -e -o pipefail
|
2017-07-03 17:07:03 +00:00
|
|
|
. /etc/functions
|
2020-07-10 18:00:13 +00:00
|
|
|
. /etc/gui_functions
|
2018-12-06 23:24:28 +00:00
|
|
|
. /tmp/config
|
2017-07-03 17:07:03 +00:00
|
|
|
|
2023-02-20 16:01:17 +00:00
|
|
|
TRACE "Under /bin/media-scan"
|
2023-02-18 17:58:43 +00:00
|
|
|
|
2023-10-18 17:15:48 +00:00
|
|
|
#Booting from external media should be authenticated if supported
|
2023-11-06 15:04:51 +00:00
|
|
|
gpg_auth || die "GPG authentication failed"
|
2023-10-18 17:15:48 +00:00
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
# Unmount any previous boot device
|
|
|
|
if grep -q /boot /proc/mounts ; then
|
|
|
|
umount /boot \
|
2017-07-22 20:32:10 +00:00
|
|
|
|| die "Unable to unmount /boot"
|
2017-07-04 23:49:14 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-26 20:03:03 +00:00
|
|
|
available_partitions="$(blkid | while read line; do echo $line | awk -F ":" {'print $1'}; done )"
|
|
|
|
|
|
|
|
if [ "$1" == "usb" ]; then
|
|
|
|
# Mount the USB boot device
|
|
|
|
mount_usb || die "Unable to mount /media"
|
|
|
|
elif $(echo $available_partitions | grep -q "$1"); then
|
|
|
|
if grep -q /media /proc/mounts; then
|
|
|
|
umount /media \
|
|
|
|
|| die "Unable to unmount /media"
|
|
|
|
fi
|
|
|
|
mount "$1" /media \
|
|
|
|
|| die "Unable to mount $1 to /media"
|
|
|
|
fi
|
2020-07-10 18:00:13 +00:00
|
|
|
|
2020-02-20 04:16:39 +00:00
|
|
|
# Get USB boot device
|
|
|
|
USB_BOOT_DEV=$(grep "/media" /etc/mtab | cut -f 1 -d' ')
|
2017-07-03 17:07:03 +00:00
|
|
|
|
|
|
|
# Check for ISO first
|
|
|
|
get_menu_option() {
|
2018-05-02 21:29:27 +00:00
|
|
|
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}"
|
2018-10-22 15:01:05 +00:00
|
|
|
done < /tmp/iso_menu.txt
|
2018-05-02 21:29:27 +00:00
|
|
|
|
2023-06-30 17:36:33 +00:00
|
|
|
MENU_OPTIONS="$MENU_OPTIONS a Abort"
|
|
|
|
|
2022-11-15 20:11:58 +00:00
|
|
|
whiptail $BG_COLOR_MAIN_MENU --title "Select your ISO boot option" \
|
2023-06-30 17:36:33 +00:00
|
|
|
--menu "Choose the ISO boot option [1-$n]:" 0 80 8 \
|
2018-05-02 21:29:27 +00:00
|
|
|
-- $MENU_OPTIONS \
|
|
|
|
2>/tmp/whiptail || die "Aborting boot attempt"
|
2017-07-03 17:07:03 +00:00
|
|
|
|
2018-05-02 21:29:27 +00:00
|
|
|
option_index=$(cat /tmp/whiptail)
|
|
|
|
else
|
|
|
|
echo "+++ Select your ISO boot option:"
|
|
|
|
n=0
|
|
|
|
while read option
|
|
|
|
do
|
|
|
|
n=`expr $n + 1`
|
|
|
|
echo "$n. $option"
|
|
|
|
done < /tmp/iso_menu.txt
|
|
|
|
|
|
|
|
read \
|
2023-06-30 17:36:33 +00:00
|
|
|
-p "Choose the ISO boot option [1-$n, a to abort]: " \
|
2018-05-02 21:29:27 +00:00
|
|
|
option_index
|
|
|
|
fi
|
2017-07-03 17:07:03 +00:00
|
|
|
|
2023-06-30 17:36:33 +00:00
|
|
|
# Empty occurs when aborting fbwhiptail with esc-esc
|
|
|
|
if [ -z "$option_index" ] || [ "$option_index" = "a" ]; then
|
2017-07-08 20:59:37 +00:00
|
|
|
die "Aborting boot attempt"
|
2017-07-03 17:07:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
option=`head -n $option_index /tmp/iso_menu.txt | tail -1`
|
2023-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
if [ -z "$option" ]; then
|
|
|
|
die "Failed to find menu option $option_index"
|
|
|
|
fi
|
2017-07-03 17:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# create ISO menu options
|
2017-07-12 04:17:45 +00:00
|
|
|
ls -1r /media/*.iso 2>/dev/null > /tmp/iso_menu.txt || true
|
2017-07-03 17:07:03 +00:00
|
|
|
if [ `cat /tmp/iso_menu.txt | wc -l` -gt 0 ]; then
|
|
|
|
option_confirm=""
|
|
|
|
while [ -z "$option" -a "$option_index" != "s" ]
|
|
|
|
do
|
|
|
|
get_menu_option
|
|
|
|
done
|
|
|
|
|
2023-06-30 17:41:07 +00:00
|
|
|
MOUNTED_ISO="$option"
|
|
|
|
ISO="${option:7}" # remove /media/ to get device relative path
|
|
|
|
DO_WITH_DEBUG kexec-iso-init "$MOUNTED_ISO" "$ISO" "$USB_BOOT_DEV"
|
2017-07-03 17:07:03 +00:00
|
|
|
|
2023-06-30 17:41:07 +00:00
|
|
|
die "Something failed in iso init"
|
2017-07-03 17:07:03 +00:00
|
|
|
fi
|
|
|
|
|
2023-06-30 17:41:07 +00:00
|
|
|
# No *.iso files on media, try ordinary bootable USB
|
|
|
|
|
2022-10-25 22:09:15 +00:00
|
|
|
if [ "$CONFIG_RESTRICTED_BOOT" = y ]; then
|
2023-06-30 17:41:07 +00:00
|
|
|
die "No ISO files found, bootable USB not allowed with Restricted Boot."
|
2022-10-25 22:09:15 +00:00
|
|
|
fi
|
|
|
|
|
2017-07-03 17:07:03 +00:00
|
|
|
echo "!!! Could not find any ISO, trying bootable USB"
|
|
|
|
# Attempt to pull verified config from device
|
2018-05-02 21:29:27 +00:00
|
|
|
if [ -x /bin/whiptail ]; then
|
2023-04-17 20:11:59 +00:00
|
|
|
DO_WITH_DEBUG kexec-select-boot -b /media -c "*.cfg" -u -g -s
|
2018-05-02 21:29:27 +00:00
|
|
|
else
|
2023-04-17 20:11:59 +00:00
|
|
|
DO_WITH_DEBUG kexec-select-boot -b /media -c "*.cfg" -u -s
|
2018-05-02 21:29:27 +00:00
|
|
|
fi
|
2017-07-03 17:07:03 +00:00
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
die "Something failed in selecting boot"
|