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