builddeb 5.7 KB

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