076e63999c2b71acf893584a0d688abd78215c25
[catalyst.git] / livecd / runscript-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 # $Header: /var/cvsroot/gentoo/src/catalyst/livecd/runscript-support/Attic/kmerge.sh,v 1.17 2004/10/21 17:06:21 wolf31o2 Exp $
5
6 die() {
7         echo "$1"
8         exit 1
9 }
10
11 build_kernel() {
12         # default genkernel args
13         GK_ARGS="${clst_livecd_gk_mainargs} \
14                          ${clst_livecd_gk_kernargs} \
15                          --kerneldir=/usr/src/linux \
16                          --do-keymap-auto \
17                          --kernel-config=/var/tmp/${clst_kname}.config \
18                          --minkernpackage=/usr/portage/packages/gk_binaries/${clst_kname}-${clst_version_stamp}.tar.bz2 all"
19         
20         # extra genkernel options that we have to test for
21         if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n "${clst_livecd_splash_theme}" ]
22         then
23                 GK_ARGS="${GK_ARGS} --bootsplash=${clst_livecd_splash_theme}"
24         fi
25         
26         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
27         then
28                 GK_ARGS="${GK_ARGS} --gensplash=${clst_livecd_splash_theme}"
29         fi
30         
31         if [  -e "/var/tmp/${clst_kname}.postconf" ]
32         then
33                 for x in $( cat /var/tmp/${clst_kname}.postconf )
34                 do
35                         clst_kernel_postconf="${clst_kernel_postconf} ${x}"
36                 done
37                 GK_ARGS="${GK_ARGS} --postconf=\"${clst_kernel_postconf}\""
38         fi
39
40         if [ -e "/var/tmp/${clst_kname}.packages" ]
41         then
42                 for x in $( cat /var/tmp/${clst_kname}.packages )
43                 do
44                         # we don't want to use the pkgcache for these since the results
45                         # are kernel-dependent.
46                         clst_kernel_merge="${clst_kernel_merge} ${x}"
47                 done
48                 GK_ARGS="${GK_ARGS} --callback=\"${clst_kernel_merge}\""
49         fi
50         
51         if [ "${clst_livecd_devmanager}" == "udev" ]
52         then
53                 GK_ARGS="${GK_ARGS} --udev"
54         fi
55         
56         # build with genkernel using the set options
57         # callback is put here to avoid escaping issues
58         genkernel ${GK_ARGS} || exit 1
59         
60         # pack up the modules for resuming
61         if [ -n "${clst_KERNCACHE}" ]
62         then
63                 tar cjpf /usr/portage/packages/gk_binaries/${1}-modules-${clst_version_stamp}.tar.bz2 \
64                         /lib/modules/"${1}" || die "Could not package kernel modules, exiting"
65         fi
66
67 }
68
69 # Script to build each kernel, kernel-related packages
70 /usr/sbin/env-update
71 source /etc/profile
72
73 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
74 export CONFIG_PROTECT="-*"
75 rm -f /usr/src/linux
76
77 #set the timezone for the kernel build
78 rm /etc/localtime
79 ln -s /usr/share/zoneinfo/UTC /etc/localtime
80
81 [ -e "/var/tmp/${clst_kname}.use" ] && export USE="$( cat /var/tmp/${clst_kname}.use )" || unset USE
82 [ -e "/var/tmp/${clst_kname}.gk_kernargs" ] && source /var/tmp/${clst_kname}.gk_kernargs
83
84 # Don't use pkgcache here, as the kernel source may get emerge with different USE variables
85 # (and thus different patches enabled/disabled.) Also, there's no real benefit in using the
86 # pkgcache for kernel source ebuilds.
87 emerge "${clst_ksource}" || exit 1
88 [ ! -e /usr/src/linux ] && die "Can't find required directory /usr/src/linux"
89         
90 #if catalyst has set NULL_VALUE, extraversion wasn't specified so we skip this part
91 if [ "${clst_kextversion}" != "NULL_VALUE" ]
92 then
93         sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextversion}:" /usr/src/linux/Makefile
94 fi
95         
96 if [ -n "${clst_CCACHE}" ]
97 then
98         #enable ccache for genkernel
99         export PATH="/usr/lib/ccache/bin:${PATH}"
100 fi
101
102 # grep out the kernel version so that we can do our modules magic
103 VER=`grep ^VERSION\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
104 PAT=`grep ^PATCHLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
105 SUB=`grep ^SUBLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
106 EXV=`grep ^EXTRAVERSION\ \= /usr/src/linux/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g"`
107 clst_fudgeuname=${VER}.${PAT}.${SUB}${EXV}
108
109 # kernel building happens here
110 # does the old config exist? if it does not, we build by default
111 if [ -e "/usr/portage/packages/gk_binaries/${clst_kname}-${clst_version_stamp}.config" ]
112 then
113         # test to see if the kernel .configs are the same, if so, then we skip kernel building
114         test1=$(md5sum /var/tmp/${clst_kname}.config | cut -d " " -f 1)
115         test2=$(md5sum /usr/portage/packages/gk_binaries/${clst_kname}-${clst_version_stamp}.config | cut -d " " -f 1)
116         if [ "${test1}" == "${test2}" -a -n "${clst_KERNCACHE}" ]
117         then
118                 echo
119                 echo "No kernel configuration change, skipping kernel build..."
120                 echo
121                 sleep 5
122
123                 # unpack our modules to the LiveCD fs
124                 echo
125                 echo "Unpacking kernel modules from the previous build..."
126                 echo
127                 [ ! -d /lib/modules ] && mkdir /lib/modules
128                 tar xjpf /usr/portage/packages/gk_binaries/${clst_fudgeuname}-modules-${clst_version_stamp}.tar.bz2 \
129                         -C / || die "Could not unpack kernel modules"
130         else
131                 build_kernel ${clst_fudgeuname}
132         fi
133
134 else
135         build_kernel ${clst_fudgeuname}
136         
137 fi
138
139 /sbin/modules-update --assume-kernel=${clst_fudgeuname}
140                 
141 #now the unmerge... (wipe db entry)
142 emerge -C ${clst_ksource}
143 unset USE
144
145 # keep the config around so that we can resume at some point
146 [ -n "${clst_KERNCACHE}" ] && cp /var/tmp/${clst_kname}.config /usr/portage/packages/gk_binaries/${clst_kname}-${clst_version_stamp}.config