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