nextboot: minimize and reduce repitition
This commit is contained in:
parent
692c361290
commit
28288670a5
95
bin/nextboot
95
bin/nextboot
|
@ -73,66 +73,75 @@ while getopts ":en" opt; do
|
|||
esac
|
||||
done
|
||||
|
||||
|
||||
# If -e wasn't set, and systemd-boot isn't installed, fail over to efimode anyways
|
||||
if [[ ! -v efimode && ! -v sdboot ]]; then
|
||||
echo "W: systemd-boot not installed. Choosing EFI boot entries instead..."
|
||||
efimode=1
|
||||
fi
|
||||
|
||||
|
||||
# If we're in EFI mode
|
||||
if [[ -v efimode ]]; then
|
||||
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="$(selectentry "$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
|
||||
elif [[ ! -v efimode ]]; then
|
||||
title="Pick systemd-boot entry config"
|
||||
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 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
|
||||
elif [[ "$choice" != "$biosname" ]]; then
|
||||
sudo bootctl set-oneshot "$choice"
|
||||
# Add an option to speed past the boot menu, since we've already
|
||||
# chosen the desired entry.
|
||||
rebootopts+=("--boot-loader-menu=1")
|
||||
fi
|
||||
else
|
||||
echo "E: you DEFINITELY don't belong here..."
|
||||
echo "E: idk how you got here..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Specialize prompt for reboot mode
|
||||
if [[ -v noreboot ]]; then
|
||||
prompt="Entry for next boot:"
|
||||
elif [[ ! -v noreboot ]]; 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"
|
||||
|
||||
# Add an option to speed past the boot menu, since we've already
|
||||
# chosen the desired entry.
|
||||
rebootopts+=("--boot-loader-menu=1")
|
||||
|
||||
else
|
||||
echo "E: you DEFINITELY don't belong here..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "E: must you insist on breaking my things?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Reboot if necessary
|
||||
[[ ! -v noreboot ]] && sudo systemctl reboot "${rebootopts[@]}"
|
||||
|
|
Loading…
Reference in New Issue