home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / etc / init.d / keymap.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2006-04-25  |  3.2 KB  |  130 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          keymap
  4. # Required-Start:    mountvirtfs
  5. # Required-Stop:     
  6. # Default-Start:     S 2 3 4 5
  7. # Default-Stop:      0 1 6
  8. ### END INIT INFO
  9.  
  10. . /lib/lsb/init-functions
  11.  
  12. #
  13. # Load the keymaps *as soon as possible*
  14. #
  15.  
  16. # Don't fail on error
  17. CONSOLE_TYPE=`fgconsole 2>/dev/null` || CONSOLE_TYPE="unknown"
  18.  
  19. # Don't fail on serial consoles
  20.  
  21. QUIT=0
  22. # fail silently if loadkeys not present (yet).
  23. command -v loadkeys >/dev/null 2>&1 || QUIT=1
  24.  
  25. CONFDIR=/etc/console
  26. CONFFILEROOT=boottime
  27. EXT=kmap
  28. CONFFILE=${CONFDIR}/${CONFFILEROOT}.${EXT}.gz
  29.  
  30. reset_kernel()
  31. {
  32.     # On Mac PPC machines, we may need to set kernel vars first
  33.         # We need to mount /proc to do that; not optimal, as its going to 
  34.         # be mounted in S10checkroot, but we need it set up before sulogin
  35.         # may be run in checkroot, which will need the keyboard to log in...
  36.     [ -x /sbin/sysctl ] || return
  37.     [ -r /etc/sysctl.conf ] || return
  38.     grep -v '^\#' /etc/sysctl.conf | grep -q keycodes 
  39.     if [ "$?" = "0" ] ; then
  40.         grep keycodes /etc/sysctl.conf | grep -v "^#" | while read d ; do
  41.             /sbin/sysctl -w $d 2> /dev/null || true
  42.             done
  43.         fi
  44. }
  45.  
  46. unicode_start_stop()
  47. {
  48.     # Switch unicode mode by checking the locale.
  49.     # This will be needed before loading the keymap.
  50.     [ -x /usr/bin/unicode_start ] || [ -x /bin/unicode_start ] ||  return
  51.     [ -x /usr/bin/unicode_stop ] || [ -x /bin/unicode_stop ] || return
  52.  
  53.     ENV_FILE="none"
  54.     [ -r /etc/environment ] && ENV_FILE="/etc/environment"
  55.     [ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale" 
  56.     [ $ENV_FILE = none ] && return
  57.     
  58.     for var in LANG LC_ALL LC_CTYPE; do
  59.         value=$(egrep "^[^#]*${var}=" $ENV_FILE | tail -n1 | cut -d= -f2)
  60.         eval $var=$value
  61.     done
  62.  
  63.     CHARMAP=`LANG=$LANG LC_ALL=$LC_ALL LC_CTYPE=$LC_CTYPE locale charmap`
  64.     if [ "$CHARMAP" = "UTF-8" ]; then
  65.         unicode_start 2> /dev/null || true
  66.     else
  67.         unicode_stop 2> /dev/null || true
  68.     fi
  69. }
  70.  
  71. if [ ! $QUIT = '1' ] ; then
  72.  
  73.   case "$1" in
  74.       start | restart | force-reload | reload)
  75.   
  76.          # First mount /proc if necessary.
  77.          unmount_proc="no"
  78.          if [ ! -x /proc/1 ]; then
  79.             unmount_proc="yes"    
  80.           mount -n /proc
  81.          fi
  82.   
  83.           # Set kernel variables if required
  84.         reset_kernel
  85.  
  86.         if [ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ] ; then
  87.            linux_keycodes=`cat /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes`
  88.     else
  89.            linux_keycodes=1;
  90.         fi
  91.  
  92.     # load new map
  93.     if [ $linux_keycodes -gt 0 ] ; then 
  94.       if [ -r ${CONFFILE} ] ; then
  95.  
  96.         # Switch console mode to UTF-8 or ASCII as necessary
  97.         unicode_start_stop
  98.  
  99.         if [ $CONSOLE_TYPE = "serial" ] ; then 
  100.             loadkeys -q ${CONFFILE} 2>&1 > /dev/null
  101.         else
  102.                 loadkeys -q ${CONFFILE}
  103.         fi
  104.         if [ $? -gt 0 ]
  105.         then
  106.             # if we've a serial console, we may not have a keyboard, so don't
  107.         # complain if we fail. 
  108.            if [ ! $CONSOLE_TYPE = "serial" ]; then 
  109.             log_warning_msg "Problem when loading ${CONFDIR}/${CONFFILEROOT}.${EXT}.gz, use install-keymap"
  110.             sleep 10
  111.            fi 
  112.         fi
  113.         fi
  114.     fi
  115.  
  116.     # unmount /proc if we mounted it
  117.         [ "$unmount_proc" = "no" ] || umount -n /proc
  118.  
  119.     ;;
  120.  
  121.     stop)
  122.     ;;
  123.  
  124.     *)
  125.     log_warning_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
  126.     ;;
  127.   esac
  128.  
  129. fi
  130.