Compare commits
No commits in common. "77c6312ead9c3d77f3e6f0f77b3cf7561a8feb3a" and "9952d040568d3f8bbbf494e4188badceaefc76cc" have entirely different histories.
77c6312ead
...
9952d04056
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# This script assumes that the specified block device can be completely wiped
|
|
||||||
|
|
||||||
|
|
||||||
# exit when any command fails
|
|
||||||
set -e
|
|
||||||
|
|
||||||
disk=$1
|
|
||||||
mp=$(mktemp -d)
|
|
||||||
|
|
||||||
# f3probe the block device for counterfeit flash memory
|
|
||||||
f3probe --destructive --time-ops $disk
|
|
||||||
|
|
||||||
# f3write and f3read need a mounted fs
|
|
||||||
mkfs.ext4 -D -F -F $disk
|
|
||||||
|
|
||||||
mount $disk $mp
|
|
||||||
|
|
||||||
f3write $mp
|
|
||||||
|
|
||||||
sync
|
|
||||||
|
|
||||||
f3read $mp
|
|
||||||
|
|
||||||
umount $mp
|
|
162
bin/nextboot
162
bin/nextboot
|
@ -10,54 +10,67 @@ bootctl is-installed &> /dev/null && sdboot=1
|
||||||
[[ "$(bootctl reboot-to-firmware)" == "supported" ]] && fwboot=1
|
[[ "$(bootctl reboot-to-firmware)" == "supported" ]] && fwboot=1
|
||||||
|
|
||||||
|
|
||||||
selectentry() {
|
picksdboot() {
|
||||||
# Usage: selectentry <title> <prompt>
|
# Usage: picksdboot <title> <prompt>
|
||||||
local sel PS3 COLUMNS
|
local entry PS3 COLUMNS
|
||||||
PS3="$2 "
|
PS3="$2 "
|
||||||
COLUMNS=1
|
COLUMNS=1
|
||||||
|
|
||||||
# Print title to stderr
|
# Print title to stderr
|
||||||
printf "\n%s\n\n" "$1" >&2
|
printf "\n%s\n\n" "$1" >&2
|
||||||
|
|
||||||
# Populate entry list array
|
# Put all systemd-boot loder entry confs into an array
|
||||||
# If we're in EFI mode
|
mapfile -t sdbootlist < <(systemctl --boot-loader-entry=help)
|
||||||
if [[ -v efimode ]]; then
|
|
||||||
# This one is fun
|
|
||||||
# mapfile splits stdin on \n to an array
|
|
||||||
# The sed regex looks for an asterisk in the 8th position (0 indexed),
|
|
||||||
# which marks an efi boot entry as "active", so those are the only ones
|
|
||||||
# we care to add to the list.
|
|
||||||
# It *seems* like one could put mapfile at the end of the pipeline, but
|
|
||||||
# each command gets run in a subshell, so the array is lost. (ref: SC2031)
|
|
||||||
mapfile -t entrylist < <(efibootmgr | sed -n '/.\{8\}\*/p')
|
|
||||||
|
|
||||||
# Add firmware interface entry if supported
|
# Only add the firmware interface to the list if booting to it is supported
|
||||||
[[ -v fwboot ]] && entrylist+=("$biosname")
|
[[ -v fwboot ]] && sdbootlist+=("$biosname")
|
||||||
|
|
||||||
# If we're in systemd-boot mode
|
select entry in "${sdbootlist[@]}"; do
|
||||||
elif [[ ! -v efimode ]]; then
|
|
||||||
# Put all systemd-boot loder entry confs into an array
|
|
||||||
mapfile -t entrylist < <(systemctl --boot-loader-entry=help)
|
|
||||||
|
|
||||||
# Only add the firmware interface to the list if booting to it is supported
|
|
||||||
[[ -v fwboot ]] && entrylist+=("$biosname")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get user selection
|
|
||||||
select sel in "${entrylist[@]}"; do
|
|
||||||
break
|
break
|
||||||
done
|
done
|
||||||
|
|
||||||
# If in efi mode and the user did not select the firmware config menu item,
|
printf "%s" "$entry"
|
||||||
# then drop everything except for the BOOTNUM (character 4-8)
|
}
|
||||||
[[ -v efimode && "$sel" != "$biosname" ]] && sel="${sel:4:4}"
|
|
||||||
|
|
||||||
# Print result to stdout
|
pickefi() {
|
||||||
printf "%s" "$sel"
|
# Usage: pickefi <title> <prompt>
|
||||||
|
local bootnext PS3 COLUMNS
|
||||||
|
PS3="$2 "
|
||||||
|
COLUMNS=1
|
||||||
|
|
||||||
|
# Print title to stderr
|
||||||
|
printf "\n%s\n\n" "$1" >&2
|
||||||
|
|
||||||
|
# This one is fun
|
||||||
|
# mapfile splits stdin on \n to an array
|
||||||
|
# The sed regex looks for an asterisk in the 8th position (0 indexed),
|
||||||
|
# which marks an efi boot entry as "active", so those are the only ones
|
||||||
|
# we care to add to the list.
|
||||||
|
# It *seems* like one could put mapfile at the end of the pipeline, but
|
||||||
|
# each command gets run in a subshell, so the array is lost. (ref: SC2031)
|
||||||
|
mapfile -t efientries < <(efibootmgr | sed -n '/.\{8\}\*/p')
|
||||||
|
|
||||||
|
# Rebooting to the firmware interface only works with systemd-boot, so only add
|
||||||
|
# it to the EFI mode list if systemd-boot is available and it's supported
|
||||||
|
[[ -v sdboot && -v fwboot ]] && efientries+=("$biosname")
|
||||||
|
|
||||||
|
select efiselection in "${efientries[@]}"; do
|
||||||
|
|
||||||
|
# If they chose the firmware interface
|
||||||
|
if [[ "$efiselection" == "$biosname" ]]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
# Take only character 4-8 of the entry, which is the BOOTNUM
|
||||||
|
bootnext="${efiselection:4:4}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "%s" "$bootnext"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Parse command line options
|
|
||||||
while getopts ":en" opt; do
|
while getopts ":en" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
e)
|
e)
|
||||||
|
@ -73,75 +86,66 @@ while getopts ":en" opt; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# If -e wasn't set, and systemd-boot isn't installed, fail over to efimode anyways
|
# If -e wasn't set, and systemd-boot isn't installed, fail over to efimode anyways
|
||||||
if [[ ! -v efimode && ! -v sdboot ]]; then
|
if [[ ! -v efimode && ! -v sdboot ]]; then
|
||||||
echo "W: systemd-boot not installed. Choosing EFI boot entries instead..."
|
echo "W: systemd-boot not installed. Choosing EFI boot entries instead..."
|
||||||
efimode=1
|
efimode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# If we're in EFI mode
|
# If we're in EFI mode
|
||||||
if [[ -v efimode ]]; then
|
if [[ -v efimode ]]; then
|
||||||
title="Pick EFI boot entry"
|
title="Pick EFI boot entry"
|
||||||
|
prompt="Entry"
|
||||||
|
|
||||||
|
if [[ -v noreboot ]]; then
|
||||||
|
prompt="$prompt for next boot:"
|
||||||
|
elif [[ ! -v noreboot ]]; then
|
||||||
|
prompt="$prompt to boot IMMEDIATELY:"
|
||||||
|
else
|
||||||
|
echo "E: idk how you got here..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prompt for the user's choice
|
||||||
|
choice="$(pickefi "$title" "$prompt")"
|
||||||
|
|
||||||
|
# A special case to boot into firmware interface
|
||||||
|
if [[ "$choice" == "$biosname" ]]; then
|
||||||
|
sudo bootctl reboot-to-firmware true
|
||||||
|
elif [[ "$choice" != "$biosname" ]]; then
|
||||||
|
sudo efibootmgr -q --bootnext "$choice"
|
||||||
|
fi
|
||||||
|
|
||||||
# If we're in systemd-boot mode
|
# If we're in systemd-boot mode
|
||||||
elif [[ ! -v efimode ]]; then
|
elif [[ ! -v efimode ]]; then
|
||||||
title="Pick systemd-boot entry config"
|
title="Pick systemd-boot entry config"
|
||||||
|
prompt="Entry"
|
||||||
|
|
||||||
else
|
if [[ -v noreboot ]]; then
|
||||||
echo "E: idk how you got here..."
|
prompt="$prompt for next boot:"
|
||||||
exit 1
|
elif [[ ! -v noreboot ]]; then
|
||||||
fi
|
prompt="$prompt to boot IMMEDIATELY:"
|
||||||
|
else
|
||||||
|
echo "E: idk how you got here either..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prompt for the user's choice
|
||||||
|
choice="$(picksdboot "$title" "$prompt")"
|
||||||
|
|
||||||
# Specialize prompt for reboot mode
|
# A special case to boot into firmware interface
|
||||||
if [[ -v noreboot ]]; then
|
if [[ "$choice" == "$biosname" ]]; then
|
||||||
prompt="Entry for next boot:"
|
sudo bootctl reboot-to-firmware true
|
||||||
elif [[ ! -v noreboot ]]; then
|
elif [[ "$choice" != "$biosname" ]]; then
|
||||||
prompt="Entry to boot IMMEDIATELY:"
|
|
||||||
else
|
|
||||||
echo "E: idk how you got here either..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Prompt for the user's choice
|
|
||||||
choice="$(selectentry "$title" "$prompt")"
|
|
||||||
|
|
||||||
|
|
||||||
# A special case to boot into firmware interface
|
|
||||||
if [[ "$choice" == "$biosname" ]]; then
|
|
||||||
sudo bootctl reboot-to-firmware true
|
|
||||||
|
|
||||||
# For all other entry selections
|
|
||||||
elif [[ "$choice" != "$biosname" ]]; then
|
|
||||||
|
|
||||||
# If we're in EFI mode
|
|
||||||
if [[ -v efimode ]]; then
|
|
||||||
|
|
||||||
# Set bootnext in nvram
|
|
||||||
sudo efibootmgr -q --bootnext "$choice"
|
|
||||||
|
|
||||||
# If we're in systemd-boot mode
|
|
||||||
elif [[ ! -v efimode ]]; then
|
|
||||||
|
|
||||||
# Set default boot entry only for next boot
|
|
||||||
sudo bootctl set-oneshot "$choice"
|
sudo bootctl set-oneshot "$choice"
|
||||||
|
|
||||||
# Add an option to speed past the boot menu, since we've already
|
# Add an option to speed past the boot menu, since we've already
|
||||||
# chosen the desired entry.
|
# chosen the desired entry.
|
||||||
rebootopts+=("--boot-loader-menu=1")
|
rebootopts+=("--boot-loader-menu=1")
|
||||||
|
|
||||||
else
|
|
||||||
echo "E: you DEFINITELY don't belong here..."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "E: must you insist on breaking my things?"
|
echo "E: you DEFINITELY don't belong here..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Reboot if necessary
|
|
||||||
[[ ! -v noreboot ]] && sudo systemctl reboot "${rebootopts[@]}"
|
[[ ! -v noreboot ]] && sudo systemctl reboot "${rebootopts[@]}"
|
||||||
|
|
Loading…
Reference in New Issue