blob: eff7f9de30dc90743d6e0c9138e4dc3b0c4afaad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2#
3# builddeb 1.2
4# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
5#
6# Simple script to generate a deb package for a Linux kernel. All the
Frans Pop4f661992009-04-23 01:08:31 +02007# complexity of what to do with a kernel after it is installed or removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07008# 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.
11
12set -e
13
14# Some variables and settings used throughout the script
15version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020016revision=$(cat .version)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010018fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000019packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010020fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000021
Frans Pop4f661992009-04-23 01:08:31 +020022if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000023 packagename=user-mode-linux-$version
24fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010027rm -rf "$tmpdir" "$fwdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010029mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
Frans Pop4f661992009-04-23 01:08:31 +020030if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000031 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
32fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020035if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000036 $MAKE linux
37 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
38 cp .config "$tmpdir/usr/share/doc/$packagename/config"
39 gzip "$tmpdir/usr/share/doc/$packagename/config"
40 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
41else
42 cp System.map "$tmpdir/boot/System.map-$version"
43 cp .config "$tmpdir/boot/config-$version"
44 cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
45fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000048 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020049 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000050 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
51 rmdir "$tmpdir/lib/modules/$version"
52 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070053fi
54
55# Install the maintainer scripts
56for script in postinst postrm preinst prerm ; do
57 mkdir -p "$tmpdir/etc/kernel/$script.d"
58 cat <<EOF > "$tmpdir/DEBIAN/$script"
59#!/bin/sh
60
61set -e
62
63test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
64exit 0
65EOF
66 chmod 755 "$tmpdir/DEBIAN/$script"
67done
68
69name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
70# Generate a simple changelog template
71cat <<EOF > debian/changelog
Michal Sojkaed2c9fa2008-02-07 17:18:51 +010072linux ($version-$revision) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 * A standard release
75
76 -- $name $(date -R)
77EOF
78
79# Generate a control file
Frans Pop4f661992009-04-23 01:08:31 +020080if [ "$ARCH" = "um" ]; then
81 cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -070082Source: linux
83Section: base
84Priority: optional
85Maintainer: $name
86Standards-Version: 3.6.1
87
Sam Ravnborg687c3da2005-07-14 20:24:00 +000088Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -070089Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -070090Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +000091Description: User Mode Linux kernel, version $version
92 User-mode Linux is a port of the Linux kernel to its own system call
93 interface. It provides a kind of virtual machine, which runs Linux
94 as a user process under another Linux kernel. This is useful for
95 kernel development, sandboxes, jails, experimentation, and
96 many other things.
97 .
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 This package contains the Linux kernel, modules and corresponding other
Sam Ravnborgdc5962f2005-07-14 20:24:56 +000099 files version $version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100EOF
101
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000102else
Frans Pop4f661992009-04-23 01:08:31 +0200103 cat <<EOF > debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000104Source: linux
105Section: base
106Priority: optional
107Maintainer: $name
108Standards-Version: 3.6.1
109
110Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700111Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100112Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000113Architecture: any
114Description: Linux kernel, version $version
115 This package contains the Linux kernel, modules and corresponding other
116 files version $version
117EOF
Frans Pop4f661992009-04-23 01:08:31 +0200118
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000119fi
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121# Fix some ownership and permissions
122chown -R root:root "$tmpdir"
123chmod -R go-w "$tmpdir"
124
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100125# Do we have firmware? Move it out of the way and build it into a package.
126if [ -e "$tmpdir/lib/firmware" ]; then
127 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
128
129 cat <<EOF >> debian/control
130
131Package: $fwpackagename
132Architecture: all
133Description: Linux kernel firmware, version $version
134 This package contains firmware from the Linux kernel, version $version
135EOF
136
137 dpkg-gencontrol -isp -p$fwpackagename -P"$fwdir"
138 dpkg --build "$fwdir" ..
139fi
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141# Perform the final magic
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100142dpkg-gencontrol -isp -p$packagename
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143dpkg --build "$tmpdir" ..
144
145exit 0