Set a main function

This commit is contained in:
Jeremy Gardais 2020-07-15 17:40:55 +02:00
parent 8376bd355e
commit 16e1324b2a
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 40 additions and 24 deletions

24
winboot
View File

@ -1,8 +1,20 @@
#!/bin/sh #!/bin/sh
GRUB_DEFAULT_PATH='/etc/default/grub' # This script set a specific grub entry (winLOOSE…) for the next boot.
GRUB_DEFAULT_DIR='/etc/default/grub.d' # Then reboot the host
WIN_GRUB="2"
# Vars {{{
readonly PROGNAME=$(basename "${0}")
readonly PROGDIR=$(readlink -m $(dirname "${0}"))
readonly ARGS="${*}"
readonly NBARGS="${#}"
readonly GRUB_DEFAULT_PATH='/etc/default/grub'
readonly GRUB_DEFAULT_DIR='/etc/default/grub.d'
readonly WIN_GRUB="2"
# }}}
main() { # {{{
# First check in Grub default dir if saved mode is set # First check in Grub default dir if saved mode is set
if grep -q -E -R -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_DIR}" if grep -q -E -R -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_DIR}"
@ -25,7 +37,11 @@ else
GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2) GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2)
sudo grub-set-default "${GRUB_DEFAULT_ENTRY}" sudo grub-set-default "${GRUB_DEFAULT_ENTRY}"
sudo update-grub sudo update-grub
printf '%b' "Please launch this script once again.\\n" printf '%b' "Please launch this script (${PROGDIR}/${PROGNAME} ${ARGS}) once again.\\n"
fi fi
}
# }}}
main
exit 0 exit 0