Commit patch for bug #139866 by Martin Parm.
[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 [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
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 [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
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
25         fi
26         
27         if [ "${GENERATE_Z_IMAGE}" != '1' ]
28         then
29             if [ "${KERN_24}" != '1' -a  "${CMD_BOOTSPLASH}" != '1' ]
30             then
31                     [ "${BUILD_INITRD}" -ne 0 ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; }
32             else
33                     [ "${BUILD_INITRD}" -ne 0 ] && { cp "${TMPDIR}/initrd-${KV}" "${TEMP}/minkernpackage/initrd-${ARCH}-${KV}" || gen_die 'Could not copy the initrd for the kernel package!'; }
34             fi
35         fi
36         
37         cd "${TEMP}/minkernpackage" 
38         /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!'
39         cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1
40 }
41 gen_modulespackage()
42 {
43         print_info 1 'Creating modules package'
44         rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1
45         mkdir "${TEMP}/modulespackage" || gen_die 'Could not make a directory for the kernel package!'
46
47         if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ]
48         then
49             mkdir -p ${TEMP}/modulespackage/lib/modules
50             cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/modulespackage/lib/modules"
51             cd "${TEMP}/modulespackage" 
52             /bin/tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!'
53         else
54             print_info 1 "Could not create a modules package ${INSTALL_MOD_PATH}/lib/modules/${KV} was not found"
55         fi
56         cd "${TEMP}" && rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1
57 }
58 gen_kerncache()
59 {
60         print_info 1 'Creating kernel cache'
61         rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
62         mkdir "${TEMP}/kerncache" || gen_die 'Could not make a directory for the kernel cache!'
63         cd "${KERNEL_DIR}"
64         cp "${KERNEL_BINARY}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!'
65         cp "${KERNEL_DIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}"
66         cp "${KERNEL_DIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}"
67         if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
68         then
69                 cp "${KERNEL_BINARY_2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package"
70         fi
71         
72         echo "VERSION = ${VER}" > "${TEMP}/kerncache/kerncache.config"
73         echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config"
74         echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config"
75         echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config"
76         
77         mkdir -p "${TEMP}/kerncache/lib/modules/"
78         
79         if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ]
80         then
81             cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/kerncache/lib/modules"
82         fi
83         
84         cd "${TEMP}/kerncache" 
85         /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!'
86         cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
87 }
88
89 gen_kerncache_extract_kernel()
90 {
91         /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
92         cp "${TEMP}/kernel-${ARCH}-${KV}" "${BOOTDIR}/kernel-${KNAME}-${ARCH}-${KV}" || gen_die 'Could not copy the kernel binary to ${BOOTDIR}!'
93         if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
94         then
95                 cp "${TEMP}/kernelz-${ARCH}-${KV}" "${BOOTDIR}/kernelz-${KNAME}-${ARCH}-${KV}" || gen_die 'Could not copy the kernel binary to ${BOOTDIR}!'
96         fi
97         cp "${TEMP}/System.map-${ARCH}-${KV}" "${BOOTDIR}/System.map-${KNAME}-${ARCH}-${KV}" || gen_die 'Could not copy System.map to ${BOOTDIR}!'
98 }
99
100 gen_kerncache_extract_modules()
101 {
102         if [ -e "${KERNCACHE}" ] 
103         then
104                 print_info 1 'Extracting kerncache kernel modules'
105                 if [ "${INSTALL_MOD_PATH}" != '' ]
106                 then
107                         /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib
108                 else
109                         /bin/tar -xjf ${KERNCACHE} -C / lib
110                 fi
111         fi
112 }
113
114 gen_kerncache_extract_config()
115 {
116         if [ -e "${KERNCACHE}" ] 
117         then
118                 print_info 1 'Extracting kerncache config to /etc/kernels'
119                 mkdir -p /etc/kernels
120                 /bin/tar -xjf ${KERNCACHE} -C /etc/kernels config-${ARCH}-${KV}
121                 mv /etc/kernels/config-${ARCH}-${KV} /etc/kernels/kernel-config-${ARCH}-${KV}
122         fi
123 }
124
125 gen_kerncache_is_valid()
126 {
127         KERNCACHE_IS_VALID=0
128         if [ "${CMD_NO_KERNEL_SOURCES}" = '1' ]
129         then
130                 
131                 BUILD_KERNEL=0
132                 # Can make this more secure ....
133                 
134                 /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
135                 if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] 
136                 then    
137                         print_info 1 'Valid kernel cache found; no sources will be used'
138                         KERNCACHE_IS_VALID=1
139                 fi
140         else
141                 if [ -e "${KERNCACHE}" ] 
142                 then
143                         /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
144                         if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e /${KERNEL_DIR}/.config ]
145                         then
146         
147                                 test1=$(md5sum ${TEMP}/config-${ARCH}-${KV} | cut -d " " -f 1)
148                                 test2=$(md5sum /${KERNEL_DIR}/.config | cut -d " " -f 1)
149                                 if [ "${test1}" == "${test2}" ]
150                                 then
151         
152                                         echo
153                                         print_info 1 "No kernel configuration change, skipping kernel build..."
154                                         echo
155                                         KERNCACHE_IS_VALID=1
156                                 fi
157                         fi
158                 fi
159         fi
160         export KERNCACHE_IS_VALID       
161         return 1
162 }