4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
6 # Simple script to generate a deb package for a Linux kernel. All the
7 # complexity of what to do with a kernel after it is installed or removed
8 # is left to other scripts and packages: they can install scripts in the
9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
10 # package install and removal.
15 local pname="$1" pdir="$2"
17 # Fix ownership and permissions
18 chown -R root:root "$pdir"
22 dpkg-gencontrol -isp -p$pname -P"$pdir"
23 dpkg --build "$pdir" ..
26 # Some variables and settings used throughout the script
27 version=$KERNELRELEASE
28 revision=$(cat .version)
29 if [ -n "$KDEB_PKGVERSION" ]; then
30 packageversion=$KDEB_PKGVERSION
32 packageversion=$version-$revision
34 tmpdir="$objtree/debian/tmp"
35 fwdir="$objtree/debian/fwtmp"
36 packagename=linux-$version
37 fwpackagename=linux-firmware-image
39 if [ "$ARCH" = "um" ] ; then
40 packagename=user-mode-linux-$version
43 # Setup the directory structure
44 rm -rf "$tmpdir" "$fwdir"
45 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
46 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
47 if [ "$ARCH" = "um" ] ; then
48 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
51 # Build and install the kernel
52 if [ "$ARCH" = "um" ] ; then
54 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
55 cp .config "$tmpdir/usr/share/doc/$packagename/config"
56 gzip "$tmpdir/usr/share/doc/$packagename/config"
57 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
59 cp System.map "$tmpdir/boot/System.map-$version"
60 cp .config "$tmpdir/boot/config-$version"
61 # Not all arches include the boot path in KBUILD_IMAGE
62 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
63 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
67 if grep -q '^CONFIG_MODULES=y' .config ; then
68 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
69 if [ "$ARCH" = "um" ] ; then
70 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
71 rmdir "$tmpdir/lib/modules/$version"
75 # Install the maintainer scripts
76 for script in postinst postrm preinst prerm ; do
77 mkdir -p "$tmpdir/etc/kernel/$script.d"
78 cat <<EOF > "$tmpdir/DEBIAN/$script"
83 # Pass maintainer script parameters to hook scripts
84 export DEB_MAINT_PARAMS="\$@"
86 test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
89 chmod 755 "$tmpdir/DEBIAN/$script"
92 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
93 # Generate a simple changelog template
94 cat <<EOF > debian/changelog
95 linux ($packageversion) unstable; urgency=low
102 # Generate a control file
103 cat <<EOF > debian/control
108 Standards-Version: 3.6.1
111 if [ "$ARCH" = "um" ]; then
112 cat <<EOF >> debian/control
114 Package: $packagename
115 Provides: kernel-image-$version, linux-image-$version
117 Description: User Mode Linux kernel, version $version
118 User-mode Linux is a port of the Linux kernel to its own system call
119 interface. It provides a kind of virtual machine, which runs Linux
120 as a user process under another Linux kernel. This is useful for
121 kernel development, sandboxes, jails, experimentation, and
124 This package contains the Linux kernel, modules and corresponding other
125 files version $version
129 cat <<EOF >> debian/control
131 Package: $packagename
132 Provides: kernel-image-$version, linux-image-$version
133 Suggests: $fwpackagename
135 Description: Linux kernel, version $version
136 This package contains the Linux kernel, modules and corresponding other
137 files version $version
142 # Do we have firmware? Move it out of the way and build it into a package.
143 if [ -e "$tmpdir/lib/firmware" ]; then
144 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
146 cat <<EOF >> debian/control
148 Package: $fwpackagename
150 Description: Linux kernel firmware, version $version
151 This package contains firmware from the Linux kernel, version $version
154 create_package "$fwpackagename" "$fwdir"
157 create_package "$packagename" "$tmpdir"