builddeb 4.2 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)
29 30 31 32 33
if [ -n "$KDEB_PKGVERSION" ]; then
	packageversion=$KDEB_PKGVERSION
else
	packageversion=$version-$revision
fi
L
Linus Torvalds 已提交
34
tmpdir="$objtree/debian/tmp"
35
fwdir="$objtree/debian/fwtmp"
36
packagename=linux-$version
37
fwpackagename=linux-firmware-image
38

39
if [ "$ARCH" = "um" ] ; then
40 41
	packagename=user-mode-linux-$version
fi
L
Linus Torvalds 已提交
42 43

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

# Build and install the kernel
52
if [ "$ARCH" = "um" ] ; then
53 54 55 56 57 58 59 60
	$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"
61 62 63 64
	# 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
65
fi
L
Linus Torvalds 已提交
66 67

if grep -q '^CONFIG_MODULES=y' .config ; then
68
	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
69
	if [ "$ARCH" = "um" ] ; then
70 71 72
		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
		rmdir "$tmpdir/lib/modules/$version"
	fi
L
Linus Torvalds 已提交
73 74 75 76 77 78 79 80 81 82
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

83 84 85
# Pass maintainer script parameters to hook scripts
export DEB_MAINT_PARAMS="\$@"

L
Linus Torvalds 已提交
86 87 88 89 90 91 92 93 94
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
95
linux ($packageversion) unstable; urgency=low
L
Linus Torvalds 已提交
96 97 98 99 100 101 102

  * A standard release

 -- $name  $(date -R)
EOF

# Generate a control file
103
cat <<EOF > debian/control
104 105 106 107 108
Source: linux
Section: base
Priority: optional
Maintainer: $name
Standards-Version: 3.6.1
109 110 111 112
EOF

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

Package: $packagename
115
Provides: kernel-image-$version, linux-image-$version
116 117 118 119 120 121 122 123 124 125 126 127 128
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
129
	cat <<EOF >> debian/control
L
Linus Torvalds 已提交
130

131
Package: $packagename
132
Provides: kernel-image-$version, linux-image-$version
133
Suggests: $fwpackagename
L
Linus Torvalds 已提交
134
Architecture: any
135
Description: Linux kernel, version $version
L
Linus Torvalds 已提交
136
 This package contains the Linux kernel, modules and corresponding other
137
 files version $version
L
Linus Torvalds 已提交
138
EOF
139

140
fi
L
Linus Torvalds 已提交
141

142 143 144 145 146 147 148 149 150 151 152 153
# 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

154
	create_package "$fwpackagename" "$fwdir"
155 156
fi

157
create_package "$packagename" "$tmpdir"
L
Linus Torvalds 已提交
158 159

exit 0