Add argument management

This commit is contained in:
Jeremy Gardais 2020-07-15 17:48:09 +02:00
parent 16e1324b2a
commit ecab3bea7e
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 42 additions and 2 deletions

44
winboot
View File

@ -12,6 +12,10 @@ readonly NBARGS="${#}"
readonly GRUB_DEFAULT_PATH='/etc/default/grub' readonly GRUB_DEFAULT_PATH='/etc/default/grub'
readonly GRUB_DEFAULT_DIR='/etc/default/grub.d' readonly GRUB_DEFAULT_DIR='/etc/default/grub.d'
readonly WIN_GRUB="2" readonly WIN_GRUB="2"
## By default, the host should reboot at the end of the script
REBOOT=0
# }}} # }}}
main() { # {{{ main() { # {{{
@ -21,7 +25,7 @@ main() { # {{{
then then
printf '%b' "Reboot to windaube partition\\n" printf '%b' "Reboot to windaube partition\\n"
sudo grub-reboot "${WIN_GRUB}" sudo grub-reboot "${WIN_GRUB}"
sudo systemctl reboot [ "${REBOOT}" -eq "0" ] && sudo systemctl reboot
fi fi
# Otherwise check the default grub file # Otherwise check the default grub file
@ -29,7 +33,7 @@ main() { # {{{
then then
printf '%b' "Reboot to windaube partition\\n" printf '%b' "Reboot to windaube partition\\n"
sudo grub-reboot "${WIN_GRUB}" sudo grub-reboot "${WIN_GRUB}"
sudo systemctl reboot [ "${REBOOT}" -eq "0" ] && sudo systemctl reboot
else else
printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n" printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n"
@ -42,6 +46,42 @@ main() { # {{{
} }
# }}} # }}}
# Manage arguments # {{{
# This code can't be in a function due to arguments
if [ ! "${NBARGS}" -eq "0" ]; then
manage_arg="0"
# Parse all options (start with a "-") one by one
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
--reboot ) ## A reboot was requested (default behaviour)
REBOOT=0
;;
-- ) ## End of options list
## End the while loop
break
;;
* ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---"
usage
exit 1
;;
esac
## Move to the next argument
shift
manage_arg=$((manage_arg+1))
done
fi
# }}}
main main
exit 0 exit 0