builddeb 5.9 KB

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