blob: 8b357b0bd250b0e04012a08815c01cd3f95f22a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2#
Frans Pop49644512009-04-23 01:09:25 +02003# builddeb 1.3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004# 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
Frans Popfe233cb2009-04-23 01:10:10 +02009# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10# specified in KDEB_HOOKDIR) that will be called on package install and
11# removal.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13set -e
14
Frans Pop3e2ab252009-04-23 01:08:44 +020015create_package() {
16 local pname="$1" pdir="$2"
17
Frans Pop9461f662009-04-24 19:08:24 +020018 cp debian/copyright "$pdir/usr/share/doc/$pname/"
maximilian attems1ab18482009-06-26 20:04:36 +020019 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
20 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
Frans Pop9461f662009-04-24 19:08:24 +020021
Frans Pop3e2ab252009-04-23 01:08:44 +020022 # Fix ownership and permissions
23 chown -R root:root "$pdir"
24 chmod -R go-w "$pdir"
25
26 # Create the package
27 dpkg-gencontrol -isp -p$pname -P"$pdir"
28 dpkg --build "$pdir" ..
29}
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031# Some variables and settings used throughout the script
32version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020033revision=$(cat .version)
Frans Popc72c75d2009-04-23 01:09:44 +020034if [ -n "$KDEB_PKGVERSION" ]; then
35 packageversion=$KDEB_PKGVERSION
36else
37 packageversion=$version-$revision
38fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070039tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010040fwdir="$objtree/debian/fwtmp"
maximilian attemsf7a2c312009-04-23 01:12:01 +020041packagename=linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010042fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000043
Frans Pop4f661992009-04-23 01:08:31 +020044if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000045 packagename=user-mode-linux-$version
46fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010049rm -rf "$tmpdir" "$fwdir"
Frans Pop9461f662009-04-24 19:08:24 +020050mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
51mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
Frans Pop4f661992009-04-23 01:08:31 +020052if [ "$ARCH" = "um" ] ; then
Frans Pop9461f662009-04-24 19:08:24 +020053 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000054fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020057if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000058 $MAKE linux
59 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
60 cp .config "$tmpdir/usr/share/doc/$packagename/config"
61 gzip "$tmpdir/usr/share/doc/$packagename/config"
62 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
63else
64 cp System.map "$tmpdir/boot/System.map-$version"
65 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b433bd2009-04-23 01:09:04 +020066 # Not all arches include the boot path in KBUILD_IMAGE
67 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
68 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
69 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000070fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000073 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020074 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000075 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
76 rmdir "$tmpdir/lib/modules/$version"
77 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070078fi
79
80# Install the maintainer scripts
Frans Popfe233cb2009-04-23 01:10:10 +020081# Note: hook scripts under /etc/kernel are also executed by official Debian
82# kernel packages, as well as kernel packages built using make-kpkg
83debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
Linus Torvalds1da177e2005-04-16 15:20:36 -070084for script in postinst postrm preinst prerm ; do
Frans Popfe233cb2009-04-23 01:10:10 +020085 mkdir -p "$tmpdir$debhookdir/$script.d"
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 cat <<EOF > "$tmpdir/DEBIAN/$script"
87#!/bin/sh
88
89set -e
90
Frans Pop49644512009-04-23 01:09:25 +020091# Pass maintainer script parameters to hook scripts
maximilian attems241ad112009-07-05 20:17:34 +020092export DEB_MAINT_PARAMS="\$*"
Frans Pop49644512009-04-23 01:09:25 +020093
Frans Popfe233cb2009-04-23 01:10:10 +020094test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070095exit 0
96EOF
97 chmod 755 "$tmpdir/DEBIAN/$script"
98done
99
maximilian attemsedec6112009-04-23 01:11:20 +0200100# Try to determine maintainer and email values
101if [ -n "$DEBEMAIL" ]; then
102 email=$DEBEMAIL
103elif [ -n "$EMAIL" ]; then
104 email=$EMAIL
105else
106 email=$(id -nu)@$(hostname -f)
107fi
108if [ -n "$DEBFULLNAME" ]; then
109 name=$DEBFULLNAME
110elif [ -n "$NAME" ]; then
111 name=$NAME
112else
113 name="Anonymous"
114fi
115maintainer="$name <$email>"
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117# Generate a simple changelog template
118cat <<EOF > debian/changelog
Frans Pop4bf4cd42009-04-23 01:11:43 +0200119linux-upstream ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Frans Popa83ca2772009-04-23 01:10:25 +0200121 * Custom built Linux kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
maximilian attemsedec6112009-04-23 01:11:20 +0200123 -- $maintainer $(date -R)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124EOF
125
Frans Pop9461f662009-04-24 19:08:24 +0200126# Generate copyright file
127cat <<EOF > debian/copyright
128This is a packacked upstream version of the Linux kernel.
129
130The sources may be found at most Linux ftp sites, including:
131ftp://ftp.kernel.org/pub/linux/kernel
132
133Copyright: 1991 - 2009 Linus Torvalds and others.
134
135The git repository for mainline kernel development is at:
136git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
137
138 This program is free software; you can redistribute it and/or modify
139 it under the terms of the GNU General Public License as published by
140 the Free Software Foundation; version 2 dated June, 1991.
141
142On Debian GNU/Linux systems, the complete text of the GNU General Public
143License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
144EOF
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200147cat <<EOF > debian/control
Frans Pop4bf4cd42009-04-23 01:11:43 +0200148Source: linux-upstream
maximilian attems54c33552009-04-23 01:12:41 +0200149Section: admin
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150Priority: optional
maximilian attemsedec6112009-04-23 01:11:20 +0200151Maintainer: $maintainer
maximilian attems6d992322009-04-23 01:12:58 +0200152Standards-Version: 3.8.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200153EOF
154
155if [ "$ARCH" = "um" ]; then
156 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000158Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200159Provides: linux-image, linux-image-2.6, linux-modules-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000161Description: User Mode Linux kernel, version $version
162 User-mode Linux is a port of the Linux kernel to its own system call
163 interface. It provides a kind of virtual machine, which runs Linux
164 as a user process under another Linux kernel. This is useful for
165 kernel development, sandboxes, jails, experimentation, and
166 many other things.
167 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200169 files, version: $version.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170EOF
171
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000172else
Frans Pop3e2ab252009-04-23 01:08:44 +0200173 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000174
175Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200176Provides: linux-image, linux-image-2.6, linux-modules-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100177Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000178Architecture: any
179Description: Linux kernel, version $version
180 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200181 files, version: $version.
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000182EOF
Frans Pop4f661992009-04-23 01:08:31 +0200183
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000184fi
185
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100186# Do we have firmware? Move it out of the way and build it into a package.
187if [ -e "$tmpdir/lib/firmware" ]; then
188 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
189
190 cat <<EOF >> debian/control
191
192Package: $fwpackagename
193Architecture: all
194Description: Linux kernel firmware, version $version
Frans Popa83ca2772009-04-23 01:10:25 +0200195 This package contains firmware from the Linux kernel, version $version.
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100196EOF
197
Frans Pop3e2ab252009-04-23 01:08:44 +0200198 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100199fi
200
Frans Pop3e2ab252009-04-23 01:08:44 +0200201create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203exit 0