Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 3 | # builddeb 1.3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> |
| 5 | # |
| 6 | # Simple script to generate a deb package for a Linux kernel. All the |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 7 | # complexity of what to do with a kernel after it is installed or removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | # is left to other scripts and packages: they can install scripts in the |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 9 | # /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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | set -e |
| 14 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 15 | create_package() { |
| 16 | local pname="$1" pdir="$2" |
| 17 | |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 18 | cp debian/copyright "$pdir/usr/share/doc/$pname/" |
| 19 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 20 | # Fix ownership and permissions |
| 21 | chown -R root:root "$pdir" |
| 22 | chmod -R go-w "$pdir" |
| 23 | |
| 24 | # Create the package |
| 25 | dpkg-gencontrol -isp -p$pname -P"$pdir" |
| 26 | dpkg --build "$pdir" .. |
| 27 | } |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | # Some variables and settings used throughout the script |
| 30 | version=$KERNELRELEASE |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 31 | revision=$(cat .version) |
Frans Pop | c72c75d | 2009-04-23 01:09:44 +0200 | [diff] [blame] | 32 | if [ -n "$KDEB_PKGVERSION" ]; then |
| 33 | packageversion=$KDEB_PKGVERSION |
| 34 | else |
| 35 | packageversion=$version-$revision |
| 36 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | tmpdir="$objtree/debian/tmp" |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 38 | fwdir="$objtree/debian/fwtmp" |
maximilian attems | f7a2c31 | 2009-04-23 01:12:01 +0200 | [diff] [blame^] | 39 | packagename=linux-image-$version |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 40 | fwpackagename=linux-firmware-image |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 41 | |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 42 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 43 | packagename=user-mode-linux-$version |
| 44 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | # Setup the directory structure |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 47 | rm -rf "$tmpdir" "$fwdir" |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 48 | mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" |
| 49 | mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 50 | if [ "$ARCH" = "um" ] ; then |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 51 | mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 52 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | # Build and install the kernel |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 55 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 56 | $MAKE linux |
| 57 | cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" |
| 58 | cp .config "$tmpdir/usr/share/doc/$packagename/config" |
| 59 | gzip "$tmpdir/usr/share/doc/$packagename/config" |
| 60 | cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" |
| 61 | else |
| 62 | cp System.map "$tmpdir/boot/System.map-$version" |
| 63 | cp .config "$tmpdir/boot/config-$version" |
Frans Pop | a89b433bd | 2009-04-23 01:09:04 +0200 | [diff] [blame] | 64 | # Not all arches include the boot path in KBUILD_IMAGE |
| 65 | if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then |
| 66 | cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" |
| 67 | fi |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 68 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | if grep -q '^CONFIG_MODULES=y' .config ; then |
Sam Ravnborg | a91f98a | 2005-07-14 20:26:09 +0000 | [diff] [blame] | 71 | INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 72 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 73 | mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" |
| 74 | rmdir "$tmpdir/lib/modules/$version" |
| 75 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | fi |
| 77 | |
| 78 | # Install the maintainer scripts |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 79 | # Note: hook scripts under /etc/kernel are also executed by official Debian |
| 80 | # kernel packages, as well as kernel packages built using make-kpkg |
| 81 | debhookdir=${KDEB_HOOKDIR:-/etc/kernel} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | for script in postinst postrm preinst prerm ; do |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 83 | mkdir -p "$tmpdir$debhookdir/$script.d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | cat <<EOF > "$tmpdir/DEBIAN/$script" |
| 85 | #!/bin/sh |
| 86 | |
| 87 | set -e |
| 88 | |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 89 | # Pass maintainer script parameters to hook scripts |
| 90 | export DEB_MAINT_PARAMS="\$@" |
| 91 | |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 92 | test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | exit 0 |
| 94 | EOF |
| 95 | chmod 755 "$tmpdir/DEBIAN/$script" |
| 96 | done |
| 97 | |
maximilian attems | edec611 | 2009-04-23 01:11:20 +0200 | [diff] [blame] | 98 | # Try to determine maintainer and email values |
| 99 | if [ -n "$DEBEMAIL" ]; then |
| 100 | email=$DEBEMAIL |
| 101 | elif [ -n "$EMAIL" ]; then |
| 102 | email=$EMAIL |
| 103 | else |
| 104 | email=$(id -nu)@$(hostname -f) |
| 105 | fi |
| 106 | if [ -n "$DEBFULLNAME" ]; then |
| 107 | name=$DEBFULLNAME |
| 108 | elif [ -n "$NAME" ]; then |
| 109 | name=$NAME |
| 110 | else |
| 111 | name="Anonymous" |
| 112 | fi |
| 113 | maintainer="$name <$email>" |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | # Generate a simple changelog template |
| 116 | cat <<EOF > debian/changelog |
Frans Pop | 4bf4cd4 | 2009-04-23 01:11:43 +0200 | [diff] [blame] | 117 | linux-upstream ($packageversion) unstable; urgency=low |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Frans Pop | a83ca277 | 2009-04-23 01:10:25 +0200 | [diff] [blame] | 119 | * Custom built Linux kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
maximilian attems | edec611 | 2009-04-23 01:11:20 +0200 | [diff] [blame] | 121 | -- $maintainer $(date -R) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | EOF |
| 123 | |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 124 | # Generate copyright file |
| 125 | cat <<EOF > debian/copyright |
| 126 | This is a packacked upstream version of the Linux kernel. |
| 127 | |
| 128 | The sources may be found at most Linux ftp sites, including: |
| 129 | ftp://ftp.kernel.org/pub/linux/kernel |
| 130 | |
| 131 | Copyright: 1991 - 2009 Linus Torvalds and others. |
| 132 | |
| 133 | The git repository for mainline kernel development is at: |
| 134 | git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git |
| 135 | |
| 136 | This program is free software; you can redistribute it and/or modify |
| 137 | it under the terms of the GNU General Public License as published by |
| 138 | the Free Software Foundation; version 2 dated June, 1991. |
| 139 | |
| 140 | On Debian GNU/Linux systems, the complete text of the GNU General Public |
| 141 | License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. |
| 142 | EOF |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | # Generate a control file |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 145 | cat <<EOF > debian/control |
Frans Pop | 4bf4cd4 | 2009-04-23 01:11:43 +0200 | [diff] [blame] | 146 | Source: linux-upstream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | Section: base |
| 148 | Priority: optional |
maximilian attems | edec611 | 2009-04-23 01:11:20 +0200 | [diff] [blame] | 149 | Maintainer: $maintainer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | Standards-Version: 3.6.1 |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 151 | EOF |
| 152 | |
| 153 | if [ "$ARCH" = "um" ]; then |
| 154 | cat <<EOF >> debian/control |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 156 | Package: $packagename |
bugme-daemon@bugzilla.kernel.org | 6f67a00 | 2007-08-29 07:57:41 -0700 | [diff] [blame] | 157 | Provides: kernel-image-$version, linux-image-$version |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | Architecture: any |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 159 | Description: User Mode Linux kernel, version $version |
| 160 | User-mode Linux is a port of the Linux kernel to its own system call |
| 161 | interface. It provides a kind of virtual machine, which runs Linux |
| 162 | as a user process under another Linux kernel. This is useful for |
| 163 | kernel development, sandboxes, jails, experimentation, and |
| 164 | many other things. |
| 165 | . |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | This package contains the Linux kernel, modules and corresponding other |
Frans Pop | a83ca277 | 2009-04-23 01:10:25 +0200 | [diff] [blame] | 167 | files, version: $version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | EOF |
| 169 | |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 170 | else |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 171 | cat <<EOF >> debian/control |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 172 | |
| 173 | Package: $packagename |
bugme-daemon@bugzilla.kernel.org | 6f67a00 | 2007-08-29 07:57:41 -0700 | [diff] [blame] | 174 | Provides: kernel-image-$version, linux-image-$version |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 175 | Suggests: $fwpackagename |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 176 | Architecture: any |
| 177 | Description: Linux kernel, version $version |
| 178 | This package contains the Linux kernel, modules and corresponding other |
Frans Pop | a83ca277 | 2009-04-23 01:10:25 +0200 | [diff] [blame] | 179 | files, version: $version. |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 180 | EOF |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 181 | |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 182 | fi |
| 183 | |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 184 | # Do we have firmware? Move it out of the way and build it into a package. |
| 185 | if [ -e "$tmpdir/lib/firmware" ]; then |
| 186 | mv "$tmpdir/lib/firmware" "$fwdir/lib/" |
| 187 | |
| 188 | cat <<EOF >> debian/control |
| 189 | |
| 190 | Package: $fwpackagename |
| 191 | Architecture: all |
| 192 | Description: Linux kernel firmware, version $version |
Frans Pop | a83ca277 | 2009-04-23 01:10:25 +0200 | [diff] [blame] | 193 | This package contains firmware from the Linux kernel, version $version. |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 194 | EOF |
| 195 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 196 | create_package "$fwpackagename" "$fwdir" |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 197 | fi |
| 198 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 199 | create_package "$packagename" "$tmpdir" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | exit 0 |