Fix bug if no kernel packages were defined but there was a postconf setting. x86...
[catalyst.git] / targets / support / bootloader-setup.sh
1 #!/bin/bash
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/bootloader-setup.sh,v 1.25 2006/01/25 16:07:35 rocket Exp $
5 . ${clst_sharedir}/targets/support/functions.sh
6 . ${clst_sharedir}/targets/support/filesystem-functions.sh
7
8 # $1 is the destination root
9
10 extract_cdtar $1
11 extract_kernels $1/boot
12 check_dev_manager
13 check_bootargs
14 check_filesystem_type
15
16 default_append_line="root=/dev/ram0 init=/linuxrc ${cmdline_opts} ${custom_kopts} cdroot"
17
18 case ${clst_mainarch} in
19         alpha)
20                 # NO SOFTLEVEL SUPPORT YET
21                 acfg=$1/etc/aboot.conf
22                 bctr=0
23                 for x in ${clst_boot_kernel}
24                 do
25                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
26                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
27                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
28                         ((bctr=${bctr}+1))
29                 done
30                 ;;
31         arm)
32                 # NO SOFTLEVEL SUPPORT YET
33                 ;;
34         hppa)
35                 # NO SOFTLEVEL SUPPORT YET
36                 icfg=$1/boot/palo.conf
37                 kmsg=$1/boot/kernels.msg
38                 hmsg=$1/boot/help.msg
39                 echo "--commandline=0/${first} initrd=${first}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts}" >> ${icfg}
40                 echo "--bootloader=boot/iplboot" >> ${icfg}
41                 echo "--ramdisk=boot/${first}.igz" >> ${icfg}
42                 ;;
43         ppc)
44                 # NO SOFTLEVEL SUPPORT YET
45                 
46                 # PPC requirements: 
47                 # -----------------
48                 # The specs indicate the kernels to be build. We need to put
49                 # those kernels and the corresponding initrd.img.gz(s) in the
50                 # /boot directory. This directory contains a message boot.msg 
51                 # containing some info to be displayed on boot, a configuration
52                 # (yaboot.conf) specifying the boot options (kernel/initrd 
53                 # combinations). The boot directory also contains a file called
54                 # yaboot, which normally gets copied from the live environment.
55                 # For now we supply a prebuilt file, prebuilt configuration 
56                 # and prebuilt boot message. This can be enhanced later on
57                 # but the following suffices for now:
58
59                 # this sets up the config file for yaboot
60
61
62                 # ADD RUNLEVEL SUPPORT ???
63
64                 icfg=$1/boot/yaboot.conf
65                 kmsg=$1/boot/boot.msg
66                 echo "default ${first}" > ${icfg}
67                 echo "timeout 300" >> ${icfg}
68                 echo "device=cd:" >> ${icfg}
69                 echo "root=/dev/ram" >> ${icfg}
70                 echo "fgcolor=white" >> ${icfg}
71                 echo "bgcolor=black" >> ${icfg}
72                 echo "message=/boot/boot.msg" >> ${icfg}
73                 for x in ${clst_boot_kernel}
74                 do      
75                         eval custom_kopts=\$${x}_kernelopts
76                         echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
77                         echo >> ${icfg}
78                         echo "image=/boot/${x}" >> ${icfg}
79
80                         if [ -e "$1/boot/${x}.igz" ]
81                         then
82                                 echo "initrd=/boot/${x}.igz" >> ${icfg}
83                         fi
84
85                         echo "label=${x}" >> ${icfg}
86                         echo "read-write" >> ${icfg}
87                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
88                         then
89                                 echo "append=\"${default_append_line} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${icfg}
90                         else
91                                 echo "append=\"${default_append_line} splash=silent\"" >> ${icfg}
92                         fi
93                 done
94                 ;;
95         sparc*)
96                 # NO SOFTLEVEL SUPPORT YET
97                 
98                 scfg=$1/boot/silo.conf
99                 echo "default=\"help\"" > ${scfg}
100                 echo "message=\"/boot/boot.msg\"" >> ${scfg}
101
102                 for x in ${clst_boot_kernel}
103                 do
104                         echo >> ${icfg}
105                         echo "image=\"/boot/${x}\"" >> ${scfg}
106                         echo -e "\tlabel=\"${x}\"" >> ${scfg}
107                         echo -e "\tappend=\"initrd=/boot/${x}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts} cdroot\"" >> ${scfg}
108
109                 done
110
111                 echo "image=\"cat /boot/silo.conf\"" >> ${scfg}
112                 echo -e "label=\"config\"" >> ${scfg}
113                 echo "image=\"cat /boot/video.msg\"" >> ${scfg}
114                 echo -e "label=\"video\"" >> ${scfg}
115                 echo "image=\"cat /boot/help.msg\"" >> ${scfg}
116                 echo -e "label=\"help\"" >> ${scfg}
117                 ;;
118         ia64)
119                 # NO SOFTLEVEL SUPPORT YET
120                 
121                 iacfg=$1/boot/elilo.conf
122                 echo 'prompt' > ${iacfg}
123                 echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
124                 echo 'chooser=simple' >> ${iacfg}
125                 echo 'timeout=50' >> ${iacfg}
126                 echo >> ${iacfg}
127                 for x in ${clst_boot_kernel}
128                 do
129                         echo "image=/efi/boot/${x}" >> ${iacfg}
130                         echo "  label=${x}" >> ${iacfg}
131                         echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
132                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
133                         echo >> ${iacfg}
134                         echo "image=/efi/boot/${x}" >> ${iacfg}
135                         echo "  label=${x}-serial">> ${iacfg}
136                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS0,9600"' >> ${iacfg}
137                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
138                         echo >> ${iacfg}
139                 done
140                 cp ${iacfg} $1/boot/efi/boot
141                 mv $1/boot/${x}{,.igz} $1/boot/efi/boot
142                 ;;
143         x86|amd64)
144                 if [ -e $1/isolinux/isolinux.bin ]
145                 then
146                         mv $1/boot/* $1/isolinux
147                         rmdir $1/boot
148                         # the rest of this function sets up the config file for isolinux
149                         icfg=$1/isolinux/isolinux.cfg
150                         kmsg=$1/isolinux/kernels.msg
151                         echo "default ${first}" > ${icfg}
152                         echo "timeout 150" >> ${icfg}
153                         echo "prompt 1" >> ${icfg}
154                         echo "display boot.msg" >> ${icfg}
155                         echo "F1 kernels.msg" >> ${icfg}
156                         echo "F2 F2.msg" >> ${icfg}
157                         echo "F3 F3.msg" >> ${icfg}
158                         echo "F4 F4.msg" >> ${icfg}
159                         echo "F5 F5.msg" >> ${icfg}
160                         echo "F6 F6.msg" >> ${icfg}
161                         echo "F7 F7.msg" >> ${icfg}
162
163                         echo "Available kernels:" > ${kmsg}
164                         for i in 2 3 4 5 6 7
165                         do
166                                 cp ${clst_sharedir}/livecd/files/x86-F$i.msg \
167                                         $1/isolinux/F$i.msg
168                         done
169
170                         for x in ${clst_boot_kernel}
171                         do
172                                 eval custom_kopts=\$${x}_kernelopts
173                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
174                                 echo >> ${icfg}
175                                 
176                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
177
178                                 if [ -n "${clst_kernel_softlevel}" ]
179                                 then
180                                         for y in ${clst_kernel_softlevel}
181                                         do
182                                                 echo "label ${x}-${y}" >> ${icfg}
183                                                 echo "  kernel ${x}" >> ${icfg}
184                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
185                                                 then
186                                                         echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
187                                                 else
188                                                         echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
189                                                 fi
190
191                                                 echo >> ${icfg}
192                                                 echo "   ${x}" >> ${kmsg}
193                                                 echo "label ${x}-${y}-nofb" >> ${icfg}
194                                                 echo "  kernel ${x}" >> ${icfg}
195                                                 echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz" >> ${icfg}
196                                                 echo >> ${icfg}
197                                                 echo "   ${x}-nofb" >> ${kmsg}
198                                         done
199                                 else
200                                         echo "label ${x}" >> ${icfg}
201                                         echo "  kernel ${x}" >> ${icfg}
202                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
203                                         then
204                                                 echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
205                                         else
206                                                 echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
207                                         fi
208
209                                         echo >> ${icfg}
210                                         echo "   ${x}" >> ${kmsg}
211                                         echo "label ${x}-nofb" >> ${icfg}
212                                         echo "  kernel ${x}" >> ${icfg}
213                                         echo "  append ${default_append_line} initrd=${x}.igz" >> ${icfg}
214                                         echo >> ${icfg}
215                                         echo "   ${x}-nofb" >> ${kmsg}
216                                 fi
217                         done
218
219                         if [ -f $1/isolinux/memtest86 ]
220                         then
221                                 echo >> $icfg
222                                 echo "   memtest86" >> $kmsg
223                                 echo "label memtest86" >> $icfg
224                                 echo "  kernel memtest86" >> $icfg
225                         fi
226                 fi
227
228                 if [ -e $1/boot/grub/stage2_eltorito ]
229                 then
230                         icfg=$1/boot/grub/grub.conf
231                         echo "default 1" > ${icfg}
232                         echo "timeout 150" >> ${icfg}
233
234                         # Setup help message
235                         echo >> ${icfg}
236                         echo "title help" >> ${icfg}
237                         cp ${clst_sharedir}/livecd/files/README.txt \
238                                 $1/boot/help.msg
239                         echo "cat /boot/help.msg" >> ${icfg}
240
241                         for x in ${clst_boot_kernel}
242                         do
243                                 eval custom_kopts=\$${x}_kernelopts
244                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
245                                 echo >> ${icfg}
246                                 
247                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
248                                 
249                                 if [ -n "${clst_kernel_softlevel}" ]
250                                 then
251                                         for y in ${clst_kernel_softlevel}
252                                         do
253                                                 echo "title ${x}-${y}" >> ${icfg}
254                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
255                                                 then
256                                                         echo "kernel /boot/${x} softlevel=${y} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
257                                                 else
258                                                         echo "kernel /boot/${x} softlevel=${y} ${default_append_line} vga=791 splash=silent" >> ${icfg}
259                                                 fi
260                                                 if [ -e $1/boot/${x}.igz ]
261                                                 then
262                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
263                                                 fi
264                                                 echo >> ${icfg}
265                                                 echo "title ${x}-${y} [ No FrameBuffer ]" >> ${icfg}
266                                                 echo "kernel ${x} /boot/${x} softlevel=${y} ${default_append_line}" >> ${icfg}
267                                                 if [ -e $1/boot/${x}.igz ]
268                                                 then
269                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
270                                                 fi
271                                                 echo >> ${icfg}
272                                         done
273                                 else
274                                         echo "title ${x}" >> ${icfg}
275                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
276                                         then
277                                                 echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
278                                         else
279                                                 echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent" >> ${icfg}
280                                         fi
281                                         if [ -e $1/boot/${x}.igz ]
282                                         then
283                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
284                                         fi
285                                         echo >> ${icfg}
286                                         echo "title ${x} [ No FrameBuffer ]" >> ${icfg}
287                                         echo "kernel ${x} /boot/${x} ${default_append_line}" >> ${icfg}
288                                         if [ -e $1/boot/${x}.igz ]
289                                         then
290                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
291                                         fi
292                                 fi
293
294                         done
295
296                         if [ -f $1/boot/memtest86 ]
297                         then
298                                 echo >> ${icfg}
299                                 echo "title memtest86" >> ${icfg}
300                                 echo "kernel /boot/memtest86" >> ${icfg}
301                         fi
302                 fi
303                 ;;
304         mips)
305
306                 # NO SOFTLEVEL SUPPORT YET
307
308
309                 # Mips is an interesting arch -- where most archs will
310                 # use ${1} as the root of the LiveCD, an SGI LiveCD lacks
311                 # such a root.  Instead, we will use ${1} as a scratch
312                 # directory to build the components we need for the
313                 # CD image, and then pass these components to the
314                 # `sgibootcd` tool which outputs a final CD image
315                 scratch="${1}"
316                 mkdir ${scratch}/kernels
317                 mkdir ${scratch}/kernels/misc
318                 mkdir ${scratch}/arcload
319                 echo "" > ${scratch}/arc.cf
320
321                 # Move kernel binaries to ${scratch}/kernels, and
322                 # move everything else to ${scratch}/kernels/misc
323                 for x in ${clst_boot_kernel}; do
324                         mv ${1}/boot/${x} ${scratch}/kernels
325                         mv ${1}/boot/${x}.igz ${scratch}/kernels/misc
326                 done
327                 rmdir ${1}/boot
328
329                 # Source the bashified arcload config
330                 source ${clst_sharedir}/targets/support/mips-arcload_conf.sh
331
332                 # Generate top portions of the config
333                 echo -e "${topofconfig}${serial}${dbg}${cmt1}" >> ${scratch}/arc.cf
334
335                 # Next, figure out what kernels were specified in the
336                 # spec file, and generate the appropriate arcload conf
337                 # blocks specific to each system
338                 ip22="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip22" | tr "\n" " ")"
339                 ip27="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip27" | tr "\n" " ")"
340                 ip28="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip28" | tr "\n" " ")"
341                 ip30="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip30" | tr "\n" " ")"
342                 ip32="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip32" | tr "\n" " ")"
343
344                 if [ -n "${ip22}" ]; then
345                         echo -e "${ip22base}" >> ${scratch}/arc.cf
346                         for x in ${ip22}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
347                         echo -e "${ip22vid}${ip22x}" >> ${scratch}/arc.cf
348                 fi
349
350                 [ -n "${ip27}" ] && echo -e "${ip27base}" >> ${scratch}/arc.cf
351                 [ -n "${ip28}" ] && echo -e "${ip28base}" >> ${scratch}/arc.cf
352                 [ -n "${ip30}" ] && echo -e "${ip30base}" >> ${scratch}/arc.cf
353
354                 if [ -n "${ip32}" ]; then
355                         echo -e "${ip32base}" >> ${scratch}/arc.cf
356                         for x in ${ip32}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
357                         echo -e "${ip32vid}${ip32x}" >> ${scratch}/arc.cf
358                 fi
359
360                 # Finish off the config
361                 echo -e "${cmt2}" >> ${scratch}/arc.cf
362
363                 # Move the bootloader binaries & config to their destination
364                 mv ${1}/sashARCS ${1}/sash64 ${1}/arc.cf ${scratch}/arcload
365                 ;;
366 esac
367 exit $?