| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # Description: set the default grub efi image for grub menu format. |
| 5 | |
| 6 | # Load DRBL setting and functions |
| 7 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 8 | |
| 9 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 10 | |
| 11 | # |
| 12 | GRUB_CONF_DEF="$GRUB_EFINB_DIR/grub.cfg" |
| 13 | |
| 14 | # |
| 15 | USAGE() { |
| 16 | echo "Usage:" |
| 17 | echo "To set the default GRUB client menu:" |
| 18 | echo "`basename $0` [OPTION] ENTRY_ID" |
| 19 | echo " Options:" |
| 20 | echo " -i, --entry-id ENTRY_ID Set ENTRY_ID as the default one" |
| 21 | echo " -c, --config CONF Use the CONF file instead of default one ($GRUB_CONF_DEF)" |
| 22 | echo " -l, --label LABEL Assign the menuentry LABEL description" |
| 23 | echo " -v, --verbose Show verbose messages" |
| 24 | echo " -h, --help Display this help and exit" |
| 25 | echo "ENTRY_ID is the menuentry ID" |
| 26 | echo "Ex:" |
| 27 | echo "To set the default menuentry as \"drbl-client\" without updating the menuentry label" |
| 28 | echo " $ocs -i drbl-client" |
| 29 | echo "To set the default menuentry as \"clonezilla-se-client\" and update the menuentry label as \"Clonezilla: multicast restore precise-x86 to disk sda\"" |
| 30 | echo " $ocs -i clonezilla-se-client -l \"Clonezilla: multicast restore precise-x86 to disk sda\"" |
| 31 | echo |
| 32 | } |
| 33 | |
| 34 | #################### |
| 35 | ### Main program ### |
| 36 | #################### |
| 37 | |
| 38 | ocs_file="$0" |
| 39 | ocs=`basename $ocs_file` |
| 40 | # |
| 41 | # Parse command-line options |
| 42 | while [ $# -gt 0 ]; do |
| 43 | case "$1" in |
| 44 | -i|--entry-id) |
| 45 | shift; |
| 46 | # skip the -xx option, in case |
| 47 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 48 | entry_id="$1" |
| 49 | shift |
| 50 | fi |
| 51 | [ -z "$entry_id" ] && USAGE && exit 1 |
| 52 | ;; |
| 53 | -c|--config) |
| 54 | shift; |
| 55 | # skip the -xx option, in case |
| 56 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 57 | GRUB_CONF="$1" |
| 58 | shift |
| 59 | fi |
| 60 | [ -z "$GRUB_CONF" ] && USAGE && exit 1 |
| 61 | ;; |
| 62 | -h|--help) |
| 63 | USAGE >& 2 |
| 64 | exit 2 ;; |
| 65 | -l|--label) |
| 66 | shift; |
| 67 | # skip the -xx option, in case |
| 68 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 69 | ENTRY_LABEL="$1" |
| 70 | shift |
| 71 | fi |
| 72 | [ -z "$ENTRY_LABEL" ] && USAGE && exit 1 |
| 73 | ;; |
| 74 | -v|--verbose) |
| 75 | VERBOSE="on" |
| 76 | shift;; |
| 77 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 78 | USAGE >& 2 |
| 79 | exit 2 ;; |
| 80 | *) break ;; |
| 81 | esac |
| 82 | done |
| 83 | |
| 84 | [ -z "$GRUB_CONF" ] && GRUB_CONF=$GRUB_CONF_DEF |
| 85 | if [ -z "$entry_id" ]; then |
| 86 | [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 87 | echo "You must specify the entry ID! Program terminated!!!" |
| 88 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 89 | USAGE |
| 90 | exit 1 |
| 91 | fi |
| 92 | # Enable it first |
| 93 | hide_reveal_grub_efi_ent "$entry_id" reveal $GRUB_CONF |
| 94 | |
| 95 | # Set default one |
| 96 | sub_default_grub_efi_img "$entry_id" $GRUB_CONF "$ENTRY_LABEL" |