11da177e4SLinus Torvalds#!/bin/sh 21da177e4SLinus Torvalds# 34964451aSFrans Pop# builddeb 1.3 41da177e4SLinus Torvalds# Copyright 2003 Wichert Akkerman <wichert@wiggy.net> 51da177e4SLinus Torvalds# 61da177e4SLinus Torvalds# Simple script to generate a deb package for a Linux kernel. All the 74f66199bSFrans Pop# complexity of what to do with a kernel after it is installed or removed 81da177e4SLinus Torvalds# is left to other scripts and packages: they can install scripts in the 91da177e4SLinus Torvalds# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on 101da177e4SLinus Torvalds# package install and removal. 111da177e4SLinus Torvalds 121da177e4SLinus Torvaldsset -e 131da177e4SLinus Torvalds 143e2ab256SFrans Popcreate_package() { 153e2ab256SFrans Pop local pname="$1" pdir="$2" 163e2ab256SFrans Pop 173e2ab256SFrans Pop # Fix ownership and permissions 183e2ab256SFrans Pop chown -R root:root "$pdir" 193e2ab256SFrans Pop chmod -R go-w "$pdir" 203e2ab256SFrans Pop 213e2ab256SFrans Pop # Create the package 223e2ab256SFrans Pop dpkg-gencontrol -isp -p$pname -P"$pdir" 233e2ab256SFrans Pop dpkg --build "$pdir" .. 243e2ab256SFrans Pop} 253e2ab256SFrans Pop 261da177e4SLinus Torvalds# Some variables and settings used throughout the script 271da177e4SLinus Torvaldsversion=$KERNELRELEASE 284f66199bSFrans Poprevision=$(cat .version) 29c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then 30c72c75dbSFrans Pop packageversion=$KDEB_PKGVERSION 31c72c75dbSFrans Popelse 32c72c75dbSFrans Pop packageversion=$version-$revision 33c72c75dbSFrans Popfi 341da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp" 35bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp" 36687c3dacSSam Ravnborgpackagename=linux-$version 37bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image 38687c3dacSSam Ravnborg 394f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 40687c3dacSSam Ravnborg packagename=user-mode-linux-$version 41687c3dacSSam Ravnborgfi 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds# Setup the directory structure 44bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir" 451da177e4SLinus Torvaldsmkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" 46bf1b3644SJonathan McDowellmkdir -p "$fwdir/DEBIAN" "$fwdir/lib" 474f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 48687c3dacSSam Ravnborg mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin" 49687c3dacSSam Ravnborgfi 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds# Build and install the kernel 524f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 53687c3dacSSam Ravnborg $MAKE linux 54687c3dacSSam Ravnborg cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" 55687c3dacSSam Ravnborg cp .config "$tmpdir/usr/share/doc/$packagename/config" 56687c3dacSSam Ravnborg gzip "$tmpdir/usr/share/doc/$packagename/config" 57687c3dacSSam Ravnborg cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" 58687c3dacSSam Ravnborgelse 591da177e4SLinus Torvalds cp System.map "$tmpdir/boot/System.map-$version" 601da177e4SLinus Torvalds cp .config "$tmpdir/boot/config-$version" 61a89b433bSFrans Pop # Not all arches include the boot path in KBUILD_IMAGE 62a89b433bSFrans Pop if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then 63a89b433bSFrans Pop cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 64a89b433bSFrans Pop fi 65687c3dacSSam Ravnborgfi 661da177e4SLinus Torvalds 671da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then 68a91f98a2SSam Ravnborg INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 694f66199bSFrans Pop if [ "$ARCH" = "um" ] ; then 70687c3dacSSam Ravnborg mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 71687c3dacSSam Ravnborg rmdir "$tmpdir/lib/modules/$version" 72687c3dacSSam Ravnborg fi 731da177e4SLinus Torvaldsfi 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds# Install the maintainer scripts 761da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do 771da177e4SLinus Torvalds mkdir -p "$tmpdir/etc/kernel/$script.d" 781da177e4SLinus Torvalds cat <<EOF > "$tmpdir/DEBIAN/$script" 791da177e4SLinus Torvalds#!/bin/sh 801da177e4SLinus Torvalds 811da177e4SLinus Torvaldsset -e 821da177e4SLinus Torvalds 834964451aSFrans Pop# Pass maintainer script parameters to hook scripts 844964451aSFrans Popexport DEB_MAINT_PARAMS="\$@" 854964451aSFrans Pop 861da177e4SLinus Torvaldstest -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d 871da177e4SLinus Torvaldsexit 0 881da177e4SLinus TorvaldsEOF 891da177e4SLinus Torvalds chmod 755 "$tmpdir/DEBIAN/$script" 901da177e4SLinus Torvaldsdone 911da177e4SLinus Torvalds 921da177e4SLinus Torvaldsname="Kernel Compiler <$(id -nu)@$(hostname -f)>" 931da177e4SLinus Torvalds# Generate a simple changelog template 941da177e4SLinus Torvaldscat <<EOF > debian/changelog 95c72c75dbSFrans Poplinux ($packageversion) unstable; urgency=low 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds * A standard release 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds -- $name $(date -R) 1001da177e4SLinus TorvaldsEOF 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds# Generate a control file 1031da177e4SLinus Torvaldscat <<EOF > debian/control 1041da177e4SLinus TorvaldsSource: linux 1051da177e4SLinus TorvaldsSection: base 1061da177e4SLinus TorvaldsPriority: optional 1071da177e4SLinus TorvaldsMaintainer: $name 1081da177e4SLinus TorvaldsStandards-Version: 3.6.1 1093e2ab256SFrans PopEOF 1103e2ab256SFrans Pop 1113e2ab256SFrans Popif [ "$ARCH" = "um" ]; then 1123e2ab256SFrans Pop cat <<EOF >> debian/control 1131da177e4SLinus Torvalds 114687c3dacSSam RavnborgPackage: $packagename 1156f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 1161da177e4SLinus TorvaldsArchitecture: any 117dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version 118dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call 119dc5962fdSSam Ravnborg interface. It provides a kind of virtual machine, which runs Linux 120dc5962fdSSam Ravnborg as a user process under another Linux kernel. This is useful for 121dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and 122dc5962fdSSam Ravnborg many other things. 123dc5962fdSSam Ravnborg . 1241da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other 125dc5962fdSSam Ravnborg files version $version 1261da177e4SLinus TorvaldsEOF 1271da177e4SLinus Torvalds 128dc5962fdSSam Ravnborgelse 1293e2ab256SFrans Pop cat <<EOF >> debian/control 130dc5962fdSSam Ravnborg 131dc5962fdSSam RavnborgPackage: $packagename 1326f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 133bf1b3644SJonathan McDowellSuggests: $fwpackagename 134dc5962fdSSam RavnborgArchitecture: any 135dc5962fdSSam RavnborgDescription: Linux kernel, version $version 136dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other 137dc5962fdSSam Ravnborg files version $version 138dc5962fdSSam RavnborgEOF 1394f66199bSFrans Pop 140dc5962fdSSam Ravnborgfi 141dc5962fdSSam Ravnborg 142bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package. 143bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then 144bf1b3644SJonathan McDowell mv "$tmpdir/lib/firmware" "$fwdir/lib/" 145bf1b3644SJonathan McDowell 146bf1b3644SJonathan McDowell cat <<EOF >> debian/control 147bf1b3644SJonathan McDowell 148bf1b3644SJonathan McDowellPackage: $fwpackagename 149bf1b3644SJonathan McDowellArchitecture: all 150bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version 151bf1b3644SJonathan McDowell This package contains firmware from the Linux kernel, version $version 152bf1b3644SJonathan McDowellEOF 153bf1b3644SJonathan McDowell 1543e2ab256SFrans Pop create_package "$fwpackagename" "$fwdir" 155bf1b3644SJonathan McDowellfi 156bf1b3644SJonathan McDowell 1573e2ab256SFrans Popcreate_package "$packagename" "$tmpdir" 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvaldsexit 0 160