console 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin console
  4. #
  5. # Description : Sets keymap and screen font
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. # Alexander E. Patrakov
  9. # DJ Lucas - dj@linuxfromscratch.org
  10. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  11. #
  12. # Version : LFS 7.0
  13. #
  14. ########################################################################
  15. ### BEGIN INIT INFO
  16. # Provides: console
  17. # Required-Start:
  18. # Should-Start: $local_fs
  19. # Required-Stop:
  20. # Should-Stop:
  21. # Default-Start: S
  22. # Default-Stop:
  23. # Short-Description: Sets up a localised console.
  24. # Description: Sets up fonts and language settings for the user's
  25. # local as defined by /etc/sysconfig/console.
  26. # X-LFS-Provided-By: LFS
  27. ### END INIT INFO
  28. . /lib/lsb/init-functions
  29. # Native English speakers probably don't have /etc/sysconfig/console at all
  30. [ -r /etc/sysconfig/console ] && . /etc/sysconfig/console
  31. is_true()
  32. {
  33. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ]
  34. }
  35. failed=0
  36. case "${1}" in
  37. start)
  38. # See if we need to do anything
  39. if [ -z "${KEYMAP}" ] && [ -z "${KEYMAP_CORRECTIONS}" ] &&
  40. [ -z "${FONT}" ] && [ -z "${LEGACY_CHARSET}" ] &&
  41. ! is_true "${UNICODE}"; then
  42. exit 0
  43. fi
  44. # There should be no bogus failures below this line!
  45. log_info_msg "Setting up Linux console..."
  46. # Figure out if a framebuffer console is used
  47. [ -d /sys/class/graphics/fb0 ] && use_fb=1 || use_fb=0
  48. # Figure out the command to set the console into the
  49. # desired mode
  50. is_true "${UNICODE}" &&
  51. MODE_COMMAND="echo -en '\033%G' && kbd_mode -u" ||
  52. MODE_COMMAND="echo -en '\033%@\033(K' && kbd_mode -a"
  53. # On framebuffer consoles, font has to be set for each vt in
  54. # UTF-8 mode. This doesn't hurt in non-UTF-8 mode also.
  55. ! is_true "${use_fb}" || [ -z "${FONT}" ] ||
  56. MODE_COMMAND="${MODE_COMMAND} && setfont ${FONT}"
  57. # Apply that command to all consoles mentioned in
  58. # /etc/inittab. Important: in the UTF-8 mode this should
  59. # happen before setfont, otherwise a kernel bug will
  60. # show up and the unicode map of the font will not be
  61. # used.
  62. for TTY in `grep '^[^#].*respawn:/sbin/agetty' /etc/inittab |
  63. grep -o '\btty[[:digit:]]*\b'`
  64. do
  65. openvt -f -w -c ${TTY#tty} -- \
  66. /bin/sh -c "${MODE_COMMAND}" || failed=1
  67. done
  68. # Set the font (if not already set above) and the keymap
  69. [ "${use_fb}" == "1" ] || [ -z "${FONT}" ] || setfont $FONT || failed=1
  70. [ -z "${KEYMAP}" ] ||
  71. loadkeys ${KEYMAP} >/dev/null 2>&1 ||
  72. failed=1
  73. [ -z "${KEYMAP_CORRECTIONS}" ] ||
  74. loadkeys ${KEYMAP_CORRECTIONS} >/dev/null 2>&1 ||
  75. failed=1
  76. # Convert the keymap from $LEGACY_CHARSET to UTF-8
  77. [ -z "$LEGACY_CHARSET" ] ||
  78. dumpkeys -c "$LEGACY_CHARSET" | loadkeys -u >/dev/null 2>&1 ||
  79. failed=1
  80. # If any of the commands above failed, the trap at the
  81. # top would set $failed to 1
  82. ( exit $failed )
  83. evaluate_retval
  84. exit $failed
  85. ;;
  86. *)
  87. echo "Usage: ${0} {start}"
  88. exit 1
  89. ;;
  90. esac
  91. # End console