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