builddeb 5.6 KB

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