builddeb 3.9 KB

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