4 echo "$0: <host> <set/del> [BOOT_OPTS]"
6 .
/etc
/vzt
/vzt-pxe-boot.cfg
18 ip
=`gethostip $host | gawk '{ print \$1 }'` ||
exit 1
19 hex_ip
=`gethostip $host | gawk '{ print \$3 }'` ||
exit 1
21 function change_pxe
(){
25 PATT
="$(echo $PATT | sed -r 's/\//\\\//g')"
26 local default
=$
( cat $config |
awk "{if (\$1 ~ /label/) point=\$2; if ((\$1 ~ /kernel/) && (\$2 ~ /$PATT/)) print point }")
28 [ -n "$default" ] ||
{
29 if [ $fatal -ne 0 ]; then
30 echo "No pattern found in $config"
37 [ $
(echo "$default" |
wc -w) -eq 1 ] ||
{
38 echo "Pattern found several times in $config"
42 sed -i "s/default .*/default $default/" $config
47 function add_entry_pxe
()
51 local kernel_opts
="$3"
54 grep "label $title_text" $config
56 echo "Err: label $title_text already present in: $config"
57 grep -n -A5 "label $title_text" $config
61 echo "#$title_text" >> $config
62 echo "label $title_text" >> $config
63 echo " kernel $kernel_img " >> $config
64 echo " append initrd=$initrd_img $kernel_opts" >> $config
68 function setup_pxe_config
73 local kernel_opts
="$4"
75 local kpattern
=$kernel_img
77 if [ ! -f $PXE_ROOT/$kernel_img ]; then
78 echo "kernel image: $PXE_ROOT/$kernel_img not found "
81 if [ ! -f $PXE_ROOT/$initrd_img ]; then
82 echo "initrd image: $PXE_ROOT/$initrd_img not found"
86 change_pxe
$conf $kpattern 0
88 echo "try to add new entry: $ $kpattern"
89 add_entry_pxe
$conf "$kernel_img" "$kernel_opts" "$initrd_img" "$title_text"
90 change_pxe
$conf $kpattern 1
95 echo "****************************************"
96 echo "*** Kernel was successfully installed ***"
97 echo "****************************************"
99 echo "*** Error while add new entry ***"
100 echo "config:$conf may be corrupted, plese check it"
105 echo "****************************************"
106 echo "*** Kernel was successfully selected ***"
107 echo "****************************************"
112 del
) rm -rf $PXE_ROOT/$PXE_CONFIG_DIR/$hex_ip;;
113 add
) if [ ! -f $PXE_ROOT/$PXE_CONFIG_DIR/$ip ];then
114 echo "$PXE_ROOT/$PXE_CONFIG_DIR/$ip not exist,"
115 echo "create new config based on: $PXE_ROOT/$PXE_CONFIG_DIR/default"
116 cp $PXE_ROOT/$PXE_CONFIG_DIR/default
$PXE_ROOT/$PXE_CONFIG_DIR/$ip
118 setup_pxe_config
"$PXE_ROOT/$PXE_CONFIG_DIR/$ip" "$PXE_KERNEL_DIR/$kernel_img" "$PXE_KERNEL_DIR/$initrd_img" "$boot_opts" "$title_msg" ||
exit 1;
119 rm -rf $PXE_ROOT/$PXE_CONFIG_DIR/$hex_ip ;
120 ln -s $ip $PXE_ROOT/$PXE_CONFIG_DIR/$hex_ip ;;
121 * ) echo "Unknown action";