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