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