builddeb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 that will be called on
  10. # package install and removal.
  11. set -e
  12. create_package() {
  13. local pname="$1" pdir="$2"
  14. # Fix ownership and permissions
  15. chown -R root:root "$pdir"
  16. chmod -R go-w "$pdir"
  17. # Create the package
  18. dpkg-gencontrol -isp -p$pname -P"$pdir"
  19. dpkg --build "$pdir" ..
  20. }
  21. # Some variables and settings used throughout the script
  22. version=$KERNELRELEASE
  23. revision=$(cat .version)
  24. if [ -n "$KDEB_PKGVERSION" ]; then
  25. packageversion=$KDEB_PKGVERSION
  26. else
  27. packageversion=$version-$revision
  28. fi
  29. tmpdir="$objtree/debian/tmp"
  30. fwdir="$objtree/debian/fwtmp"
  31. packagename=linux-$version
  32. fwpackagename=linux-firmware-image
  33. if [ "$ARCH" = "um" ] ; then
  34. packagename=user-mode-linux-$version
  35. fi
  36. # Setup the directory structure
  37. rm -rf "$tmpdir" "$fwdir"
  38. mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
  39. mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
  40. if [ "$ARCH" = "um" ] ; then
  41. mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
  42. fi
  43. # Build and install the kernel
  44. if [ "$ARCH" = "um" ] ; then
  45. $MAKE linux
  46. cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
  47. cp .config "$tmpdir/usr/share/doc/$packagename/config"
  48. gzip "$tmpdir/usr/share/doc/$packagename/config"
  49. cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
  50. else
  51. cp System.map "$tmpdir/boot/System.map-$version"
  52. cp .config "$tmpdir/boot/config-$version"
  53. # Not all arches include the boot path in KBUILD_IMAGE
  54. if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
  55. cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
  56. fi
  57. fi
  58. if grep -q '^CONFIG_MODULES=y' .config ; then
  59. INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
  60. if [ "$ARCH" = "um" ] ; then
  61. mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
  62. rmdir "$tmpdir/lib/modules/$version"
  63. fi
  64. fi
  65. # Install the maintainer scripts
  66. for script in postinst postrm preinst prerm ; do
  67. mkdir -p "$tmpdir/etc/kernel/$script.d"
  68. cat <<EOF > "$tmpdir/DEBIAN/$script"
  69. #!/bin/sh
  70. set -e
  71. # Pass maintainer script parameters to hook scripts
  72. export DEB_MAINT_PARAMS="\$@"
  73. test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
  74. exit 0
  75. EOF
  76. chmod 755 "$tmpdir/DEBIAN/$script"
  77. done
  78. name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
  79. # Generate a simple changelog template
  80. cat <<EOF > debian/changelog
  81. linux ($packageversion) unstable; urgency=low
  82. * A standard release
  83. -- $name $(date -R)
  84. EOF
  85. # Generate a control file
  86. cat <<EOF > debian/control
  87. Source: linux
  88. Section: base
  89. Priority: optional
  90. Maintainer: $name
  91. Standards-Version: 3.6.1
  92. EOF
  93. if [ "$ARCH" = "um" ]; then
  94. cat <<EOF >> debian/control
  95. Package: $packagename
  96. Provides: kernel-image-$version, linux-image-$version
  97. Architecture: any
  98. Description: User Mode Linux kernel, version $version
  99. User-mode Linux is a port of the Linux kernel to its own system call
  100. interface. It provides a kind of virtual machine, which runs Linux
  101. as a user process under another Linux kernel. This is useful for
  102. kernel development, sandboxes, jails, experimentation, and
  103. many other things.
  104. .
  105. This package contains the Linux kernel, modules and corresponding other
  106. files version $version
  107. EOF
  108. else
  109. cat <<EOF >> debian/control
  110. Package: $packagename
  111. Provides: kernel-image-$version, linux-image-$version
  112. Suggests: $fwpackagename
  113. Architecture: any
  114. Description: Linux kernel, version $version
  115. This package contains the Linux kernel, modules and corresponding other
  116. files version $version
  117. EOF
  118. fi
  119. # Do we have firmware? Move it out of the way and build it into a package.
  120. if [ -e "$tmpdir/lib/firmware" ]; then
  121. mv "$tmpdir/lib/firmware" "$fwdir/lib/"
  122. cat <<EOF >> debian/control
  123. Package: $fwpackagename
  124. Architecture: all
  125. Description: Linux kernel firmware, version $version
  126. This package contains firmware from the Linux kernel, version $version
  127. EOF
  128. create_package "$fwpackagename" "$fwdir"
  129. fi
  130. create_package "$packagename" "$tmpdir"
  131. exit 0