builddeb 3.9 KB

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