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