builddeb 4.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2
#!/bin/sh
#
3
# builddeb 1.3
L
Linus Torvalds 已提交
4 5 6
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
#
# 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 installed or removed
L
Linus Torvalds 已提交
8 9 10 11 12 13
# is left to other scripts and packages: they can install scripts in the
# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
# package install and removal.

set -e

14 15 16 17 18 19 20 21 22 23 24 25
create_package() {
	local pname="$1" pdir="$2"

	# Fix ownership and permissions
	chown -R root:root "$pdir"
	chmod -R go-w "$pdir"

	# Create the package
	dpkg-gencontrol -isp -p$pname -P"$pdir"
	dpkg --build "$pdir" ..
}

L
Linus Torvalds 已提交
26 27
# Some variables and settings used throughout the script
version=$KERNELRELEASE
28
revision=$(cat .version)
L
Linus Torvalds 已提交
29
tmpdir="$objtree/debian/tmp"
30
fwdir="$objtree/debian/fwtmp"
31
packagename=linux-$version
32
fwpackagename=linux-firmware-image
33

34
if [ "$ARCH" = "um" ] ; then
35 36
	packagename=user-mode-linux-$version
fi
L
Linus Torvalds 已提交
37 38

# Setup the directory structure
39
rm -rf "$tmpdir" "$fwdir"
L
Linus Torvalds 已提交
40
mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
41
mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
42
if [ "$ARCH" = "um" ] ; then
43 44
	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
fi
L
Linus Torvalds 已提交
45 46

# Build and install the kernel
47
if [ "$ARCH" = "um" ] ; then
48 49 50 51 52 53 54 55
	$MAKE linux
	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
	cp .config "$tmpdir/usr/share/doc/$packagename/config"
	gzip "$tmpdir/usr/share/doc/$packagename/config"
	cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
else 
	cp System.map "$tmpdir/boot/System.map-$version"
	cp .config "$tmpdir/boot/config-$version"
56 57 58 59
	# Not all arches include the boot path in KBUILD_IMAGE
	if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
	fi
60
fi
L
Linus Torvalds 已提交
61 62

if grep -q '^CONFIG_MODULES=y' .config ; then
63
	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
64
	if [ "$ARCH" = "um" ] ; then
65 66 67
		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
		rmdir "$tmpdir/lib/modules/$version"
	fi
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77
fi

# Install the maintainer scripts
for script in postinst postrm preinst prerm ; do
	mkdir -p "$tmpdir/etc/kernel/$script.d"
	cat <<EOF > "$tmpdir/DEBIAN/$script"
#!/bin/sh

set -e

78 79 80
# Pass maintainer script parameters to hook scripts
export DEB_MAINT_PARAMS="\$@"

L
Linus Torvalds 已提交
81 82 83 84 85 86 87 88 89
test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
exit 0
EOF
	chmod 755 "$tmpdir/DEBIAN/$script"
done

name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
# Generate a simple changelog template
cat <<EOF > debian/changelog
90
linux ($version-$revision) unstable; urgency=low
L
Linus Torvalds 已提交
91 92 93 94 95 96 97

  * A standard release

 -- $name  $(date -R)
EOF

# Generate a control file
98
cat <<EOF > debian/control
99 100 101 102 103
Source: linux
Section: base
Priority: optional
Maintainer: $name
Standards-Version: 3.6.1
104 105 106 107
EOF

if [ "$ARCH" = "um" ]; then
	cat <<EOF >> debian/control
108 109

Package: $packagename
110
Provides: kernel-image-$version, linux-image-$version
111 112 113 114 115 116 117 118 119 120 121 122 123
Architecture: any
Description: User Mode Linux kernel, version $version
 User-mode Linux is a port of the Linux kernel to its own system call
 interface.  It provides a kind of virtual machine, which runs Linux
 as a user process under another Linux kernel.  This is useful for
 kernel development, sandboxes, jails, experimentation, and
 many other things.
 .
 This package contains the Linux kernel, modules and corresponding other
 files version $version
EOF

else
124
	cat <<EOF >> debian/control
L
Linus Torvalds 已提交
125

126
Package: $packagename
127
Provides: kernel-image-$version, linux-image-$version
128
Suggests: $fwpackagename
L
Linus Torvalds 已提交
129
Architecture: any
130
Description: Linux kernel, version $version
L
Linus Torvalds 已提交
131
 This package contains the Linux kernel, modules and corresponding other
132
 files version $version
L
Linus Torvalds 已提交
133
EOF
134

135
fi
L
Linus Torvalds 已提交
136

137 138 139 140 141 142 143 144 145 146 147 148
# Do we have firmware? Move it out of the way and build it into a package.
if [ -e "$tmpdir/lib/firmware" ]; then
	mv "$tmpdir/lib/firmware" "$fwdir/lib/"

	cat <<EOF >> debian/control

Package: $fwpackagename
Architecture: all
Description: Linux kernel firmware, version $version
 This package contains firmware from the Linux kernel, version $version
EOF

149
	create_package "$fwpackagename" "$fwdir"
150 151
fi

152
create_package "$packagename" "$tmpdir"
L
Linus Torvalds 已提交
153 154

exit 0