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 tmpdir="$objtree/debian/tmp"
30 fwdir="$objtree/debian/fwtmp"
31 packagename=linux-$version
32 fwpackagename=linux-firmware-image
34 if [ "$ARCH" = "um" ] ; then
35 packagename=user-mode-linux-$version
38 # Setup the directory structure
39 rm -rf "$tmpdir" "$fwdir"
40 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
41 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
42 if [ "$ARCH" = "um" ] ; then
43 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
46 # Build and install the kernel
47 if [ "$ARCH" = "um" ] ; then
49 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
50 cp .config "$tmpdir/usr/share/doc/$packagename/config"
51 gzip "$tmpdir/usr/share/doc/$packagename/config"
52 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
54 cp System.map "$tmpdir/boot/System.map-$version"
55 cp .config "$tmpdir/boot/config-$version"
56 # Not all arches include the boot path in KBUILD_IMAGE
57 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
58 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
62 if grep -q '^CONFIG_MODULES=y' .config ; then
63 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
64 if [ "$ARCH" = "um" ] ; then
65 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
66 rmdir "$tmpdir/lib/modules/$version"
70 # Install the maintainer scripts
71 for script in postinst postrm preinst prerm ; do
72 mkdir -p "$tmpdir/etc/kernel/$script.d"
73 cat <<EOF > "$tmpdir/DEBIAN/$script"
78 test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
81 chmod 755 "$tmpdir/DEBIAN/$script"
84 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
85 # Generate a simple changelog template
86 cat <<EOF > debian/changelog
87 linux ($version-$revision) unstable; urgency=low
94 # Generate a control file
95 cat <<EOF > debian/control
100 Standards-Version: 3.6.1
103 if [ "$ARCH" = "um" ]; then
104 cat <<EOF >> debian/control
106 Package: $packagename
107 Provides: kernel-image-$version, linux-image-$version
109 Description: User Mode Linux kernel, version $version
110 User-mode Linux is a port of the Linux kernel to its own system call
111 interface. It provides a kind of virtual machine, which runs Linux
112 as a user process under another Linux kernel. This is useful for
113 kernel development, sandboxes, jails, experimentation, and
116 This package contains the Linux kernel, modules and corresponding other
117 files version $version
121 cat <<EOF >> debian/control
123 Package: $packagename
124 Provides: kernel-image-$version, linux-image-$version
125 Suggests: $fwpackagename
127 Description: Linux kernel, version $version
128 This package contains the Linux kernel, modules and corresponding other
129 files version $version
134 # Do we have firmware? Move it out of the way and build it into a package.
135 if [ -e "$tmpdir/lib/firmware" ]; then
136 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
138 cat <<EOF >> debian/control
140 Package: $fwpackagename
142 Description: Linux kernel firmware, version $version
143 This package contains firmware from the Linux kernel, version $version
146 create_package "$fwpackagename" "$fwdir"
149 create_package "$packagename" "$tmpdir"