console 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/sh
  2. # Begin $rc_base/init.d/console
  3. ### BEGIN INIT INFO
  4. # Provides: console
  5. # Required-Start:
  6. # Should-Start: $local_fs
  7. # Required-Stop:
  8. # Should-Stop:
  9. # Default-Start: sysinit
  10. # Default-Stop:
  11. # Short-Description: Sets up a localised console.
  12. # Description: Sets up fonts and language settings for the user's
  13. # local as defined by /etc/sysconfig/console.
  14. # X-LFS-Default-Start: S70
  15. # X-LFS-Default-Stop:
  16. # X-LFS-Provided-By: LFS
  17. ### END INIT INFO
  18. . /lib/lsb/init-functions
  19. MESSAGE="Setting up Linux console..."
  20. # Native English speakers probably don't have /etc/sysconfig/console at all
  21. if [ -f /etc/sysconfig/console ]
  22. then
  23. . /etc/sysconfig/console
  24. fi
  25. is_true() {
  26. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ]
  27. }
  28. failed=0
  29. case "${1}" in
  30. start)
  31. # There should be no bogus failures below this line!
  32. # Figure out if a framebuffer console is used
  33. [ -d /sys/class/graphics/fb0 ] && USE_FB=1 || USE_FB=0
  34. # Figure out the command to set the console into the
  35. # desired mode
  36. is_true "${UNICODE}" &&
  37. MODE_COMMAND="echo -en '\033%G' && kbd_mode -u" ||
  38. MODE_COMMAND="echo -en '\033%@\033(K' && kbd_mode -a"
  39. # On framebuffer consoles, font has to be set for each vt in
  40. # UTF-8 mode. This doesn't hurt in non-UTF-8 mode also.
  41. ! is_true "${USE_FB}" || [ -z "${FONT}" ] ||
  42. MODE_COMMAND="${MODE_COMMAND} && setfont ${FONT}"
  43. # Apply that command to all consoles mentioned in
  44. # /etc/inittab. Important: in the UTF-8 mode this should
  45. # happen before setfont, otherwise a kernel bug will
  46. # show up and the unicode map of the font will not be
  47. # used.
  48. # FIXME: Fedora Core also initializes two spare consoles
  49. # - do we want that?
  50. for TTY in `grep '^[^#].*respawn:/sbin/agetty' /etc/inittab |
  51. grep -o '\btty[[:digit:]]*\b'`
  52. do
  53. openvt -f -w -c ${TTY#tty} -- \
  54. /bin/sh -c "${MODE_COMMAND}" || failed=1
  55. done
  56. # Set the font (if not already set above) and the keymap
  57. is_true "${USE_FB}" || [ -z "${FONT}" ] ||
  58. setfont $FONT ||
  59. failed=1
  60. [ -z "${KEYMAP}" ] ||
  61. loadkeys ${KEYMAP} >/dev/null 2>&1 ||
  62. failed=1
  63. [ -z "${KEYMAP_CORRECTIONS}" ] ||
  64. loadkeys ${KEYMAP_CORRECTIONS} >/dev/null 2>&1 ||
  65. failed=1
  66. # Linux kernel generates wrong bytes when composing
  67. # in Unicode mode. That's why we disable dead keys in Unicode
  68. # mode by default. If you need them, download and apply
  69. # http://www.linuxfromscratch.org/~alexander/patches/linux-2.6.12.5-utf8_input-2.patch
  70. # After patching, add "-m charset_of_your_keymap" to the FONT
  71. # variable and set BROKEN_COMPOSE=false
  72. # in /etc/sysconfig/console
  73. [ -n "$BROKEN_COMPOSE" ] || BROKEN_COMPOSE="$UNICODE"
  74. ! is_true "$BROKEN_COMPOSE" ||
  75. echo "" | loadkeys -c >/dev/null 2>&1 ||
  76. failed=1
  77. # Convert the keymap from $LEGACY_CHARSET to UTF-8
  78. [ -z "$LEGACY_CHARSET" ] ||
  79. dumpkeys -c "$LEGACY_CHARSET" |
  80. loadkeys -u >/dev/null 2>&1 ||
  81. failed=1
  82. # If any of the commands above failed, the trap at the
  83. # top would set $failed to 1
  84. ( exit $failed )
  85. evaluate_retval standard
  86. ;;
  87. *)
  88. echo $"Usage:" "${0} {start}"
  89. exit 1
  90. ;;
  91. esac
  92. # End $rc_base/init.d/console