1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Hide or reveal the menus in PXE Linux config file.
# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
# functions
prog="$(basename $0)"
USAGE() {
echo "Usage:"
echo "$prog LABEL [hide|reveal] PXE_CONF_FILE"
echo "Ex: To hide the label drbl in /tftpboot/nbi_img/pxelinux.cfg/default, run:"
echo " $prog drbl hide /tftpboot/nbi_img/pxelinux.cfg/default"
}
lab="$1"
ACT="$2"
PXE_CONF="$3"
for i in lab ACT PXE_CONF; do
eval arg=\$$i
[ -z "$arg" ] && USAGE && exit 1
done
if [ ! -f "$PXE_CONF" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "file $PXE_CONF not found!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
exit 1
fi
# Check in the other way, not using check_img_in_pxe_cfg since it gives red error, while we just need warning especially when "clonezilla-live" is not available for Clonezilla SE with Clonezilla live client.
#check_img_in_pxe_cfg $lab $PXE_CONF
# turn off MENU DEFAULT & turn on MENU HIDE for the specified image
lines="$(get_pxecfg_image_block $lab $PXE_CONF)"
begin_line="$(LC_ALL=C echo $lines | awk -F" " '{print $1}')"
end_line="$(LC_ALL=C echo $lines | awk -F" " '{print $2}')"
case "$ACT" in
"hide")
[ -n "$VERBOSE" ] && echo "Hide $lab in $PXE_CONF... "
if [ -z "$begin_line" -o -z "$end_line" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "No hidden label $lab was found! Skip it."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
exit 2
fi
sub_act_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU HIDE.*/ MENU HIDE/i}"
;;
"reveal")
[ -n "$VERBOSE" ] && echo "Reveal $lab in $PXE_CONF... "
if [ -z "$begin_line" -o -z "$end_line" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "No revealed label $lab was found! Skip it."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
exit 2
fi
sub_act_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU HIDE.*/ # MENU HIDE/i}"
;;
esac
LC_ALL=C perl -pi -e "$sub_act_cmd" $PXE_CONF
|