Added a patch from Joshua Kinard <kumba@gentoo.org> to clean up the Pegasos hacks...
[genkernel.git] / gen_package.sh
1 #!/bin/bash
2
3 gen_minkernpackage()
4 {
5         print_info 1 'Creating minimal kernel package'
6         rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1
7         mkdir "${TEMP}/minkernpackage" || gen_die 'Could not make a directory for the kernel package!'
8         if [ "${CMD_KERNCACHE}" != "" ]
9         then
10                 /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} kernel-${ARCH}-${KV}
11                 /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} config-${ARCH}-${KV}
12                 if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
13                 then
14                         /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} kernelz-${ARCH}-${KV}
15                 fi
16         else
17                 cd "${KERNEL_DIR}"
18                 cp "${KERNEL_BINARY}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!'
19                 cp ".config" "${TEMP}/minkernpackage/config-${ARCH}-${KV}" || gen_die 'Could not the copy kernel config for the min kernel package!'
20                 if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
21                 then
22                         cp "${KERNEL_BINARY_2}" "${TEMP}/minkernpackage/kernelz-${KV}" || gen_die "Could not copy the kernelz for the min kernel package"
23                 fi
24         fi
25         
26         if [ "${ENABLE_PEGASOS_HACKS}" != 'yes' ]
27         then
28                 if [ "${KERN_24}" != '1' ]
29                 then
30                         [ "${BUILD_INITRD}" -ne 0 ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; }
31                 else
32                         [ "${BUILD_INITRD}" -ne 0 ] && { cp "${TMPDIR}/initrd-${KV}" "${TEMP}/minkernpackage/initrd-${ARCH}-${KV}" || gen_die 'Could not copy the initrd for the kernel package!'; }
33                 fi
34         fi
35
36         if [ "${CMD_KERNCACHE}" != "" ]
37         then
38                 /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} System.map-${ARCH}-${KV}
39         else
40                 cp "${KERNEL_DIR}/System.map" "${TEMP}/minkernpackage/System.map-${ARCH}-${KV}" || gen_die 'Could not copy System.map for the kernel package!';
41         fi
42         
43         cd "${TEMP}/minkernpackage" 
44         /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!'
45         cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1
46 }
47 gen_modulespackage()
48 {
49         print_info 1 'Creating modules package'
50         rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1
51         mkdir "${TEMP}/modulespackage" || gen_die 'Could not make a directory for the kernel package!'
52
53         if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ]
54         then
55             mkdir -p ${TEMP}/modulespackage/lib/modules
56             cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/modulespackage/lib/modules"
57             cd "${TEMP}/modulespackage" 
58             /bin/tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!'
59         else
60             print_info 1 "Could not create a modules package ${INSTALL_MOD_PATH}/lib/modules/${KV} was not found"
61         fi
62         cd "${TEMP}" && rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1
63 }
64 gen_kerncache()
65 {
66         print_info 1 'Creating kernel cache'
67         rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
68         mkdir "${TEMP}/kerncache" || gen_die 'Could not make a directory for the kernel cache!'
69         cd "${KERNEL_DIR}"
70         cp "${KERNEL_BINARY}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!'
71         cp "${KERNEL_DIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}"
72         cp "${KERNEL_DIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}"
73         if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
74         then
75                 cp "${KERNEL_BINARY_2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package"
76         fi
77         
78         echo "VERSION = ${VER}" > "${TEMP}/kerncache/kerncache.config"
79         echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config"
80         echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config"
81         echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config"
82         
83         mkdir -p "${TEMP}/kerncache/lib/modules/"
84         
85         if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ]
86         then
87             cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/kerncache/lib/modules"
88         fi
89         
90         cd "${TEMP}/kerncache" 
91         /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!'
92         cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
93 }
94
95 gen_kerncache_extract_kernel()
96 {
97         /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
98         copy_image_with_preserve "kernel" \
99                 "${TEMP}/kernel-${ARCH}-${KV}" \
100                 "kernel-${KNAME}-${ARCH}-${KV}"
101
102         if [ "${ENABLE_PEGASOS_HACKS}" = 'yes']
103         then
104                 copy_image_with_preserve "kernelz" \
105                         "${TEMP}/kernelz-${ARCH}-${KV}" \
106                         "kernelz-${KNAME}-${ARCH}-${KV}"
107         fi
108     
109         copy_image_with_preserve "System.map" \
110                 "${TEMP}/System.map-${ARCH}-${KV}" \
111                 "System.map-${KNAME}-${ARCH}-${KV}"
112 }
113
114 gen_kerncache_extract_modules()
115 {
116         if [ -e "${KERNCACHE}" ] 
117         then
118                 print_info 1 'Extracting kerncache kernel modules'
119                 if [ "${INSTALL_MOD_PATH}" != '' ]
120                 then
121                         /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib
122                 else
123                         /bin/tar -xjf ${KERNCACHE} -C / lib
124                 fi
125         fi
126 }
127
128 gen_kerncache_extract_config()
129 {
130         if [ -e "${KERNCACHE}" ] 
131         then
132                 print_info 1 'Extracting kerncache config to /etc/kernels'
133                 mkdir -p /etc/kernels
134                 /bin/tar -xjf ${KERNCACHE} -C /etc/kernels config-${ARCH}-${KV}
135                 mv /etc/kernels/config-${ARCH}-${KV} /etc/kernels/kernel-config-${ARCH}-${KV}
136         fi
137 }
138
139 gen_kerncache_is_valid()
140 {
141         KERNCACHE_IS_VALID=0
142         if [ "${CMD_NO_KERNEL_SOURCES}" = '1' ]
143         then
144                 
145                 BUILD_KERNEL=0
146                 # Can make this more secure ....
147                 
148                 /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
149                 if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] 
150                 then    
151                         print_info 1 'Valid kernel cache found; no sources will be used'
152                         KERNCACHE_IS_VALID=1
153                 fi
154         else
155                 if [ -e "${KERNCACHE}" ] 
156                 then
157                         KERNEL_CONFIG="/${KERNEL_DIR}/.config"
158                         if [ "${CMD_KERNEL_CONFIG}" != '' ]
159                         then
160                                 KERNEL_CONFIG="${CMD_KERNEL_CONFIG}"
161                         fi
162
163                         /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
164                         if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${KERNEL_CONFIG} ]
165                         then
166         
167                                 test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV} | md5sum | cut -d " " -f 1)
168                                 test2=$(grep -v "^#" ${KERNEL_CONFIG} | md5sum | cut -d " " -f 1)
169                                 if [ "${test1}" == "${test2}" ]
170                                 then
171         
172                                         echo
173                                         print_info 1 "No kernel configuration change, skipping kernel build..."
174                                         echo
175                                         KERNCACHE_IS_VALID=1
176                                 fi
177                         fi
178                 fi
179         fi
180         export KERNCACHE_IS_VALID       
181         return 1
182 }