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