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