Add argument management
This commit is contained in:
parent
16e1324b2a
commit
ecab3bea7e
44
winboot
44
winboot
|
@ -12,6 +12,10 @@ readonly NBARGS="${#}"
|
|||
readonly GRUB_DEFAULT_PATH='/etc/default/grub'
|
||||
readonly GRUB_DEFAULT_DIR='/etc/default/grub.d'
|
||||
readonly WIN_GRUB="2"
|
||||
|
||||
## By default, the host should reboot at the end of the script
|
||||
REBOOT=0
|
||||
|
||||
# }}}
|
||||
|
||||
main() { # {{{
|
||||
|
@ -21,7 +25,7 @@ main() { # {{{
|
|||
then
|
||||
printf '%b' "Reboot to windaube partition\\n"
|
||||
sudo grub-reboot "${WIN_GRUB}"
|
||||
sudo systemctl reboot
|
||||
[ "${REBOOT}" -eq "0" ] && sudo systemctl reboot
|
||||
fi
|
||||
|
||||
# Otherwise check the default grub file
|
||||
|
@ -29,7 +33,7 @@ main() { # {{{
|
|||
then
|
||||
printf '%b' "Reboot to windaube partition\\n"
|
||||
sudo grub-reboot "${WIN_GRUB}"
|
||||
sudo systemctl reboot
|
||||
[ "${REBOOT}" -eq "0" ] && sudo systemctl reboot
|
||||
else
|
||||
|
||||
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
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue