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 # Pass maintainer script parameters to hook scripts
79 export DEB_MAINT_PARAMS="\$@"
81 test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
84 chmod 755 "$tmpdir/DEBIAN/$script"
87 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
88 # Generate a simple changelog template
89 cat <<EOF > debian/changelog
90 linux ($version-$revision) unstable; urgency=low
97 # Generate a control file
98 cat <<EOF > debian/control
103 Standards-Version: 3.6.1
106 if [ "$ARCH" = "um" ]; then
107 cat <<EOF >> debian/control
109 Package: $packagename
110 Provides: kernel-image-$version, linux-image-$version
112 Description: User Mode Linux kernel, version $version
113 User-mode Linux is a port of the Linux kernel to its own system call
114 interface. It provides a kind of virtual machine, which runs Linux
115 as a user process under another Linux kernel. This is useful for
116 kernel development, sandboxes, jails, experimentation, and
119 This package contains the Linux kernel, modules and corresponding other
120 files version $version
124 cat <<EOF >> debian/control
126 Package: $packagename
127 Provides: kernel-image-$version, linux-image-$version
128 Suggests: $fwpackagename
130 Description: Linux kernel, version $version
131 This package contains the Linux kernel, modules and corresponding other
132 files version $version
137 # Do we have firmware? Move it out of the way and build it into a package.
138 if [ -e "$tmpdir/lib/firmware" ]; then
139 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
141 cat <<EOF >> debian/control
143 Package: $fwpackagename
145 Description: Linux kernel firmware, version $version
146 This package contains firmware from the Linux kernel, version $version
149 create_package "$fwpackagename" "$fwdir"
152 create_package "$packagename" "$tmpdir"