Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #!/bin/sh |
2 | # | |
4964451a | 3 | # builddeb 1.3 |
1da177e4 LT |
4 | # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> |
5 | # | |
6 | # Simple script to generate a deb package for a Linux kernel. All the | |
4f66199b | 7 | # complexity of what to do with a kernel after it is installed or removed |
1da177e4 | 8 | # is left to other scripts and packages: they can install scripts in the |
fe233cb6 FP |
9 | # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location |
10 | # specified in KDEB_HOOKDIR) that will be called on package install and | |
11 | # removal. | |
1da177e4 LT |
12 | |
13 | set -e | |
14 | ||
3e2ab256 FP |
15 | create_package() { |
16 | local pname="$1" pdir="$2" | |
17 | ||
9461f666 | 18 | cp debian/copyright "$pdir/usr/share/doc/$pname/" |
1ab18486 | 19 | cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" |
20 | gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" | |
b59a1225 FJ |
21 | sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ |
22 | | xargs -r0 md5sum > DEBIAN/md5sums" | |
9461f666 | 23 | |
3e2ab256 FP |
24 | # Fix ownership and permissions |
25 | chown -R root:root "$pdir" | |
26 | chmod -R go-w "$pdir" | |
27 | ||
28 | # Create the package | |
29 | dpkg-gencontrol -isp -p$pname -P"$pdir" | |
30 | dpkg --build "$pdir" .. | |
31 | } | |
32 | ||
1da177e4 LT |
33 | # Some variables and settings used throughout the script |
34 | version=$KERNELRELEASE | |
4f66199b | 35 | revision=$(cat .version) |
c72c75db FP |
36 | if [ -n "$KDEB_PKGVERSION" ]; then |
37 | packageversion=$KDEB_PKGVERSION | |
38 | else | |
39 | packageversion=$version-$revision | |
40 | fi | |
1da177e4 | 41 | tmpdir="$objtree/debian/tmp" |
bf1b3644 | 42 | fwdir="$objtree/debian/fwtmp" |
f7a2c31f | 43 | packagename=linux-image-$version |
bf1b3644 | 44 | fwpackagename=linux-firmware-image |
687c3dac | 45 | |
4f66199b | 46 | if [ "$ARCH" = "um" ] ; then |
687c3dac SR |
47 | packagename=user-mode-linux-$version |
48 | fi | |
1da177e4 LT |
49 | |
50 | # Setup the directory structure | |
bf1b3644 | 51 | rm -rf "$tmpdir" "$fwdir" |
9461f666 FP |
52 | mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" |
53 | mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" | |
4f66199b | 54 | if [ "$ARCH" = "um" ] ; then |
9461f666 | 55 | mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" |
687c3dac | 56 | fi |
1da177e4 LT |
57 | |
58 | # Build and install the kernel | |
4f66199b | 59 | if [ "$ARCH" = "um" ] ; then |
687c3dac SR |
60 | $MAKE linux |
61 | cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" | |
62 | cp .config "$tmpdir/usr/share/doc/$packagename/config" | |
63 | gzip "$tmpdir/usr/share/doc/$packagename/config" | |
64 | cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" | |
65 | else | |
66 | cp System.map "$tmpdir/boot/System.map-$version" | |
67 | cp .config "$tmpdir/boot/config-$version" | |
a89b433b FP |
68 | # Not all arches include the boot path in KBUILD_IMAGE |
69 | if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then | |
70 | cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" | |
71 | fi | |
687c3dac | 72 | fi |
1da177e4 LT |
73 | |
74 | if grep -q '^CONFIG_MODULES=y' .config ; then | |
a91f98a2 | 75 | INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install |
4f66199b | 76 | if [ "$ARCH" = "um" ] ; then |
687c3dac SR |
77 | mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" |
78 | rmdir "$tmpdir/lib/modules/$version" | |
79 | fi | |
1da177e4 LT |
80 | fi |
81 | ||
82 | # Install the maintainer scripts | |
fe233cb6 FP |
83 | # Note: hook scripts under /etc/kernel are also executed by official Debian |
84 | # kernel packages, as well as kernel packages built using make-kpkg | |
85 | debhookdir=${KDEB_HOOKDIR:-/etc/kernel} | |
1da177e4 | 86 | for script in postinst postrm preinst prerm ; do |
fe233cb6 | 87 | mkdir -p "$tmpdir$debhookdir/$script.d" |
1da177e4 LT |
88 | cat <<EOF > "$tmpdir/DEBIAN/$script" |
89 | #!/bin/sh | |
90 | ||
91 | set -e | |
92 | ||
4964451a | 93 | # Pass maintainer script parameters to hook scripts |
241ad11f | 94 | export DEB_MAINT_PARAMS="\$*" |
4964451a | 95 | |
fe233cb6 | 96 | test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d |
1da177e4 LT |
97 | exit 0 |
98 | EOF | |
99 | chmod 755 "$tmpdir/DEBIAN/$script" | |
100 | done | |
101 | ||
edec611d | 102 | # Try to determine maintainer and email values |
103 | if [ -n "$DEBEMAIL" ]; then | |
104 | email=$DEBEMAIL | |
105 | elif [ -n "$EMAIL" ]; then | |
106 | email=$EMAIL | |
107 | else | |
108 | email=$(id -nu)@$(hostname -f) | |
109 | fi | |
110 | if [ -n "$DEBFULLNAME" ]; then | |
111 | name=$DEBFULLNAME | |
112 | elif [ -n "$NAME" ]; then | |
113 | name=$NAME | |
114 | else | |
115 | name="Anonymous" | |
116 | fi | |
117 | maintainer="$name <$email>" | |
118 | ||
1da177e4 LT |
119 | # Generate a simple changelog template |
120 | cat <<EOF > debian/changelog | |
4bf4cd49 | 121 | linux-upstream ($packageversion) unstable; urgency=low |
1da177e4 | 122 | |
a83ca277 | 123 | * Custom built Linux kernel. |
1da177e4 | 124 | |
edec611d | 125 | -- $maintainer $(date -R) |
1da177e4 LT |
126 | EOF |
127 | ||
9461f666 FP |
128 | # Generate copyright file |
129 | cat <<EOF > debian/copyright | |
130 | This is a packacked upstream version of the Linux kernel. | |
131 | ||
132 | The sources may be found at most Linux ftp sites, including: | |
133 | ftp://ftp.kernel.org/pub/linux/kernel | |
134 | ||
135 | Copyright: 1991 - 2009 Linus Torvalds and others. | |
136 | ||
137 | The git repository for mainline kernel development is at: | |
138 | git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git | |
139 | ||
140 | This program is free software; you can redistribute it and/or modify | |
141 | it under the terms of the GNU General Public License as published by | |
142 | the Free Software Foundation; version 2 dated June, 1991. | |
143 | ||
144 | On Debian GNU/Linux systems, the complete text of the GNU General Public | |
145 | License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. | |
146 | EOF | |
147 | ||
1da177e4 | 148 | # Generate a control file |
3e2ab256 | 149 | cat <<EOF > debian/control |
4bf4cd49 | 150 | Source: linux-upstream |
54c33556 | 151 | Section: admin |
dc5962fd | 152 | Priority: optional |
edec611d | 153 | Maintainer: $maintainer |
2d7204ac | 154 | Standards-Version: 3.8.4 |
ee6eed80 | 155 | Homepage: http://www.kernel.org/ |
3e2ab256 FP |
156 | EOF |
157 | ||
158 | if [ "$ARCH" = "um" ]; then | |
159 | cat <<EOF >> debian/control | |
dc5962fd SR |
160 | |
161 | Package: $packagename | |
8ebc2fe9 | 162 | Provides: linux-image, linux-image-2.6, linux-modules-$version |
dc5962fd SR |
163 | Architecture: any |
164 | Description: User Mode Linux kernel, version $version | |
165 | User-mode Linux is a port of the Linux kernel to its own system call | |
166 | interface. It provides a kind of virtual machine, which runs Linux | |
167 | as a user process under another Linux kernel. This is useful for | |
168 | kernel development, sandboxes, jails, experimentation, and | |
169 | many other things. | |
170 | . | |
171 | This package contains the Linux kernel, modules and corresponding other | |
a83ca277 | 172 | files, version: $version. |
dc5962fd SR |
173 | EOF |
174 | ||
175 | else | |
3e2ab256 | 176 | cat <<EOF >> debian/control |
1da177e4 | 177 | |
687c3dac | 178 | Package: $packagename |
8ebc2fe9 | 179 | Provides: linux-image, linux-image-2.6, linux-modules-$version |
bf1b3644 | 180 | Suggests: $fwpackagename |
1da177e4 | 181 | Architecture: any |
dc5962fd | 182 | Description: Linux kernel, version $version |
1da177e4 | 183 | This package contains the Linux kernel, modules and corresponding other |
a83ca277 | 184 | files, version: $version. |
1da177e4 | 185 | EOF |
4f66199b | 186 | |
dc5962fd | 187 | fi |
1da177e4 | 188 | |
bf1b3644 JM |
189 | # Do we have firmware? Move it out of the way and build it into a package. |
190 | if [ -e "$tmpdir/lib/firmware" ]; then | |
191 | mv "$tmpdir/lib/firmware" "$fwdir/lib/" | |
192 | ||
193 | cat <<EOF >> debian/control | |
194 | ||
195 | Package: $fwpackagename | |
196 | Architecture: all | |
197 | Description: Linux kernel firmware, version $version | |
a83ca277 | 198 | This package contains firmware from the Linux kernel, version $version. |
bf1b3644 JM |
199 | EOF |
200 | ||
3e2ab256 | 201 | create_package "$fwpackagename" "$fwdir" |
bf1b3644 JM |
202 | fi |
203 | ||
3e2ab256 | 204 | create_package "$packagename" "$tmpdir" |
1da177e4 LT |
205 | |
206 | exit 0 |