builddeb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 installer 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. # Some variables and settings used throughout the script
  13. version=$KERNELRELEASE
  14. tmpdir="$objtree/debian/tmp"
  15. packagename=linux-$version
  16. if [ "$ARCH" == "um" ] ; then
  17. packagename=user-mode-linux-$version
  18. fi
  19. # Setup the directory structure
  20. rm -rf "$tmpdir"
  21. mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
  22. if [ "$ARCH" == "um" ] ; then
  23. mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
  24. fi
  25. # Build and install the kernel
  26. if [ "$ARCH" == "um" ] ; then
  27. $MAKE linux
  28. cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
  29. cp .config "$tmpdir/usr/share/doc/$packagename/config"
  30. gzip "$tmpdir/usr/share/doc/$packagename/config"
  31. cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
  32. else
  33. cp System.map "$tmpdir/boot/System.map-$version"
  34. cp .config "$tmpdir/boot/config-$version"
  35. cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
  36. fi
  37. if grep -q '^CONFIG_MODULES=y' .config ; then
  38. INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
  39. if [ "$ARCH" == "um" ] ; then
  40. mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
  41. rmdir "$tmpdir/lib/modules/$version"
  42. fi
  43. fi
  44. # Install the maintainer scripts
  45. for script in postinst postrm preinst prerm ; do
  46. mkdir -p "$tmpdir/etc/kernel/$script.d"
  47. cat <<EOF > "$tmpdir/DEBIAN/$script"
  48. #!/bin/sh
  49. set -e
  50. test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
  51. exit 0
  52. EOF
  53. chmod 755 "$tmpdir/DEBIAN/$script"
  54. done
  55. name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
  56. # Generate a simple changelog template
  57. cat <<EOF > debian/changelog
  58. linux ($version) unstable; urgency=low
  59. * A standard release
  60. -- $name $(date -R)
  61. EOF
  62. # Generate a control file
  63. if [ "$ARCH" == "um" ]; then
  64. cat <<EOF > debian/control
  65. Source: linux
  66. Section: base
  67. Priority: optional
  68. Maintainer: $name
  69. Standards-Version: 3.6.1
  70. Package: $packagename
  71. Provides: kernel-image-$version, linux-image-$version
  72. Architecture: any
  73. Description: User Mode Linux kernel, version $version
  74. User-mode Linux is a port of the Linux kernel to its own system call
  75. interface. It provides a kind of virtual machine, which runs Linux
  76. as a user process under another Linux kernel. This is useful for
  77. kernel development, sandboxes, jails, experimentation, and
  78. many other things.
  79. .
  80. This package contains the Linux kernel, modules and corresponding other
  81. files version $version
  82. EOF
  83. else
  84. cat <<EOF > debian/control
  85. Source: linux
  86. Section: base
  87. Priority: optional
  88. Maintainer: $name
  89. Standards-Version: 3.6.1
  90. Package: $packagename
  91. Provides: kernel-image-$version, linux-image-$version
  92. Architecture: any
  93. Description: Linux kernel, version $version
  94. This package contains the Linux kernel, modules and corresponding other
  95. files version $version
  96. EOF
  97. fi
  98. # Fix some ownership and permissions
  99. chown -R root:root "$tmpdir"
  100. chmod -R go-w "$tmpdir"
  101. # Perform the final magic
  102. dpkg-gencontrol -isp
  103. dpkg --build "$tmpdir" ..
  104. exit 0