You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 lines
2.3 KiB

  1. #!/bin/sh
  2. # Try to guess at whether the user would like a desktop installed on their
  3. # system. Of course Debian has many users who use it on a wide array of
  4. # hardware, so this is tricky, but it's only a default.
  5. set -e
  6. if ! [ "$NEW_INSTALL" ]; then
  7. exit 3
  8. fi
  9. arch="$(dpkg --print-architecture)"
  10. unmark () {
  11. exit 3
  12. }
  13. mark () {
  14. exit 2
  15. }
  16. # A few arches have the lion's share of desktops.
  17. common_desktop_architecture () {
  18. case "$arch" in
  19. i386|amd64|powerpc*)
  20. return 0
  21. ;;
  22. *)
  23. return 1
  24. ;;
  25. esac
  26. }
  27. # On some arches it's almost unheard of to run a desktop, at least using
  28. # this task.
  29. unlikely_desktop_architecture () {
  30. case "$arch" in
  31. m68k|s390|hppa)
  32. return 0
  33. ;;
  34. *)
  35. return 1
  36. ;;
  37. esac
  38. }
  39. # Modern desktops take a lot of ram.
  40. enough_ram () {
  41. min_ram=64
  42. ram=$(grep ^MemTotal: /proc/meminfo | { read x y z; echo $y; }) || true # kb
  43. # The 4 is a fuzz factor to allow for kernel ram usage.
  44. if [ "$ram" ] && [ "$ram" -ge "$(expr $(expr $min_ram - 4) \* 1024)" ]; then
  45. return 0
  46. else
  47. return 1
  48. fi
  49. }
  50. # The desktop task requires 2 gb or so of disk in /usr, and .5 in /var for
  51. # the debs.
  52. # FIXME: this should really be generalised and used for tasksel to not
  53. # suggest any task for which there is not enough disk.
  54. enough_disk () {
  55. min_disk=3
  56. disk=$(df -P /usr | tail -1 | awk '{print $4}')
  57. if [ "$disk" ] && [ "$disk" -ge "$(expr $min_disk \* 1024 \* 1024)" ]; then
  58. return 0
  59. else
  60. return 1
  61. fi
  62. }
  63. desktop_hardware () {
  64. if laptop-detect; then
  65. # Nearly always appropriate to include a desktop.
  66. return 0
  67. else
  68. # TODO: test for the existence of a framebuffer and a mouse.
  69. # A mouse, in particular, almost always indicates a
  70. # desktop.
  71. :
  72. fi
  73. return 1
  74. }
  75. rack_hardware () {
  76. if [ -x "`which dmidecode 2>/dev/null`" ] && \
  77. dmidecode | grep -q 'Type: Rack Mount Chassis'; then
  78. return 0
  79. fi
  80. # XXX further heuristics here to avoid selecting the task on
  81. # high-end hardware that's intended to be used as a server.
  82. # For example, if it has two NICs with link, it's probably a
  83. # server.
  84. return 1
  85. }
  86. if ! enough_ram || ! enough_disk; then
  87. unmark
  88. fi
  89. if desktop_hardware; then
  90. mark
  91. fi
  92. if unlikely_desktop_architecture; then
  93. unmark
  94. elif common_desktop_architecture; then
  95. if rack_hardware; then
  96. unmark
  97. else
  98. mark # probably a desktop ...
  99. fi
  100. else
  101. # XXX further heuristics here
  102. :
  103. fi
  104. unmark