Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Last active August 29, 2022 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hayao0819/16fb4e2badac87ad1c81f9b1d907e68c to your computer and use it in GitHub Desktop.
Save Hayao0819/16fb4e2badac87ad1c81f9b1d907e68c to your computer and use it in GitHub Desktop.
指定したOSで再起動するスクリプト
#!/usr/bin/env bash
set -Eeu -o pipefail
# shellcheck source=/dev/null
source /dev/stdin < <(curl -sL "https://github.com/Hayao0819/FasBashLib/releases/download/v0.2.5/fasbashlib.sh")
(( "$UID" == 0 )) || { Msg.Err "Please run as root."; exit 1; }
readarray -t EntryList < <(awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg | grep -v "^$")
LastEntry=$(
last="$(grub-editenv list | cut -d "=" -f 2-)"
[[ -n "${last-""}" ]] || exit 0
eval "Array=($(grep "$last" /boot/grub/grub.cfg))"
# shellcheck disable=SC2154
echo "${Array[1]}"
)
grub-reboot "$(Choice -d "$LastEntry" -p "Select an entry to boot:" "${EntryList[@]}")" && reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment