builddeb 5.9 KB

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