Add support for gk's --busybox-config= option
[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 [ -n "${clst_busybox_config}" ]
59         then
60                 GK_ARGS="${GK_ARGS} --busybox-config=/tmp/busy-config"
61         fi
62
63         if [ "${clst_target}" == "netboot2" ]
64         then
65                 GK_ARGS="${GK_ARGS} --netboot"
66
67                 if [ -n "${clst_merge_path}" ]
68                 then
69                         GK_ARGS="${GK_ARGS} --initramfs-overlay=\"${clst_merge_path}\""
70                 fi
71         fi
72 }
73
74 genkernel_compile(){
75         eval "clst_initramfs_overlay=\$clst_boot_kernel_${filtered_kname}_initramfs_overlay"
76         eval "clst_kernel_merge=\$clst_boot_kernel_${filtered_kname}_packages"
77
78         setup_gk_args
79         #echo "The GK_ARGS are"
80         #echo ${GK_ARGS}        
81         export clst_kernel_merge
82         export clst_initramfs_overlay
83         # Build our list of kernel packages
84         case ${clst_livecd_type} in
85                 gentoo-release-live*)
86                         if [ -n "${clst_kernel_merge}" ]
87                         then
88                                 mkdir -p /usr/livecd
89                                 echo "${clst_kernel_merge}" > /usr/livecd/kernelpkgs.txt
90                         fi
91                 ;;
92         esac
93         # Build with genkernel using the set options
94         # callback is put here to avoid escaping issues
95         gk_callback_opts="-qN"
96         PKGDIR=${PKGDIR}
97         if [ -n "${clst_KERNCACHE}" ]
98         then
99                 gk_callback_opts="${gk_callback_opts} -kb"
100         fi
101         if [ -n "${clst_FETCH}" ]
102         then
103                 gk_callback_opts="${gk_callback_opts} -f"
104         fi
105         if [ "${clst_kernel_merge}" != "" ]
106         then
107                 genkernel --callback="emerge ${gk_callback_opts} ${clst_kernel_merge}" \
108                         ${GK_ARGS} || exit 1
109         else
110                 genkernel ${GK_ARGS} || exit 1
111         fi
112         md5sum /var/tmp/${clst_kname}.config | awk '{print $1}' > \
113                 /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG
114 }
115
116 build_kernel() {
117         genkernel_compile
118 }
119
120 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
121 export CONFIG_PROTECT="-*"
122
123 # Set the timezone for the kernel build
124 rm /etc/localtime
125 cp -f /usr/share/zoneinfo/UTC /etc/localtime
126
127 filtered_kname=${clst_kname/-/_}
128 filtered_kname=${clst_kname/\//_}
129 filtered_kname=${filtered_kname/\./_}
130
131 eval "clst_kernel_use=\$clst_boot_kernel_${filtered_kname}_use"
132 eval "clst_kernel_gk_kernargs=\$clst_boot_kernel_${filtered_kname}_gk_kernargs"
133 eval "clst_ksource=\$clst_boot_kernel_${filtered_kname}_sources"
134
135 if [ -z "${clst_ksource}" ]
136 then
137         clst_ksource="virtual/linux-sources"
138 fi
139
140 # Don't use pkgcache here, as the kernel source may get emerged with different
141 # USE variables (and thus different patches enabled/disabled.) Also, there's no
142 # real benefit in using the pkgcache for kernel source ebuilds.
143
144 USE_MATCH=0 
145 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE ]
146 then
147         STR1=$(for i in `cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE`; do echo $i; done|sort)
148         STR2=$(for i in ${clst_kernel_use}; do echo $i; done|sort)
149         if [ "${STR1}" = "${STR2}" ]
150         then 
151                 #echo "USE Flags match"
152                 USE_MATCH=1 
153         else
154                 if [ -n "${clst_KERNCACHE}" ]
155                 then
156                 [ -d /tmp/kerncache/${clst_kname}/ebuilds ] && \
157                         rm -r /tmp/kerncache/${clst_kname}/ebuilds
158                 [ -e /tmp/kerncache/${clst_kname}/usr/src/linux/.config ] && \
159                         rm /tmp/kerncache/${clst_kname}/usr/src/linux/.config
160                 fi
161         fi
162 fi
163
164 EXTRAVERSION_MATCH=0
165 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION ]
166 then
167         STR1=`cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION`
168         STR2=${clst_kextraversion}
169         if [ "${STR1}" = "${STR2}" ]
170         then 
171                 if [ -n "${clst_KERNCACHE}" ]
172                 then
173                         #echo "EXTRAVERSION match"
174                         EXTRAVERSION_MATCH=1
175                 fi
176         fi
177 fi
178
179 CONFIG_MATCH=0
180 if [ -e /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG ]
181 then
182         STR1=`cat /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG`
183         STR2=`md5sum /var/tmp/${clst_kname}.config|awk '{print $1}'`
184         if [ "${STR1}" = "${STR2}" ]
185         then 
186                 if [ -n "${clst_KERNCACHE}" ]
187                 then
188                         #echo "CONFIG match"
189                         CONFIG_MATCH=1
190                 fi
191         fi
192 fi
193
194 [ -e /etc/make.conf ] && \
195         echo "USE=\"\${USE} ${clst_kernel_use} build\"" >> /etc/make.conf
196
197 if [ -n "${clst_KERNCACHE}" ]
198 then
199         mkdir -p /tmp/kerncache/${clst_kname}
200         clst_root_path=/tmp/kerncache/${clst_kname} PKGDIR=${PKGDIR} clst_myemergeopts="--quiet --nodeps --update --newuse" run_merge "${clst_ksource}" || exit 1
201         KERNELVERSION=`portageq best_visible / "${clst_ksource}"`
202         if [ ! -e /etc/portage/profile/package.provided ]
203         then
204                 mkdir -p /etc/portage/profile
205                 echo "${KERNELVERSION}" > /etc/portage/profile/package.provided
206         else
207                 if ( ! grep -q "^${KERNELVERSION}\$"  /etc/portage/profile/package.provided ) 
208                 then
209                         echo "${KERNELVERSION}" >> /etc/portage/profile/package.provided
210                 fi
211         fi
212         [ -L /usr/src/linux ] && rm -f /usr/src/linux
213         ln -s /tmp/kerncache/${clst_kname}/usr/src/linux /usr/src/linux
214 else
215         [ -L /usr/src/linux ] && rm -f /usr/src/linux
216         run_merge "${clst_ksource}" || exit 1
217 fi
218 make_destpath
219
220 # If catalyst has set to a empty string, extraversion wasn't specified so we
221 # skip this part
222 if [ "${EXTRAVERSION_MATCH}" = "0" ]
223 then
224         if [ ! "${clst_kextraversion}" = "" ]
225         then
226                 echo "Setting extraversion to ${clst_kextraversion}"
227                 sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" /usr/src/linux/Makefile
228                 echo ${clst_kextraversion} > /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
229         else 
230                 touch /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
231         fi
232 fi
233
234 build_kernel
235 sed -i "/USE=\"\${USE} ${clst_kernel_use} build\"/d" /etc/make.conf
236 # grep out the kernel version so that we can do our modules magic
237 VER=`grep ^VERSION\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
238 PAT=`grep ^PATCHLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
239 SUB=`grep ^SUBLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
240 EXV=`grep ^EXTRAVERSION\ \= /usr/src/linux/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g"`
241 clst_fudgeuname=${VER}.${PAT}.${SUB}${EXV}
242
243 /sbin/update-modules --assume-kernel=${clst_fudgeuname}
244
245 unset USE
246 echo ${clst_kernel_use} > /tmp/kerncache/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE
247
248
249 if [ -n "${clst_KERNCACHE}" ]
250 then
251         if [ -e /etc/portage/profile/package.provided ]
252         then
253                 sed -i "/^$(echo "${KERNELVERSION}" | sed -e 's|/|\\/|g')\$/d" /etc/portage/profile/package.provided
254         fi
255 fi