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