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 | |
| 18 | # Fix ownership and permissions |
| 19 | chown -R root:root "$pdir" |
| 20 | chmod -R go-w "$pdir" |
| 21 | |
| 22 | # Create the package |
| 23 | dpkg-gencontrol -isp -p$pname -P"$pdir" |
| 24 | dpkg --build "$pdir" .. |
| 25 | } |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | # Some variables and settings used throughout the script |
| 28 | version=$KERNELRELEASE |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 29 | revision=$(cat .version) |
Frans Pop | c72c75d | 2009-04-23 01:09:44 +0200 | [diff] [blame] | 30 | if [ -n "$KDEB_PKGVERSION" ]; then |
| 31 | packageversion=$KDEB_PKGVERSION |
| 32 | else |
| 33 | packageversion=$version-$revision |
| 34 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | tmpdir="$objtree/debian/tmp" |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 36 | fwdir="$objtree/debian/fwtmp" |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 37 | packagename=linux-$version |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 38 | fwpackagename=linux-firmware-image |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 39 | |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 40 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 41 | packagename=user-mode-linux-$version |
| 42 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | # Setup the directory structure |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 45 | rm -rf "$tmpdir" "$fwdir" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 47 | mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 48 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 49 | mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin" |
| 50 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | # Build and install the kernel |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 53 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 54 | $MAKE linux |
| 55 | cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" |
| 56 | cp .config "$tmpdir/usr/share/doc/$packagename/config" |
| 57 | gzip "$tmpdir/usr/share/doc/$packagename/config" |
| 58 | cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" |
| 59 | else |
| 60 | cp System.map "$tmpdir/boot/System.map-$version" |
| 61 | cp .config "$tmpdir/boot/config-$version" |
Frans Pop | a89b433bd | 2009-04-23 01:09:04 +0200 | [diff] [blame] | 62 | # Not all arches include the boot path in KBUILD_IMAGE |
| 63 | if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then |
| 64 | cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" |
| 65 | fi |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 66 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | if grep -q '^CONFIG_MODULES=y' .config ; then |
Sam Ravnborg | a91f98a | 2005-07-14 20:26:09 +0000 | [diff] [blame] | 69 | INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 70 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 71 | mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" |
| 72 | rmdir "$tmpdir/lib/modules/$version" |
| 73 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | fi |
| 75 | |
| 76 | # Install the maintainer scripts |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame^] | 77 | # Note: hook scripts under /etc/kernel are also executed by official Debian |
| 78 | # kernel packages, as well as kernel packages built using make-kpkg |
| 79 | debhookdir=${KDEB_HOOKDIR:-/etc/kernel} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | for script in postinst postrm preinst prerm ; do |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame^] | 81 | mkdir -p "$tmpdir$debhookdir/$script.d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | cat <<EOF > "$tmpdir/DEBIAN/$script" |
| 83 | #!/bin/sh |
| 84 | |
| 85 | set -e |
| 86 | |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 87 | # Pass maintainer script parameters to hook scripts |
| 88 | export DEB_MAINT_PARAMS="\$@" |
| 89 | |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame^] | 90 | test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | exit 0 |
| 92 | EOF |
| 93 | chmod 755 "$tmpdir/DEBIAN/$script" |
| 94 | done |
| 95 | |
| 96 | name="Kernel Compiler <$(id -nu)@$(hostname -f)>" |
| 97 | # Generate a simple changelog template |
| 98 | cat <<EOF > debian/changelog |
Frans Pop | c72c75d | 2009-04-23 01:09:44 +0200 | [diff] [blame] | 99 | linux ($packageversion) unstable; urgency=low |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | * A standard release |
| 102 | |
| 103 | -- $name $(date -R) |
| 104 | EOF |
| 105 | |
| 106 | # Generate a control file |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 107 | cat <<EOF > debian/control |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | Source: linux |
| 109 | Section: base |
| 110 | Priority: optional |
| 111 | Maintainer: $name |
| 112 | Standards-Version: 3.6.1 |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 113 | EOF |
| 114 | |
| 115 | if [ "$ARCH" = "um" ]; then |
| 116 | cat <<EOF >> debian/control |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 118 | Package: $packagename |
bugme-daemon@bugzilla.kernel.org | 6f67a00 | 2007-08-29 07:57:41 -0700 | [diff] [blame] | 119 | Provides: kernel-image-$version, linux-image-$version |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | Architecture: any |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 121 | Description: User Mode Linux kernel, version $version |
| 122 | User-mode Linux is a port of the Linux kernel to its own system call |
| 123 | interface. It provides a kind of virtual machine, which runs Linux |
| 124 | as a user process under another Linux kernel. This is useful for |
| 125 | kernel development, sandboxes, jails, experimentation, and |
| 126 | many other things. |
| 127 | . |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | This package contains the Linux kernel, modules and corresponding other |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 129 | files version $version |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | EOF |
| 131 | |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 132 | else |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 133 | cat <<EOF >> debian/control |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 134 | |
| 135 | Package: $packagename |
bugme-daemon@bugzilla.kernel.org | 6f67a00 | 2007-08-29 07:57:41 -0700 | [diff] [blame] | 136 | Provides: kernel-image-$version, linux-image-$version |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 137 | Suggests: $fwpackagename |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 138 | Architecture: any |
| 139 | Description: Linux kernel, version $version |
| 140 | This package contains the Linux kernel, modules and corresponding other |
| 141 | files version $version |
| 142 | EOF |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 143 | |
Sam Ravnborg | dc5962f | 2005-07-14 20:24:56 +0000 | [diff] [blame] | 144 | fi |
| 145 | |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 146 | # Do we have firmware? Move it out of the way and build it into a package. |
| 147 | if [ -e "$tmpdir/lib/firmware" ]; then |
| 148 | mv "$tmpdir/lib/firmware" "$fwdir/lib/" |
| 149 | |
| 150 | cat <<EOF >> debian/control |
| 151 | |
| 152 | Package: $fwpackagename |
| 153 | Architecture: all |
| 154 | Description: Linux kernel firmware, version $version |
| 155 | This package contains firmware from the Linux kernel, version $version |
| 156 | EOF |
| 157 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 158 | create_package "$fwpackagename" "$fwdir" |
Jonathan McDowell | bf1b364 | 2008-09-13 17:08:31 +0100 | [diff] [blame] | 159 | fi |
| 160 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 161 | create_package "$packagename" "$tmpdir" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | exit 0 |