blob: feebd69c2eea540fd95ec90e0b86e33c1eb37d7d [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
Frans Pop3e2ab252009-04-23 01:08:44 +020014create_package() {
15 local pname="$1" pdir="$2"
16
17 # Fix ownership and permissions
18 chown -R root:root "$pdir"
19 chmod -R go-w "$pdir"
20
21 # Create the package
22 dpkg-gencontrol -isp -p$pname -P"$pdir"
23 dpkg --build "$pdir" ..
24}
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026# Some variables and settings used throughout the script
27version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020028revision=$(cat .version)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010030fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000031packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010032fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000033
Frans Pop4f661992009-04-23 01:08:31 +020034if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000035 packagename=user-mode-linux-$version
36fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010039rm -rf "$tmpdir" "$fwdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010041mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
Frans Pop4f661992009-04-23 01:08:31 +020042if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000043 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
44fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020047if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000048 $MAKE linux
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"
53else
54 cp System.map "$tmpdir/boot/System.map-$version"
55 cp .config "$tmpdir/boot/config-$version"
56 cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
57fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000060 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020061 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000062 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
63 rmdir "$tmpdir/lib/modules/$version"
64 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070065fi
66
67# Install the maintainer scripts
68for script in postinst postrm preinst prerm ; do
69 mkdir -p "$tmpdir/etc/kernel/$script.d"
70 cat <<EOF > "$tmpdir/DEBIAN/$script"
71#!/bin/sh
72
73set -e
74
75test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
76exit 0
77EOF
78 chmod 755 "$tmpdir/DEBIAN/$script"
79done
80
81name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
82# Generate a simple changelog template
83cat <<EOF > debian/changelog
Michal Sojkaed2c9fa2008-02-07 17:18:51 +010084linux ($version-$revision) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 * A standard release
87
88 -- $name $(date -R)
89EOF
90
91# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +020092cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -070093Source: linux
94Section: base
95Priority: optional
96Maintainer: $name
97Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +020098EOF
99
100if [ "$ARCH" = "um" ]; then
101 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000103Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700104Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000106Description: User Mode Linux kernel, version $version
107 User-mode Linux is a port of the Linux kernel to its own system call
108 interface. It provides a kind of virtual machine, which runs Linux
109 as a user process under another Linux kernel. This is useful for
110 kernel development, sandboxes, jails, experimentation, and
111 many other things.
112 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 This package contains the Linux kernel, modules and corresponding other
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000114 files version $version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115EOF
116
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000117else
Frans Pop3e2ab252009-04-23 01:08:44 +0200118 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000119
120Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700121Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100122Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000123Architecture: any
124Description: Linux kernel, version $version
125 This package contains the Linux kernel, modules and corresponding other
126 files version $version
127EOF
Frans Pop4f661992009-04-23 01:08:31 +0200128
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000129fi
130
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100131# Do we have firmware? Move it out of the way and build it into a package.
132if [ -e "$tmpdir/lib/firmware" ]; then
133 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
134
135 cat <<EOF >> debian/control
136
137Package: $fwpackagename
138Architecture: all
139Description: Linux kernel firmware, version $version
140 This package contains firmware from the Linux kernel, version $version
141EOF
142
Frans Pop3e2ab252009-04-23 01:08:44 +0200143 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100144fi
145
Frans Pop3e2ab252009-04-23 01:08:44 +0200146create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148exit 0