Automatically append --netboot to GK_ARGS for netboot2 target
[catalyst.git] / targets / support / kmerge.sh
1 #!/bin/bash
2
3 source /tmp/chroot-functions.sh
4
5 check_genkernel_version
6
7 install -d /tmp/kerncache
8 PKGDIR=/tmp/kerncache/${clst_kname}/ebuilds
9
10 setup_gk_args() {
11         # default genkernel args
12         GK_ARGS="${clst_gk_mainargs} \
13                          ${clst_kernel_gk_kernargs} \
14                          --cachedir=/tmp/kerncache/${clst_kname}-genkernel_cache-${clst_version_stamp} \
15                          --no-mountboot \
16                          --kerneldir=/usr/src/linux \
17                          --modulespackage=/tmp/kerncache/${clst_kname}-modules-${clst_version_stamp}.tar.bz2 \
18                          --minkernpackage=/tmp/kerncache/${clst_kname}-kernel-initrd-${clst_version_stamp}.tar.bz2 all"
19         # extra genkernel options that we have to test for
20         if [ -n "${clst_KERNCACHE}" ]
21         then
22                 GK_ARGS="${GK_ARGS} --kerncache=/tmp/kerncache/${clst_kname}-kerncache-${clst_version_stamp}.tar.bz2"
23         fi
24         if [ -e /var/tmp/${clst_kname}.config ]
25         then
26                 GK_ARGS="${GK_ARGS} --kernel-config=/var/tmp/${clst_kname}.config"
27         fi
28
29         if [ -n "${clst_splash_theme}" ]
30         then
31                 GK_ARGS="${GK_ARGS} --splash=${clst_splash_theme}"
32                 # Setup case structure for livecd_type
33                 case ${clst_livecd_type} in
34                         gentoo-release-minimal|gentoo-release-universal)
35                                 case ${clst_hostarch} in
36                                         amd64|x86)
37                                                 GK_ARGS="${GK_ARGS} --splash-res=1024x768"
38                                         ;;
39                                 esac
40                         ;;
41                 esac
42         fi
43
44         if [ -d "/tmp/initramfs_overlay/${clst_initramfs_overlay}" ]
45         then
46                 GK_ARGS="${GK_ARGS} --initramfs-overlay=/tmp/initramfs_overlay/${clst_initramfs_overlay}"
47         fi
48         if [ -n "${clst_CCACHE}" ]
49         then
50                 GK_ARGS="${GK_ARGS} --kernel-cc=/usr/lib/ccache/bin/gcc --utils-cc=/usr/lib/ccache/bin/gcc"
51         fi
52         
53         if [ -n "${clst_linuxrc}" ]
54         then
55                 GK_ARGS="${GK_ARGS} --linuxrc=/tmp/linuxrc"
56         fi
57
58     if [ "${clst_target}" == "netboot2" ]
59     then
60                 GK_ARGS="${GK_ARGS} --netboot"
61
62                 if [ -n "${clst_merge_path}" ]
63                 then
64                 GK_ARGS="${GK_ARGS} --initramfs-overlay=\"${clst_merge_path}\""
65                 fi
66     fi
67 }
68
69 genkernel_compile(){
70         eval "clst_initramfs_overlay=\$clst_boot_kernel_${filtered_kname}_initramfs_overlay"
71         eval "clst_kernel_merge=\$clst_boot_kernel_${filtered_kname}_packages"
72
73         setup_gk_args
74         #echo "The GK_ARGS are"
75         #echo ${GK_ARGS}        
76         export clst_kernel_merge
77         export clst_initramfs_overlay
78         # Build our list of kernel packages
79         case ${clst_livecd_type} in
80                 gentoo-release-live*)
81                         if [ -n "${clst_kernel_merge}" ]
82                         then
83                                 mkdir -p /usr/livecd
84                                 echo "${clst_kernel_merge}" > /usr/livecd/kernelpkgs.txt
85                         fi
86                 ;;
87         esac
88         # Build with genkernel using the set options
89         # callback is put here to avoid escaping issues
90         gk_callback_opts="-qN"
91         PKGDIR=${PKGDIR}
92         if [ -n "${clst_KERNCACHE}" ]
93         then
94                 gk_callback_opts="${gk_callback_opts} -kb"
95         fi
96         if [ -n "${clst_FETCH}" ]
97         then
98                 gk_callback_opts="${gk_callback_opts} -f"
99         fi
100         if [ "${clst_kernel_merge}" != "" ]
101         then
102                 genkernel --callback="emerge ${gk_callback_opts} ${clst_kernel_merge}" \
103                         ${GK_ARGS} || exit 1
104         else
105                 genkernel ${GK_ARGS} || exit 1
106         fi
107         md5sum /var/tmp/${clst_kname}.config | awk '{print $1}' > \
108                 /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG
109 }
110
111 build_kernel() {
112         genkernel_compile
113 }
114
115 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
116 export CONFIG_PROTECT="-*"
117
118 # Set the timezone for the kernel build
119 rm /etc/localtime
120 cp -f /usr/share/zoneinfo/UTC /etc/localtime
121
122 filtered_kname=${clst_kname/-/_}
123 filtered_kname=${clst_kname/\//_}
124 filtered_kname=${filtered_kname/\./_}
125
126 eval "clst_kernel_use=\$clst_boot_kernel_${filtered_kname}_use"
127 eval "clst_kernel_gk_kernargs=\$clst_boot_kernel_${filtered_kname}_gk_kernargs"
128 eval "clst_ksource=\$clst_boot_kernel_${filtered_kname}_sources"
129
130 if [ -z "${clst_ksource}" ]
131 then
132         clst_ksource="virtual/linux-sources"
133 fi
134
135 # Don't use pkgcache here, as the kernel source may get emerged with different
136 # USE variables (and thus different patches enabled/disabled.) Also, there's no
137 # real benefit in using the pkgcache for kernel source ebuilds.
138
139 USE_MATCH=0 
140 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE ]
141 then
142         STR1=$(for i in `cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE`; do echo $i; done|sort)
143         STR2=$(for i in ${clst_kernel_use}; do echo $i; done|sort)
144         if [ "${STR1}" = "${STR2}" ]
145         then 
146                 #echo "USE Flags match"
147                 USE_MATCH=1 
148         else
149                 if [ -n "${clst_KERNCACHE}" ]
150                 then
151                 [ -d /tmp/kerncache/${clst_kname}/ebuilds ] && \
152                         rm -r /tmp/kerncache/${clst_kname}/ebuilds
153                 [ -e /tmp/kerncache/${clst_kname}/usr/src/linux/.config ] && \
154                         rm /tmp/kerncache/${clst_kname}/usr/src/linux/.config
155                 fi
156         fi
157 fi
158
159 EXTRAVERSION_MATCH=0
160 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION ]
161 then
162         STR1=`cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION`
163         STR2=${clst_kextraversion}
164         if [ "${STR1}" = "${STR2}" ]
165         then 
166                 if [ -n "${clst_KERNCACHE}" ]
167                 then
168                         #echo "EXTRAVERSION match"
169                         EXTRAVERSION_MATCH=1
170                 fi
171         fi
172 fi
173
174 CONFIG_MATCH=0
175 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG ]
176 then
177         STR1=`cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG`
178         STR2=`md5sum /var/tmp/${clst_kname}.config|awk '{print $1}'`
179         if [ "${STR1}" = "${STR2}" ]
180         then 
181                 if [ -n "${clst_KERNCACHE}" ]
182                 then
183                         #echo "CONFIG match"
184                         CONFIG_MATCH=1
185                 fi
186         fi
187 fi
188
189 [ -e /etc/make.conf ] && \
190         echo "USE=\"\${USE} ${clst_kernel_use} build\"" >> /etc/make.conf
191
192 if [ -n "${clst_KERNCACHE}" ]
193 then
194         mkdir -p /tmp/kerncache/${clst_kname}
195         clst_root_path=/tmp/kerncache/${clst_kname} PKGDIR=${PKGDIR} clst_myemergeopts="--quiet --nodeps --update --newuse" run_merge "${clst_ksource}" || exit 1
196         KERNELVERSION=`portageq best_visible / "${clst_ksource}"`
197         if [ ! -e /etc/portage/profile/package.provided ]
198         then
199                 mkdir -p /etc/portage/profile
200                 echo "${KERNELVERSION}" > /etc/portage/profile/package.provided
201         else
202                 if ( ! grep -q "^${KERNELVERSION}\$"  /etc/portage/profile/package.provided ) 
203                 then
204                         echo "${KERNELVERSION}" >> /etc/portage/profile/package.provided
205                 fi
206         fi
207         [ -L /usr/src/linux ] && rm -f /usr/src/linux
208         ln -s /tmp/kerncache/${clst_kname}/usr/src/linux /usr/src/linux
209 else
210         [ -L /usr/src/linux ] && rm -f /usr/src/linux
211         run_merge "${clst_ksource}" || exit 1
212 fi
213 make_destpath
214
215 # If catalyst has set to a empty string, extraversion wasn't specified so we
216 # skip this part
217 if [ "${EXTRAVERSION_MATCH}" = "0" ]
218 then
219         if [ ! "${clst_kextraversion}" = "" ]
220         then
221                 echo "Setting extraversion to ${clst_kextraversion}"
222                 sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" /usr/src/linux/Makefile
223                 echo ${clst_kextraversion} > /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
224         else 
225                 touch /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
226         fi
227 fi
228
229 build_kernel
230 sed -i "/USE=\"\${USE} ${clst_kernel_use} build\"/d" /etc/make.conf
231 # grep out the kernel version so that we can do our modules magic
232 VER=`grep ^VERSION\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
233 PAT=`grep ^PATCHLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
234 SUB=`grep ^SUBLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
235 EXV=`grep ^EXTRAVERSION\ \= /usr/src/linux/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g"`
236 clst_fudgeuname=${VER}.${PAT}.${SUB}${EXV}
237
238 /sbin/update-modules --assume-kernel=${clst_fudgeuname}
239
240 unset USE
241 echo ${clst_kernel_use} > /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE
242
243
244 if [ -n "${clst_KERNCACHE}" ]
245 then
246         if [ -e /etc/portage/profile/package.provided ]
247         then
248                 sed -i "/^$(echo "${KERNELVERSION}" | sed -e 's|/|\\/|g')\$/d" /etc/portage/profile/package.provided
249         fi
250 fi