Create additional cleanup options. --postclear for final cleanup and 2 new genkernel...
[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 "${TEMP}/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 "${TEMP}/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         [ -d ${TEMP} ] && gen_die "temporary directory already exists! Exiting."
74         (umask 077 && mkdir ${TEMP}) || {
75             gen_die "Could not create temporary directory! Exiting."
76         }
77         /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
78         cp "${TEMP}/kernel-${ARCH}-${KV}" "/boot/kernel-${KNAME}-${ARCH}-${KV}" || {
79                 rm -r ${TEMP}
80                 gen_die 'Could not copy the kernel binary to /boot!'
81                 }
82         cp "${TEMP}/System.map-${ARCH}-${KV}" "/boot/System.map-${KNAME}-${ARCH}-${KV}" || {
83                 rm -r ${TEMP}
84                 gen_die 'Could not copy System.map to /boot!'
85                 }
86         rm -r ${TEMP}
87 }
88
89 gen_kerncache_extract_modules()
90 {
91         if [ -e "${KERNCACHE}" ] 
92         then
93                 print_info 1 'Extracting kerncache kernel modules'
94                 if [ "${INSTALL_MOD_PATH}" != '' ]
95                 then
96                         /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib
97                 else
98                         /bin/tar -xjf ${KERNCACHE} -C / lib
99                 fi
100         fi
101 }
102
103 gen_kerncache_is_valid()
104 {
105         KERNCACHE_IS_VALID=0
106         if [ "${CMD_NO_KERNEL_SOURCES}" = '1' ]
107         then
108                 
109                 BUILD_KERNEL=0
110                 # Can make this more secure ....
111                 [ -d ${TEMP} ] && gen_die "temporary directory already exists! Exiting."
112                 (umask 077 && mkdir ${TEMP}) || {
113                     gen_die "Could not create temporary directory! Exiting."
114                 }
115                 
116                 /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
117                 if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] 
118                 then    
119                         print_info 1 'Valid kernel cache found; no sources will be used'
120                         KERNCACHE_IS_VALID=1
121                 fi
122                 /bin/rm -r ${TEMP}
123         else
124                 if [ -e "${KERNCACHE}" ] 
125                 then
126                         [ -d ${TEMP} ] && gen_die "temporary directory already exists! Exiting."
127                         (umask 077 && mkdir ${TEMP}) || {
128                             gen_die "Could not create temporary directory! Exiting."
129                             
130                         }
131                 
132                         /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
133                         if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e /${KERNEL_DIR}/.config ]
134                         then
135         
136                                 test1=$(md5sum ${TEMP}/config-${ARCH}-${KV} | cut -d " " -f 1)
137                                 test2=$(md5sum /${KERNEL_DIR}/.config | cut -d " " -f 1)
138                                 if [ "${test1}" == "${test2}" ]
139                                 then
140         
141                                         echo
142                                         print_info 1 "No kernel configuration change, skipping kernel build..."
143                                         echo
144                                         KERNCACHE_IS_VALID=1
145                                 fi
146                         fi
147                         /bin/rm -r ${TEMP}
148                 fi
149         fi
150         export KERNCACHE_IS_VALID       
151         return 1
152 }