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 12set -e 13 14# Some variables and settings used throughout the script 15version=$KERNELRELEASE 16revision=`cat .version` 17tmpdir="$objtree/debian/tmp" 18packagename=linux-$version 19 20if [ "$ARCH" == "um" ] ; then 21 packagename=user-mode-linux-$version 22fi 23 24# Setup the directory structure 25rm -rf "$tmpdir" 26mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" 27if [ "$ARCH" == "um" ] ; then 28 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin" 29fi 30 31# Build and install the kernel 32if [ "$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" 38else 39 cp System.map "$tmpdir/boot/System.map-$version" 40 cp .config "$tmpdir/boot/config-$version" 41 cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 42fi 43 44if grep -q '^CONFIG_MODULES=y' .config ; then 45 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 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 50fi 51 52# Install the maintainer scripts 53for 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 58set -e 59 60test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d 61exit 0 62EOF 63 chmod 755 "$tmpdir/DEBIAN/$script" 64done 65 66name="Kernel Compiler <$(id -nu)@$(hostname -f)>" 67# Generate a simple changelog template 68cat <<EOF > debian/changelog 69linux ($version-$revision) unstable; urgency=low 70 71 * A standard release 72 73 -- $name $(date -R) 74EOF 75 76# Generate a control file 77if [ "$ARCH" == "um" ]; then 78 79cat <<EOF > debian/control 80Source: linux 81Section: base 82Priority: optional 83Maintainer: $name 84Standards-Version: 3.6.1 85 86Package: $packagename 87Provides: kernel-image-$version, linux-image-$version 88Architecture: any 89Description: 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 . 96 This package contains the Linux kernel, modules and corresponding other 97 files version $version 98EOF 99 100else 101cat <<EOF > debian/control 102Source: linux 103Section: base 104Priority: optional 105Maintainer: $name 106Standards-Version: 3.6.1 107 108Package: $packagename 109Provides: kernel-image-$version, linux-image-$version 110Architecture: any 111Description: Linux kernel, version $version 112 This package contains the Linux kernel, modules and corresponding other 113 files version $version 114EOF 115fi 116 117# Fix some ownership and permissions 118chown -R root:root "$tmpdir" 119chmod -R go-w "$tmpdir" 120 121# Perform the final magic 122dpkg-gencontrol -isp 123dpkg --build "$tmpdir" .. 124 125exit 0 126 127