Use config files instead of globbing, adjust indention
[grml-terminalserver.git] / templates / grub-pxelinux_config
1 # the following variables are available in the template:
2 #
3 # $INTERFACE_     (interface for the terminalserver)
4 # $IP_            (ip for the terminalserver to bind)
5 # $NETMASK_       (network mask)
6 # $GW_            (gateway)
7 # $NAMESERVERS_   (nameservers for the nodes)
8 # $IPRANGE_FROM_  (user configured iprange, first ip)
9 # $IPRANGE_TO_    (user configured iprange, last ip)
10 # $NETWORK_       (first ip in this subnet)
11 # $OPTIONS_       (options for grml-terminalserver)
12 # $BOOT_ARGS_     (boot arguments for the nodes)
13 #
14 # NOTE:
15 # templates are shellscript fragments and will be sourced from the
16 # terminalserver
17 #
18 # GLOBAL_README_END
19
20 if grep -q live-media-path= /proc/cmdline 2>/dev/null ; then
21     live_media_path_="live-media-path=$(awk -F live-media-path= '{print $2}' /proc/cmdline)"
22 fi
23
24 # default boot arguments used for both grub and pxelinux
25 if [ -e '/live/cow' ]; then
26     default_boot_args_="root=/dev/nfs rw nfsroot=$IP_:$MOUNT_POINT_ \
27 nodhcp noprompt noeject"
28 else
29     default_boot_args_="ramdisk_size=24000 root=/dev/ram0 rw \
30 init=/etc/init nfsdir=$IP_:$MOUNT_POINT_ nodhcp noprompt noeject \
31 apm=power-off nomce"
32 fi
33
34 # special boot arguments required by grub
35 grub_def_boot_args_="/linux26 $default_boot_args_"
36
37 # special boot arguments required by pxelinux
38 pxe_def_boot_args_="$default_boot_args_"
39
40 # default arguments for framebuffer console
41 def_fb_args_="vga=791"
42 no_fb_args_="vga=normal"
43
44 ###
45 ## create grub config
46 ###
47
48 cat >"$TFTPD_DATA_DIR_/menu.lst" <<EOT
49 default=0
50 timeout=10
51 title GRML
52   root (nd)
53   kernel $grub_def_boot_args_ $def_fb_args_ $BOOT_ARGS_
54   initrd /minirt26.gz
55
56 title GRML no framebuffer
57   root (nd)
58   kernel $grub_def_boot_args_ $no_fb_args_ $BOOT_ARGS_
59
60 title GRML small
61   root (nd)
62   kernel $grub_def_boot_args_ small $def_fb_args_ $BOOT_ARGS_
63   initrd /minirt26.gz
64
65 title GRML small nofb
66   root (nd)
67   kernel $grub_def_boot_args_ small $no_fb_args_ $BOOT_ARGS_
68   initrd /minirt26.gz
69
70 title GRML debuginit
71   root (nd)
72   kernel $grub_def_boot_args_ debuginitrd $def_fb_args_ $BOOT_ARGS_
73   initrd /minirt26.gz
74
75 title GRML debuginit nofb
76   root (nd)
77   kernel $grub_def_boot_args_ debuginitrd $no_fb_args_ $BOOT_ARGS_
78   initrd /minirt26.gz
79
80 title GRML rescue
81   root (nd)
82   kernel $grub_def_boot_args_ $no_fb_args_
83   initrd /minirt26.gz
84
85 title memtest
86   root (nd)
87   kernel /memtest
88
89 title Reload config
90   configfile (nd)/menu.lst
91 EOT
92
93 ret_=$?
94
95
96 ###
97 ## create pxelinux config
98 ###
99 DEST_DIR=$(mktemp -d)
100 if [ -d /live/image/boot ] ; then
101   grml2usb --bootloader-only \
102       --bootoptions="$pxe_def_boot_args_ $BOOT_ARGS_" /live/image "$DEST_DIR"
103
104   mv "$DEST_DIR"/boot/syslinux/* "$TFTPD_DATA_DIR_/"
105   rmdir "$DEST_DIR"/boot/syslinux
106
107   mv "$DEST_DIR"/boot/ "$TFTPD_DATA_DIR_"
108 else # there is no kernel inside /live/image copy it from /boot
109   if [ ! -d /usr/share/grml-live/templates/boot/isolinux ] ; then
110     echo "E: Could not find isolinux template directory" >&2
111     exit 2
112   fi
113
114   array=( $(cat /etc/grml_version) )
115   grml_name_=${array[0]}
116   grml_version_=${array[1]}
117
118   cp /usr/share/grml-live/templates/boot/isolinux/* "$TFTPD_DATA_DIR_/"
119
120   config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
121   sed -i "s/%ARCH%/$(uname -m)/" $config_files_
122   sed -i "s/%BOOTID%/$RANDOM/" $config_files_
123   sed -i "s/%SHORT_NAME%/dummy/" $config_files_
124   sed -i "s/%VERSION%/$grml_version_/" $config_files_
125   sed -i "s/%GRML_NAME%/$grml_name_/" $config_files_
126   sed -i "s/%DISTRI_SPLASH%/grml.png/" $config_files_
127   sed -i "s/%DISTRI_INFO%/Grml/" $config_files_
128   sed -i "s#\(^.*append.*initrd.*$\)#\1 $pxe_def_boot_args_ $BOOT_ARGS_#" $config_files_
129   cat > "$TFTPD_DATA_DIR_/grmlmain.cfg"<<EOT
130   include default.cfg
131 include menuoptions.cfg
132 include grml.cfg
133 include options.cfg
134 include isoprompt.cfg
135 include hd.cfg
136 include hidden.cfg
137 EOT
138
139 fi
140
141
142 config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
143
144 # cd is multi iso, grml2usb got it right ;0
145 if [ -d "$MOUNT_POINT_"/boot/release ] ; then
146    sed -i -e 's#\(.*\)/boot/\(.*\)#\1\2#' $config_files_
147 else
148   # remove normal kernel path and use our image
149   sed -i -e 's/.*kernel.*linux26/kernel linux26/' $config_files_
150   sed -i -e 's/\(initrd\)=[[:alnum:]/._-]*/\1=minirt26.gz/' $config_files_
151
152   # only append live-media-path if needed
153   if [ ! -z "$live_media_path_" ] ; then
154     sed -i -e 's#\(live-media-path\)=[[:alnum:]/._-]*#\1='$live_media_path_'#' $config_files_
155   else
156     sed -i -e 's#live-media-path=[[:alnum:]/._-]*##' $config_files_
157   fi
158
159 fi
160 # adjust ldbsd.com bootline
161 sed -i -e 's#\(.*kernel .*/ldbsd.com\)#\1 set image /boot/addons/bsd4grml/bsd.rd`echo Type "boot" to load MirOS bsd4grml via keeppxe#' "$TFTPD_DATA_DIR_/"addon_*_bsd.cfg
162
163 # remove grub entries
164 rm -f "$TFTPD_DATA_DIR_/"addon_*grub*.cfg
165
166 mv "$TFTPD_DATA_DIR_/syslinux.cfg" "$TFTPD_DATA_DIR_/pxelinux.cfg/default"
167 rm -rf "$DEST_DIR"
168
169 let ret_=$ret_+$?
170 return $ret_