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