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