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 189461f666SFrans Pop cp debian/copyright "$pdir/usr/share/doc/$pname/" 199461f666SFrans Pop 203e2ab256SFrans Pop # Fix ownership and permissions 213e2ab256SFrans Pop chown -R root:root "$pdir" 223e2ab256SFrans Pop chmod -R go-w "$pdir" 233e2ab256SFrans Pop 243e2ab256SFrans Pop # Create the package 253e2ab256SFrans Pop dpkg-gencontrol -isp -p$pname -P"$pdir" 263e2ab256SFrans Pop dpkg --build "$pdir" .. 273e2ab256SFrans Pop} 283e2ab256SFrans Pop 291da177e4SLinus Torvalds# Some variables and settings used throughout the script 301da177e4SLinus Torvaldsversion=$KERNELRELEASE 314f66199bSFrans Poprevision=$(cat .version) 32c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then 33c72c75dbSFrans Pop packageversion=$KDEB_PKGVERSION 34c72c75dbSFrans Popelse 35c72c75dbSFrans Pop packageversion=$version-$revision 36c72c75dbSFrans Popfi 371da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp" 38bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp" 39687c3dacSSam Ravnborgpackagename=linux-$version 40bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image 41687c3dacSSam Ravnborg 424f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 43687c3dacSSam Ravnborg packagename=user-mode-linux-$version 44687c3dacSSam Ravnborgfi 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds# Setup the directory structure 47bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir" 489461f666SFrans Popmkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" 499461f666SFrans Popmkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" 504f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 519461f666SFrans Pop mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" 52687c3dacSSam Ravnborgfi 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds# Build and install the kernel 554f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 56687c3dacSSam Ravnborg $MAKE linux 57687c3dacSSam Ravnborg cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" 58687c3dacSSam Ravnborg cp .config "$tmpdir/usr/share/doc/$packagename/config" 59687c3dacSSam Ravnborg gzip "$tmpdir/usr/share/doc/$packagename/config" 60687c3dacSSam Ravnborg cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" 61687c3dacSSam Ravnborgelse 621da177e4SLinus Torvalds cp System.map "$tmpdir/boot/System.map-$version" 631da177e4SLinus Torvalds cp .config "$tmpdir/boot/config-$version" 64a89b433bSFrans Pop # Not all arches include the boot path in KBUILD_IMAGE 65a89b433bSFrans Pop if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then 66a89b433bSFrans Pop cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 67a89b433bSFrans Pop fi 68687c3dacSSam Ravnborgfi 691da177e4SLinus Torvalds 701da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then 71a91f98a2SSam Ravnborg INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 724f66199bSFrans Pop if [ "$ARCH" = "um" ] ; then 73687c3dacSSam Ravnborg mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 74687c3dacSSam Ravnborg rmdir "$tmpdir/lib/modules/$version" 75687c3dacSSam Ravnborg fi 761da177e4SLinus Torvaldsfi 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds# Install the maintainer scripts 79fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian 80fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg 81fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel} 821da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do 83fe233cb6SFrans Pop mkdir -p "$tmpdir$debhookdir/$script.d" 841da177e4SLinus Torvalds cat <<EOF > "$tmpdir/DEBIAN/$script" 851da177e4SLinus Torvalds#!/bin/sh 861da177e4SLinus Torvalds 871da177e4SLinus Torvaldsset -e 881da177e4SLinus Torvalds 894964451aSFrans Pop# Pass maintainer script parameters to hook scripts 904964451aSFrans Popexport DEB_MAINT_PARAMS="\$@" 914964451aSFrans Pop 92fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d 931da177e4SLinus Torvaldsexit 0 941da177e4SLinus TorvaldsEOF 951da177e4SLinus Torvalds chmod 755 "$tmpdir/DEBIAN/$script" 961da177e4SLinus Torvaldsdone 971da177e4SLinus Torvalds 98edec611dSmaximilian attems# Try to determine maintainer and email values 99edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then 100edec611dSmaximilian attems email=$DEBEMAIL 101edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then 102edec611dSmaximilian attems email=$EMAIL 103edec611dSmaximilian attemselse 104edec611dSmaximilian attems email=$(id -nu)@$(hostname -f) 105edec611dSmaximilian attemsfi 106edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then 107edec611dSmaximilian attems name=$DEBFULLNAME 108edec611dSmaximilian attemselif [ -n "$NAME" ]; then 109edec611dSmaximilian attems name=$NAME 110edec611dSmaximilian attemselse 111edec611dSmaximilian attems name="Anonymous" 112edec611dSmaximilian attemsfi 113edec611dSmaximilian attemsmaintainer="$name <$email>" 114edec611dSmaximilian attems 1151da177e4SLinus Torvalds# Generate a simple changelog template 1161da177e4SLinus Torvaldscat <<EOF > debian/changelog 117c72c75dbSFrans Poplinux ($packageversion) unstable; urgency=low 1181da177e4SLinus Torvalds 119a83ca277SFrans Pop * Custom built Linux kernel. 1201da177e4SLinus Torvalds 121edec611dSmaximilian attems -- $maintainer $(date -R) 1221da177e4SLinus TorvaldsEOF 1231da177e4SLinus Torvalds 1249461f666SFrans Pop# Generate copyright file 1259461f666SFrans Popcat <<EOF > debian/copyright 1269461f666SFrans PopThis is a packacked upstream version of the Linux kernel. 1279461f666SFrans Pop 1289461f666SFrans PopThe sources may be found at most Linux ftp sites, including: 1299461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel 1309461f666SFrans Pop 1319461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others. 1329461f666SFrans Pop 1339461f666SFrans PopThe git repository for mainline kernel development is at: 1349461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 1359461f666SFrans Pop 1369461f666SFrans Pop This program is free software; you can redistribute it and/or modify 1379461f666SFrans Pop it under the terms of the GNU General Public License as published by 1389461f666SFrans Pop the Free Software Foundation; version 2 dated June, 1991. 1399461f666SFrans Pop 1409461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public 1419461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 1429461f666SFrans PopEOF 1439461f666SFrans Pop 1441da177e4SLinus Torvalds# Generate a control file 1451da177e4SLinus Torvaldscat <<EOF > debian/control 1461da177e4SLinus TorvaldsSource: linux 1471da177e4SLinus TorvaldsSection: base 1481da177e4SLinus TorvaldsPriority: optional 149edec611dSmaximilian attemsMaintainer: $maintainer 1501da177e4SLinus TorvaldsStandards-Version: 3.6.1 1513e2ab256SFrans PopEOF 1523e2ab256SFrans Pop 1533e2ab256SFrans Popif [ "$ARCH" = "um" ]; then 1543e2ab256SFrans Pop cat <<EOF >> debian/control 1551da177e4SLinus Torvalds 156687c3dacSSam RavnborgPackage: $packagename 1576f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 1581da177e4SLinus TorvaldsArchitecture: any 159dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version 160dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call 161dc5962fdSSam Ravnborg interface. It provides a kind of virtual machine, which runs Linux 162dc5962fdSSam Ravnborg as a user process under another Linux kernel. This is useful for 163dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and 164dc5962fdSSam Ravnborg many other things. 165dc5962fdSSam Ravnborg . 1661da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other 167a83ca277SFrans Pop files, version: $version. 1681da177e4SLinus TorvaldsEOF 1691da177e4SLinus Torvalds 170dc5962fdSSam Ravnborgelse 1713e2ab256SFrans Pop cat <<EOF >> debian/control 172dc5962fdSSam Ravnborg 173dc5962fdSSam RavnborgPackage: $packagename 1746f67a004Sbugme-daemon@bugzilla.kernel.orgProvides: kernel-image-$version, linux-image-$version 175bf1b3644SJonathan McDowellSuggests: $fwpackagename 176dc5962fdSSam RavnborgArchitecture: any 177dc5962fdSSam RavnborgDescription: Linux kernel, version $version 178dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other 179a83ca277SFrans Pop files, version: $version. 180dc5962fdSSam RavnborgEOF 1814f66199bSFrans Pop 182dc5962fdSSam Ravnborgfi 183dc5962fdSSam Ravnborg 184bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package. 185bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then 186bf1b3644SJonathan McDowell mv "$tmpdir/lib/firmware" "$fwdir/lib/" 187bf1b3644SJonathan McDowell 188bf1b3644SJonathan McDowell cat <<EOF >> debian/control 189bf1b3644SJonathan McDowell 190bf1b3644SJonathan McDowellPackage: $fwpackagename 191bf1b3644SJonathan McDowellArchitecture: all 192bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version 193a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version. 194bf1b3644SJonathan McDowellEOF 195bf1b3644SJonathan McDowell 1963e2ab256SFrans Pop create_package "$fwpackagename" "$fwdir" 197bf1b3644SJonathan McDowellfi 198bf1b3644SJonathan McDowell 1993e2ab256SFrans Popcreate_package "$packagename" "$tmpdir" 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvaldsexit 0 202