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