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 9fe233cb6SFrans Pop# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location 10fe233cb6SFrans Pop# specified in KDEB_HOOKDIR) that will be called on package install and 11fe233cb6SFrans Pop# removal. 121da177e4SLinus Torvalds 131da177e4SLinus Torvaldsset -e 141da177e4SLinus Torvalds 153e2ab256SFrans Popcreate_package() { 163e2ab256SFrans Pop local pname="$1" pdir="$2" 173e2ab256SFrans Pop 183e2ab256SFrans Pop # Fix ownership and permissions 193e2ab256SFrans Pop chown -R root:root "$pdir" 203e2ab256SFrans Pop chmod -R go-w "$pdir" 213e2ab256SFrans Pop 223e2ab256SFrans Pop # Create the package 233e2ab256SFrans Pop dpkg-gencontrol -isp -p$pname -P"$pdir" 243e2ab256SFrans Pop dpkg --build "$pdir" .. 253e2ab256SFrans Pop} 263e2ab256SFrans Pop 271da177e4SLinus Torvalds# Some variables and settings used throughout the script 281da177e4SLinus Torvaldsversion=$KERNELRELEASE 294f66199bSFrans Poprevision=$(cat .version) 30c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then 31c72c75dbSFrans Pop packageversion=$KDEB_PKGVERSION 32c72c75dbSFrans Popelse 33c72c75dbSFrans Pop packageversion=$version-$revision 34c72c75dbSFrans Popfi 351da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp" 36bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp" 37687c3dacSSam Ravnborgpackagename=linux-$version 38bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image 39687c3dacSSam Ravnborg 404f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 41687c3dacSSam Ravnborg packagename=user-mode-linux-$version 42687c3dacSSam Ravnborgfi 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds# Setup the directory structure 45bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir" 461da177e4SLinus Torvaldsmkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" 47bf1b3644SJonathan McDowellmkdir -p "$fwdir/DEBIAN" "$fwdir/lib" 484f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 49687c3dacSSam Ravnborg mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin" 50687c3dacSSam Ravnborgfi 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds# Build and install the kernel 534f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 54687c3dacSSam Ravnborg $MAKE linux 55687c3dacSSam Ravnborg cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" 56687c3dacSSam Ravnborg cp .config "$tmpdir/usr/share/doc/$packagename/config" 57687c3dacSSam Ravnborg gzip "$tmpdir/usr/share/doc/$packagename/config" 58687c3dacSSam Ravnborg cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" 59687c3dacSSam Ravnborgelse 601da177e4SLinus Torvalds cp System.map "$tmpdir/boot/System.map-$version" 611da177e4SLinus Torvalds cp .config "$tmpdir/boot/config-$version" 62a89b433bSFrans Pop # Not all arches include the boot path in KBUILD_IMAGE 63a89b433bSFrans Pop if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then 64a89b433bSFrans Pop cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 65a89b433bSFrans Pop fi 66687c3dacSSam Ravnborgfi 671da177e4SLinus Torvalds 681da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then 69a91f98a2SSam Ravnborg INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 704f66199bSFrans Pop if [ "$ARCH" = "um" ] ; then 71687c3dacSSam Ravnborg mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 72687c3dacSSam Ravnborg rmdir "$tmpdir/lib/modules/$version" 73687c3dacSSam Ravnborg fi 741da177e4SLinus Torvaldsfi 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds# Install the maintainer scripts 77fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian 78fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg 79fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel} 801da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do 81fe233cb6SFrans Pop mkdir -p "$tmpdir$debhookdir/$script.d" 821da177e4SLinus Torvalds cat <<EOF > "$tmpdir/DEBIAN/$script" 831da177e4SLinus Torvalds#!/bin/sh 841da177e4SLinus Torvalds 851da177e4SLinus Torvaldsset -e 861da177e4SLinus Torvalds 874964451aSFrans Pop# Pass maintainer script parameters to hook scripts 884964451aSFrans Popexport DEB_MAINT_PARAMS="\$@" 894964451aSFrans Pop 90fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d 911da177e4SLinus Torvaldsexit 0 921da177e4SLinus TorvaldsEOF 931da177e4SLinus Torvalds chmod 755 "$tmpdir/DEBIAN/$script" 941da177e4SLinus Torvaldsdone 951da177e4SLinus Torvalds 961da177e4SLinus Torvaldsname="Kernel Compiler <$(id -nu)@$(hostname -f)>" 971da177e4SLinus Torvalds# Generate a simple changelog template 981da177e4SLinus Torvaldscat <<EOF > debian/changelog 99c72c75dbSFrans Poplinux ($packageversion) unstable; urgency=low 1001da177e4SLinus Torvalds 101a83ca277SFrans Pop * Custom built Linux kernel. 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds -- $name $(date -R) 1041da177e4SLinus TorvaldsEOF 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds# Generate a control file 1071da177e4SLinus Torvaldscat <<EOF > debian/control 1081da177e4SLinus TorvaldsSource: linux 1091da177e4SLinus TorvaldsSection: base 1101da177e4SLinus TorvaldsPriority: optional 1111da177e4SLinus TorvaldsMaintainer: $name 1121da177e4SLinus TorvaldsStandards-Version: 3.6.1 1133e2ab256SFrans PopEOF 1143e2ab256SFrans Pop 1153e2ab256SFrans Popif [ "$ARCH" = "um" ]; then 1163e2ab256SFrans Pop cat <<EOF >> debian/control 1171da177e4SLinus Torvalds 118687c3dacSSam RavnborgPackage: $packagename 1196f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 1201da177e4SLinus TorvaldsArchitecture: any 121dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version 122dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call 123dc5962fdSSam Ravnborg interface. It provides a kind of virtual machine, which runs Linux 124dc5962fdSSam Ravnborg as a user process under another Linux kernel. This is useful for 125dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and 126dc5962fdSSam Ravnborg many other things. 127dc5962fdSSam Ravnborg . 1281da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other 129a83ca277SFrans Pop files, version: $version. 1301da177e4SLinus TorvaldsEOF 1311da177e4SLinus Torvalds 132dc5962fdSSam Ravnborgelse 1333e2ab256SFrans Pop cat <<EOF >> debian/control 134dc5962fdSSam Ravnborg 135dc5962fdSSam RavnborgPackage: $packagename 1366f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 137bf1b3644SJonathan McDowellSuggests: $fwpackagename 138dc5962fdSSam RavnborgArchitecture: any 139dc5962fdSSam RavnborgDescription: Linux kernel, version $version 140dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other 141a83ca277SFrans Pop files, version: $version. 142dc5962fdSSam RavnborgEOF 1434f66199bSFrans Pop 144dc5962fdSSam Ravnborgfi 145dc5962fdSSam Ravnborg 146bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package. 147bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then 148bf1b3644SJonathan McDowell mv "$tmpdir/lib/firmware" "$fwdir/lib/" 149bf1b3644SJonathan McDowell 150bf1b3644SJonathan McDowell cat <<EOF >> debian/control 151bf1b3644SJonathan McDowell 152bf1b3644SJonathan McDowellPackage: $fwpackagename 153bf1b3644SJonathan McDowellArchitecture: all 154bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version 155a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version. 156bf1b3644SJonathan McDowellEOF 157bf1b3644SJonathan McDowell 1583e2ab256SFrans Pop create_package "$fwpackagename" "$fwdir" 159bf1b3644SJonathan McDowellfi 160bf1b3644SJonathan McDowell 1613e2ab256SFrans Popcreate_package "$packagename" "$tmpdir" 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvaldsexit 0 164