Debian Codegraph @

scripts/bin/hide_reveal_grub_efi_ent

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: Hide or reveal the menus in GRUB EFI NB config file.
5 # Load DRBL setting and functions
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9 . /etc/drbl/drbl-ocs.conf
10 . $DRBL_SCRIPT_PATH/sbin/ocs-functions
11
12 # Functions
13 prog="$(basename $0)"
14 USAGE() {
15 echo "Usage:"
16 echo "$prog ID [hide|reveal] GRUB_CONF_FILE"
17 echo " Options:"
18 echo " -b, --efi-boot-file FILE Assign the EFI boot file. This is for menuentry local-disk in reveal case only"
19 echo " -l, --efi-os-label LABEL Assign the EFI OS label. This is for menuentry local-disk in reveal case only"
20 echo " -p, --efi-sys-part-no PART_NO Assign the EFI System Partition, or ESP. This is for menuentry local-disk in reveal case only"
21 echo "Ex: To hide the menuentry id local-disk in /tftpboot/nbi_img/grub/grub.cfg, run:"
22 echo " $prog local-disk hide /tftpboot/nbi_img/grub/grub.cfg"
23 }
24
25 ########################
26 ##### MAIN PROGRAM #####
27 ########################
28
29 while [ $# -gt 0 ]; do
30 case "$1" in
31 -p|--efi-sys-part-no)
32 shift;
33 # skip the -xx option, in case
34 if [ -z "$(echo $1 |grep ^-.)" ]; then
35 efi_spt="$1"
36 shift
37 fi
38 [ -z "$efi_spt" ] && USAGE && exit 1
39 ;;
40 -b|--efi-boot-file)
41 shift;
42 # skip the -xx option, in case
43 if [ -z "$(echo $1 |grep ^-.)" ]; then
44 efi_boot_file="$1"
45 shift
46 fi
47 [ -z "$efi_boot_file" ] && USAGE && exit 1
48 ;;
49 -l|--efi-os-label)
50 shift;
51 # skip the -xx option, in case
52 if [ -z "$(echo $1 |grep ^-.)" ]; then
53 efi_os_label="$1"
54 shift
55 fi
56 [ -z "$efi_os_label" ] && USAGE && exit 1
57 ;;
58 -*) echo "${0}: ${1}: invalid option" >&2
59 USAGE >& 2
60 exit 2 ;;
61 *) break ;;
62 esac
63 done
64
65 ENTRY_ID="$1"
66 ACT="$2"
67 GRUB_CONF_T="$3"
68 for i in ENTRY_ID ACT GRUB_CONF_T; do
69 eval arg=\$$i
70 [ -z "$arg" ] && USAGE && exit 1
71 done
72 #check_entryid_in_grub_efi_cfg $ENTRY_ID $GRUB_CONF_T
73 if [ -n "$GRUB_CONF_T" -a ! -e "$GRUB_CONF_T" ]; then
74 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
75 echo "File $GRUB_CONF_T not found. No support for uEFI network boot."
76 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
77 exit 2
78 fi
79 # turn off MENU DEFAULT & turn on MENU HIDE for the specified image
80 lines="$(get_grub_efi_image_block "--id $ENTRY_ID" $GRUB_CONF_T)"
81 begin_line="$(LC_ALL=C echo $lines | awk -F" " '{print $1}')"
82 end_line="$(LC_ALL=C echo $lines | awk -F" " '{print $2}')"
83 case "$ACT" in
84 "hide")
85 if [ -z "$begin_line" -o -z "$end_line" ]; then
86 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
87 echo "No hidden menuentry with ID $ENTRY_ID found! Skip it."
88 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
89 exit 2
90 fi
91 [ -n "$VERBOSE" ] && echo "Hide $ENTRY_ID in $GRUB_CONF_T... "
92 sub_act_cmd="if ($begin_line..$end_line) {s/^([[:space:]]*[^#].*)/#\$1/i}"
93 LC_ALL=C perl -pi -e "$sub_act_cmd" $GRUB_CONF_T
94 ;;
95 "reveal")
96 if [ -z "$begin_line" -o -z "$end_line" ]; then
97 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
98 echo "No revealed menuentry with ID $ENTRY_ID found! Skip it."
99 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
100 exit 2
101 fi
102 # The menuentry is like:
103 #menuentry "Local" --id local-disk {
104 # # This is a template menuentry to boot a local harddrive
105 # echo "Booting local disk..."
106 # set root=(hd0,1)
107 # chainloader /EFI/redhat/grub.efi +1
108 #}
109 [ -n "$VERBOSE" ] && echo "Reveal $ENTRY_ID in $GRUB_CONF_T... "
110 sub_act_cmd="if ($begin_line..$end_line) {s/^#(.*)/\$1/i}"
111 LC_ALL=C perl -pi -e "$sub_act_cmd" $GRUB_CONF_T
112
113 ;;
114 esac