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