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/" 191ab18486Smaximilian attems cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" 201ab18486Smaximilian attems gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" 21b59a1225SFEJES Jozsef sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ 22b59a1225SFEJES Jozsef | xargs -r0 md5sum > DEBIAN/md5sums" 239461f666SFrans Pop 243e2ab256SFrans Pop # Fix ownership and permissions 253e2ab256SFrans Pop chown -R root:root "$pdir" 263e2ab256SFrans Pop chmod -R go-w "$pdir" 273e2ab256SFrans Pop 283e2ab256SFrans Pop # Create the package 293e2ab256SFrans Pop dpkg-gencontrol -isp -p$pname -P"$pdir" 303e2ab256SFrans Pop dpkg --build "$pdir" .. 313e2ab256SFrans Pop} 323e2ab256SFrans Pop 331da177e4SLinus Torvalds# Some variables and settings used throughout the script 341da177e4SLinus Torvaldsversion=$KERNELRELEASE 354f66199bSFrans Poprevision=$(cat .version) 36c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then 37c72c75dbSFrans Pop packageversion=$KDEB_PKGVERSION 38c72c75dbSFrans Popelse 39c72c75dbSFrans Pop packageversion=$version-$revision 40c72c75dbSFrans Popfi 411da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp" 42bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp" 43f7a2c31fSmaximilian attemspackagename=linux-image-$version 44bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image 45687c3dacSSam Ravnborg 464f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 47687c3dacSSam Ravnborg packagename=user-mode-linux-$version 48687c3dacSSam Ravnborgfi 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds# Setup the directory structure 51bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir" 52e86c2412Smaximilian attemsmkdir -m 755 -p "$tmpdir/DEBIAN" 53e86c2412Smaximilian attemsmkdir -p "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" 54e86c2412Smaximilian attemsmkdir -m 755 -p "$fwdir/DEBIAN" 55e86c2412Smaximilian attemsmkdir -p "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" 564f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 579461f666SFrans Pop mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" 58687c3dacSSam Ravnborgfi 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds# Build and install the kernel 614f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 62687c3dacSSam Ravnborg $MAKE linux 63687c3dacSSam Ravnborg cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" 64687c3dacSSam Ravnborg cp .config "$tmpdir/usr/share/doc/$packagename/config" 65687c3dacSSam Ravnborg gzip "$tmpdir/usr/share/doc/$packagename/config" 66687c3dacSSam Ravnborg cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" 67687c3dacSSam Ravnborgelse 681da177e4SLinus Torvalds cp System.map "$tmpdir/boot/System.map-$version" 691da177e4SLinus Torvalds cp .config "$tmpdir/boot/config-$version" 70a89b433bSFrans Pop # Not all arches include the boot path in KBUILD_IMAGE 71242c5ab0SGuillem Jover if [ -e $KBUILD_IMAGE ]; then 72242c5ab0SGuillem Jover cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 73242c5ab0SGuillem Jover else 74a89b433bSFrans Pop cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 75a89b433bSFrans Pop fi 76687c3dacSSam Ravnborgfi 771da177e4SLinus Torvalds 781da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then 79a91f98a2SSam Ravnborg INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 804f66199bSFrans Pop if [ "$ARCH" = "um" ] ; then 81687c3dacSSam Ravnborg mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 82687c3dacSSam Ravnborg rmdir "$tmpdir/lib/modules/$version" 83687c3dacSSam Ravnborg fi 841da177e4SLinus Torvaldsfi 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds# Install the maintainer scripts 87fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian 88fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg 89fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel} 901da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do 91fe233cb6SFrans Pop mkdir -p "$tmpdir$debhookdir/$script.d" 921da177e4SLinus Torvalds cat <<EOF > "$tmpdir/DEBIAN/$script" 931da177e4SLinus Torvalds#!/bin/sh 941da177e4SLinus Torvalds 951da177e4SLinus Torvaldsset -e 961da177e4SLinus Torvalds 974964451aSFrans Pop# Pass maintainer script parameters to hook scripts 98241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*" 994964451aSFrans Pop 100fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d 1011da177e4SLinus Torvaldsexit 0 1021da177e4SLinus TorvaldsEOF 1031da177e4SLinus Torvalds chmod 755 "$tmpdir/DEBIAN/$script" 1041da177e4SLinus Torvaldsdone 1051da177e4SLinus Torvalds 106edec611dSmaximilian attems# Try to determine maintainer and email values 107edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then 108edec611dSmaximilian attems email=$DEBEMAIL 109edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then 110edec611dSmaximilian attems email=$EMAIL 111edec611dSmaximilian attemselse 112edec611dSmaximilian attems email=$(id -nu)@$(hostname -f) 113edec611dSmaximilian attemsfi 114edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then 115edec611dSmaximilian attems name=$DEBFULLNAME 116edec611dSmaximilian attemselif [ -n "$NAME" ]; then 117edec611dSmaximilian attems name=$NAME 118edec611dSmaximilian attemselse 119edec611dSmaximilian attems name="Anonymous" 120edec611dSmaximilian attemsfi 121edec611dSmaximilian attemsmaintainer="$name <$email>" 122edec611dSmaximilian attems 1231da177e4SLinus Torvalds# Generate a simple changelog template 1241da177e4SLinus Torvaldscat <<EOF > debian/changelog 1254bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low 1261da177e4SLinus Torvalds 127a83ca277SFrans Pop * Custom built Linux kernel. 1281da177e4SLinus Torvalds 129edec611dSmaximilian attems -- $maintainer $(date -R) 1301da177e4SLinus TorvaldsEOF 1311da177e4SLinus Torvalds 1329461f666SFrans Pop# Generate copyright file 1339461f666SFrans Popcat <<EOF > debian/copyright 1349461f666SFrans PopThis is a packacked upstream version of the Linux kernel. 1359461f666SFrans Pop 1369461f666SFrans PopThe sources may be found at most Linux ftp sites, including: 1379461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel 1389461f666SFrans Pop 1399461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others. 1409461f666SFrans Pop 1419461f666SFrans PopThe git repository for mainline kernel development is at: 1429461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 1439461f666SFrans Pop 1449461f666SFrans Pop This program is free software; you can redistribute it and/or modify 1459461f666SFrans Pop it under the terms of the GNU General Public License as published by 1469461f666SFrans Pop the Free Software Foundation; version 2 dated June, 1991. 1479461f666SFrans Pop 1489461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public 1499461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 1509461f666SFrans PopEOF 1519461f666SFrans Pop 1521da177e4SLinus Torvalds# Generate a control file 1531da177e4SLinus Torvaldscat <<EOF > debian/control 1544bf4cd49SFrans PopSource: linux-upstream 155aa42abedSRogério BritoSection: kernel 1561da177e4SLinus TorvaldsPriority: optional 157edec611dSmaximilian attemsMaintainer: $maintainer 1582d7204acSRogério BritoStandards-Version: 3.8.4 159ee6eed80SRogério BritoHomepage: http://www.kernel.org/ 1603e2ab256SFrans PopEOF 1613e2ab256SFrans Pop 1623e2ab256SFrans Popif [ "$ARCH" = "um" ]; then 1633e2ab256SFrans Pop cat <<EOF >> debian/control 1641da177e4SLinus Torvalds 165687c3dacSSam RavnborgPackage: $packagename 1668ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version 1671da177e4SLinus TorvaldsArchitecture: any 168dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version 169dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call 170dc5962fdSSam Ravnborg interface. It provides a kind of virtual machine, which runs Linux 171dc5962fdSSam Ravnborg as a user process under another Linux kernel. This is useful for 172dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and 173dc5962fdSSam Ravnborg many other things. 174dc5962fdSSam Ravnborg . 1751da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other 176a83ca277SFrans Pop files, version: $version. 1771da177e4SLinus TorvaldsEOF 1781da177e4SLinus Torvalds 179dc5962fdSSam Ravnborgelse 1803e2ab256SFrans Pop cat <<EOF >> debian/control 181dc5962fdSSam Ravnborg 182dc5962fdSSam RavnborgPackage: $packagename 1838ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version 184bf1b3644SJonathan McDowellSuggests: $fwpackagename 185dc5962fdSSam RavnborgArchitecture: any 186dc5962fdSSam RavnborgDescription: Linux kernel, version $version 187dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other 188a83ca277SFrans Pop files, version: $version. 189dc5962fdSSam RavnborgEOF 1904f66199bSFrans Pop 191dc5962fdSSam Ravnborgfi 192dc5962fdSSam Ravnborg 193bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package. 194bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then 195bf1b3644SJonathan McDowell mv "$tmpdir/lib/firmware" "$fwdir/lib/" 196bf1b3644SJonathan McDowell 197bf1b3644SJonathan McDowell cat <<EOF >> debian/control 198bf1b3644SJonathan McDowell 199bf1b3644SJonathan McDowellPackage: $fwpackagename 200bf1b3644SJonathan McDowellArchitecture: all 201bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version 202a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version. 203bf1b3644SJonathan McDowellEOF 204bf1b3644SJonathan McDowell 2053e2ab256SFrans Pop create_package "$fwpackagename" "$fwdir" 206bf1b3644SJonathan McDowellfi 207bf1b3644SJonathan McDowell 2083e2ab256SFrans Popcreate_package "$packagename" "$tmpdir" 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvaldsexit 0 211