home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120521.etc.tar.gz / bradford.20120521.etc.tar / etc / init.d / kbd < prev    next >
Text File  |  2006-04-25  |  12KB  |  461 lines

  1. #! /bin/sh
  2. # Copyright (c) 1995-2005 SUSE LINUX Products AG, Nuernberg, Germany.
  3. #
  4. # Author:   Burchard Steinbild
  5. #           Werner Fink <werner@suse.de>
  6. #
  7. # Please send feedback to http://www.suse.de/feedback
  8. #
  9. # /etc/init.d/kbd
  10. #
  11. #   and symbolic its link
  12. #
  13. # /sbin/rckbd
  14. #
  15. # Warning:
  16. # /etc/init.d/earlykbd can run this script even if
  17. # the Required-Start conditions listed here are not satisfied.
  18. # Our use of $remote_fs is 
  19. # /usr/share/kbd - for finding keymaps
  20. # /usr/sbin/hwinfo - for numlock from bios
  21. #
  22. ### BEGIN INIT INFO
  23. # Provides:       kbd
  24. # Required-Start: $remote_fs
  25. # Required-Stop:
  26. # X-SuSE-Should-Start:    fbset setserial earlykbd
  27. # X-SuSE-Should-Stop: 
  28. # Default-Start:  1 2 3 5 S
  29. # Default-Stop:
  30. # Description:    Keyboard settings (don't disable!)
  31. ### END INIT INFO
  32.  
  33. . /etc/rc.status
  34. . /etc/sysconfig/console
  35. . /etc/sysconfig/keyboard
  36.  
  37. test -n "$KBD_VERBOSE" && set -x
  38.  
  39. test -e /etc/SuSEconfig/profile && . /etc/SuSEconfig/profile
  40. test -e /etc/profile.d/lang.sh  && . /etc/profile.d/lang.sh
  41. LOCALE_CHARMAP=`locale charmap`
  42. LC_ALL=POSIX
  43.  
  44. MACHINE=`/bin/uname -m 2> /dev/null`
  45. if [ "$MACHINE" = "sparc" -o "$MACHINE" = "sparc64" ]; then 
  46.    # Test if we have a serial console. 
  47.    (test -c /dev/tty1 && > /dev/tty1 ) > /dev/null 2>&1 || exit 0
  48. fi
  49. # iSeries machines also exit, just a little further down...
  50.  
  51. # The variable NON_SUSE_KERNEL determines whether we need to chvt 
  52. # to a console before some console settings apply.
  53. # We have no magic to find out about this (at boot time), so we 
  54. # leave it to the user to read this comment and put NON_SUSE_KERNEL="yes"
  55. # into /etc/sysconfig/console
  56.  
  57. test "$NON_SUSE_KERNEL" = "yes" && FGCONS=`/bin/fgconsole`
  58.  
  59. KBDBASE="/usr/share/kbd"
  60.  
  61. KTABLE=${KEYTABLE%.map*}
  62. KTABLE=${KTABLE##*/}
  63.  
  64. #
  65. # first search the wanted keytable.
  66. #
  67. if [ $MACHINE = ppc -o $MACHINE = ppc64 ]; then
  68.     test -f /proc/cpuinfo || mount -n -t proc proc /proc 2>/dev/null
  69.     while read line; do
  70.            case "$line" in
  71.           *MacRISC*)    MACHINE="mac"
  72.           test -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes && \
  73.               echo 1 > /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes
  74.           ;;
  75.           *CHRP*)      MACHINE="chrp";;
  76.           *PReP*)      MACHINE="prep" ;;
  77.           *iSeries*)    exit 0 ;;
  78.         esac
  79.     done < /proc/cpuinfo
  80. fi
  81.  
  82. #
  83. # Calculate KBD_TTY array only once
  84. # Caution: Keep in sync with earlykbd.init
  85. #
  86. if test -z "$KBD_TTY"; then
  87.     KBD_TTY="tty1 tty2 tty3 tty4 tty5 tty6 tty7 tty8 tty9
  88.          tty10 tty11 tty12 tty13 tty14 tty15 tty16
  89.          tty17 tty18 tty19 tty20 tty21 tty22 tty23 tty24"
  90. fi
  91.  
  92. newkbd=""
  93. for tty in $KBD_TTY; do
  94.     test -w /dev/$tty        || continue
  95.     test -c /dev/$tty        || continue
  96.     > /dev/$tty &> /dev/null    || continue
  97.     newkbd="${newkbd:+$newkbd }/dev/$tty"
  98. done
  99. KBD_TTY="$newkbd"
  100. unset newkbd
  101.  
  102. #
  103. # load usb drivers in runlevel S
  104. #
  105. case "${PREVLEVEL}${RUNLEVEL}" in
  106.     N1|NS)
  107.     test -f /proc/cpuinfo || mount -n -t proc proc /proc 2>/dev/null
  108.  
  109. #    [bugzilla #46113]
  110. #    we come here although heading for runlevel 5. 
  111. #    I'll comment out diabling hotplug for now. jw.
  112. #    test -f /proc/sys/kernel/hotplug && echo /bin/true > /proc/sys/kernel/hotplug 2>/dev/null
  113.     test -d /proc/bus/usb || modprobe usbcore >/dev/null 2>&1
  114.     mount -n -t usbfs usbfs /proc/bus/usb >/dev/null 2>&1
  115.     for mod in ehci-hcd ohci-hcd uhci-hcd usb-ohci usb-uhci ; do
  116.          echo -n $mod" "
  117.          modprobe $mod >/dev/null 2>&1
  118.     done
  119.     echo 
  120.     echo "wait 3 seconds for USB initialisation ..."
  121.     sleep 3
  122.     for mod in usbhid input hid keybdev ; do
  123.          modprobe $mod >/dev/null 2>&1
  124.     done
  125.     ;;
  126. esac
  127.  
  128. KEYMAP=""
  129. if test -e /$KEYTABLE ; then
  130.     KEYMAP=$KEYTABLE
  131. else
  132.     KEYTABLE=$KTABLE
  133.     case "$KEYTABLE" in
  134.     *.gz)  KBDPATH="${KEYTABLE}" ;;
  135.     *.map) KBDPATH="${KEYTABLE} ${KEYTABLE}.gz" ;;
  136.     *)     KBDPATH="${KEYTABLE} ${KEYTABLE}.gz ${KEYTABLE}.map.gz ${KEYTABLE}.map" ;;
  137.     esac
  138.     KEYMAP=$(find ${KBDBASE}/keymaps -type f \( -name ${KBDPATH// / -o -name } \))
  139. fi
  140. #
  141. # setup kbdrate and led status
  142. #
  143. function set_kbdrate ()
  144. {
  145.     local line
  146.  
  147.     if test "$MACHINE" != "mac" ; then
  148.         KBDOPT=""
  149.         if test -n "$KBD_RATE" ; then
  150.             KBDOPT="${KBDOPT:+$KBDOPT }-r $KBD_RATE"
  151.         fi
  152.         if test -n "$KBD_DELAY"; then
  153.             KBDOPT="${KBDOPT:+$KBDOPT }-d $KBD_DELAY"
  154.         fi
  155.         if test -n "$KBDOPT" ; then
  156.             echo -n "Keyboard: "
  157.             /bin/kbdrate $KBDOPT
  158.             rc_status -v1
  159.         fi
  160.     fi
  161.  
  162.     # setleds
  163.     #
  164.     # Note: The file /var/run/numlock-on is used in ~/.xinitrc
  165.     #    to reflect the correct numlock state choosen by the
  166.     #    user even under X11
  167.     #
  168.     if test "$KBD_NUMLOCK" = "yes"; then
  169.         touch /var/run/numlock-on
  170.     elif test "$KBD_NUMLOCK" = "no"; then
  171.         rm -f /var/run/numlock-on
  172.     elif test "$KBD_NUMLOCK" = "bios"; then
  173.         if test -x /usr/sbin/hwinfo ; then
  174.             /usr/sbin/hwinfo --bios | \
  175.             while read line ; do
  176.             case "$line" in
  177.             Num\ Lock:\ on)  touch /var/run/numlock-on ;;
  178.             Num\ Lock:\ off) rm -f /var/run/numlock-on ;;
  179.             Caps\ Lock:)     break
  180.             esac
  181.             done
  182.         else
  183.             echo "no /usr/sbin -> Numlock off."
  184.             rm -f /var/run/numlock-on
  185.         fi
  186.     fi 
  187.     unset line
  188.  
  189.     #
  190.     # Only change keyboard leds if setleds is in path
  191.     # 
  192.     type -p setleds &> /dev/null        || return
  193.  
  194.     if test -e /var/run/numlock-on ; then
  195.         LEDOPT="+num"
  196.     else
  197.         LEDOPT="-num"
  198.     fi
  199.     if test "$KBD_CAPSLOCK" = "yes"; then
  200.         LEDOPT="$LEDOPT +caps"
  201.     else
  202.         LEDOPT="$LEDOPT -caps"
  203.     fi  
  204.     if test "$KBD_SCRLOCK" = "yes"; then
  205.         LEDOPT="$LEDOPT +scroll"
  206.     else
  207.         LEDOPT="$LEDOPT -scroll"
  208.     fi  
  209.  
  210.     #
  211.     # Only change keyboard leds if they will be switched
  212.     # on ... OR if they are switched on currently
  213.     #
  214.     if [[ $LEDOPT == *+* ]] ; then
  215.         touch /var/run/setleds-on
  216.     else
  217.         test -e /var/run/setleds-on    || return
  218.         test -n "$LEDOPT"        || return
  219.         rm -f /var/run/setleds-on
  220.     fi
  221.  
  222.     for tty in $KBD_TTY; do
  223.         setleds -D $LEDOPT < $tty
  224.     done
  225. }
  226. #
  227. rc_reset
  228. case "$1" in
  229.     start|restart|reload|force-reload)
  230.  
  231.     case "$1" in
  232.             start)
  233.         # don't do anything if we have this file.
  234.         # this means that initialization was already done.
  235.         # don't do it twice unless forced, it may annoy xdm and
  236.         # produce lots of error messages.
  237.         test -s /var/run/keymap && exit 0
  238.         ;;
  239.     esac
  240.     
  241.  
  242.     if test -z "$KEYTABLE"; then
  243.         echo "No keyboard map to load"
  244.     else
  245.         if test -z "$KEYMAP" || test ! -d "$KBDBASE" ; then
  246.         if test -r /etc/defkeymap.map ; then
  247.             if test -n "$KEYMAP" ; then
  248.                 echo "$KEYMAP is unvailable, using /etc/defkeymap.map instead."
  249.             if test -r /var/run/keymap ; then
  250.                 read cached < /etc/defkeymap.name
  251.                 if test "$KEYMAP" != "$cached" && test $K != "$cached" ; then
  252.                     echo "Warning: fallback differs: $cached"
  253.                 fi
  254.             fi
  255.             else
  256.                 echo "Can not find a keymap for ${KEYTABLE}, trying fallback."
  257.             fi
  258.             KEYMAP=/etc/defkeymap.map
  259.         else
  260.             echo "Fallback /etc/defkeymap.map not there."
  261.             echo "Can not find a keymap for ${KEYTABLE}, Exit."
  262.             rc_failed
  263.         fi
  264.         else
  265.         if test ! -e "$KEYMAP" ; then
  266.             echo "Found more than one keymap ${KEYTABLE}"
  267.             KEYMAP=$K
  268.             echo "Using $KEYMAP."
  269.             echo "If you want another one, please add complete path to"
  270.             echo "KEYTABLE in /etc/sysconfig/keyboard."
  271.         fi
  272.         fi
  273.         rc_status && retmsg="`loadkeys -C "$KBD_TTY" $KEYMAP 2>&1`"
  274.         if test $? -eq 0 && ( > /var/run/keymap ) > /dev/null 2>&1 ; then
  275.         echo "$KEYMAP"    > /var/run/keymap
  276.         else
  277.         case "$RUNLEVEL" in
  278.             S|N|1|\#) true ;;
  279.             *) rc_failed ;;
  280.         esac
  281.         fi
  282.         echo "Loading keymap ${retmsg#Loading*${KBDBASE}/keymaps/}"
  283.         rc_status -v1
  284.  
  285.         set_kbdrate
  286.     fi
  287.     
  288.     # Disable CAPS LOCK key if wanted
  289.     if test "$KBD_DISABLE_CAPS_LOCK" = "yes"; then
  290.         loadkeys -C "$KBD_TTY" disable.capslock >/dev/null 2>&1 || echo "Could not disable Caps Lock"
  291.     fi
  292.  
  293.     # Load compose tables
  294.     case "$RUNLEVEL" in
  295.         S|N|1|\#) COMPOSETABLE="" ;;
  296.     esac
  297.     if test ! -z "$COMPOSETABLE"; then
  298.         unset COMPOSELOADED COMPOSECLEAR
  299.         for name in $COMPOSETABLE; do
  300.             # Test for compose clear flag
  301.             if test "$name" = "-c" -o "$name" = "clear"; then
  302.                 COMPOSECLEAR=-c
  303.                 continue
  304.             fi
  305.             # Handle the first table differently ...
  306.             if test -z "$COMPOSELOADED"; then
  307.                 echo -n "Loading compose table $name"
  308.                 loadkeys -C "$KBD_TTY" $COMPOSECLEAR compose.$name >/dev/null 2>&1
  309.                 rc_check
  310.                 #if test $name = clear; then rc_reset; fi
  311.                 COMPOSELOADED=1
  312.             else
  313.                 echo -n " $name"
  314.                 loadkeys -C "$KBD_TTY" compose.$name >/dev/null 2>&1
  315.                 rc_check
  316.             fi
  317.         done
  318.         if test ! -z "$COMPOSELOADED"; then 
  319.             rc_status -v
  320.         fi
  321.     fi
  322.     
  323.  
  324.     # Unicode mode    
  325.     if test -x /bin/kbd_mode ; then
  326.         case $LOCALE_CHARMAP in
  327.         UTF-8)
  328.              echo Start Unicode mode
  329.                 for tty in $KBD_TTY; do
  330.             # The chvt is not needed for SuSE kernels
  331.             test "$NON_SUSE_KERNEL" != "yes" || chvt ${tty#*tty}
  332.  
  333.             # Tell the console output driver that the bytes
  334.             # arriving are UTF-8 encoded multibyte sequences.
  335.             echo -n -e '\033%G' > $tty
  336.  
  337.             # Set the keyboard driver in Unicode mode.
  338.             # (Default is ASCII mode.)
  339.             # This really does nothing with the way normal
  340.             # keys are handled in the kernel. All it does is:
  341.             # - It is necessary for `dumpkeys' in order to
  342.             #   not drop U+XXXX entries from the keymaps.
  343.             # - It is necessary for `loadkeys' in order to
  344.             #   avoid warnings.
  345.             # - Unicode characters typed as Alt-x1 ... Alt-xn
  346.             #   (where x1,...,xn are digits on the numeric keypad)
  347.             #    will be emitted in UTF-8.
  348.             kbd_mode -u -C $tty
  349.             rc_status
  350.             done
  351.                 ;;
  352.             *)
  353.             echo Stop Unicode mode
  354.             for tty in $KBD_TTY; do
  355.             # The chvt is not needed for SuSE kernels
  356.             test "$NON_SUSE_KERNEL" != "yes" || chvt ${tty#*tty}
  357.  
  358.             echo -n -e '\033%@' > $tty
  359.  
  360.             kbd_mode -a -C $tty
  361.             rc_status
  362.                 done
  363.                 ;;
  364.         esac
  365.         test "$NON_SUSE_KERNEL" != "yes" || chvt $FGCONS
  366.         rc_status -v1
  367.     fi
  368.     
  369.     # setfont
  370.     if test -d ${KBDBASE}/consolefonts -a \
  371.         -n "$CONSOLE_FONT" -a "$CONSOLE_FONT" != "YAST_ASK"
  372.     then
  373.         if test ! -z "$CONSOLE_UNICODEMAP"; then 
  374.             UMAP="-u $CONSOLE_UNICODEMAP"
  375.         fi
  376.         if test ! -z "$CONSOLE_SCREENMAP"; then 
  377.             SMAP="-m $CONSOLE_SCREENMAP"
  378.         fi
  379.         PRINTABLE_MAGIC="";
  380.         if test -n "$CONSOLE_MAGIC" -a "$CONSOLE_MAGIC" != "none"; then
  381.             case $CONSOLE_MAGIC in
  382.                    \(B)    PRINTABLE_MAGIC="G0:iso8859-1" ;;
  383.                    \(0)    PRINTABLE_MAGIC="G0:vt100" ;;
  384.                    \(U)    PRINTABLE_MAGIC="G0:ROM" ;;
  385.                    \(K)    PRINTABLE_MAGIC="G0:loadable" ;;
  386.                    \)B)    PRINTABLE_MAGIC="G1:iso8859-1" ;;
  387.                    \)0)    PRINTABLE_MAGIC="G1:vt100" ;;
  388.                    \)U)    PRINTABLE_MAGIC="G1:ROM" ;;
  389.                    \)K)    PRINTABLE_MAGIC="G1:loadable" ;;
  390.                    *)    PRINTABLE_MAGIC="magic='$MAGIC'" ;;
  391.             esac
  392.             CONSOLE_MAGIC="\033$CONSOLE_MAGIC"
  393.         else
  394.             CONSOLE_MAGIC="";
  395.         fi
  396.         if test -x /bin/setfont ; then
  397.         echo "Loading console font $CONSOLE_FONT $UMAP $SMAP $PRINTABLE_MAGIC"
  398.         for tty in $KBD_TTY; do
  399.             # The chvt is not needed for SuSE kernels
  400.             test "$NON_SUSE_KERNEL" != "yes" || chvt ${tty#*tty}
  401.  
  402.             /bin/setfont -C $tty $CONSOLE_FONT $UMAP $SMAP
  403.             rc_status
  404.  
  405.             echo -en "$CONSOLE_MAGIC" > $tty
  406.         done
  407.         test "$NON_SUSE_KERNEL" != "yes" || chvt $FGCONS
  408.         rc_status -v1
  409.         fi
  410.     fi
  411.  
  412.     case "$RUNLEVEL" in
  413.         S|N|1|\#) true ;;
  414.         *)
  415.             case $LOCALE_CHARMAP in
  416.             UTF-8)
  417.                 # Change the keyboard mapping in such a way that the
  418.                 # non-ASCII keys produce UTF-8 encoded multibyte sequences
  419.             # instead of single bytes >= 0x80 in a legacy 8-bit encoding.
  420.                 ( dumpkeys | loadkeys -C "$KBD_TTY" --unicode ) > /dev/null 2>&1
  421.                 ;;
  422.             *) 
  423.                 ;;
  424.         esac
  425.         dumpkeys=yes
  426.         if type -p cmp > /dev/null 2>&1 && \
  427.            dumpkeys | cmp -s /etc/defkeymap.map
  428.         then
  429.            dumpkeys=no
  430.         fi
  431.         if test "$dumpkeys" = "yes" ; then
  432.             ( dumpkeys > /etc/defkeymap.map ) > /dev/null 2>&1
  433.             if test ! -z "$KEYMAP" && test "$KEYMAP" != "/etc/defkeymap.map" ; then
  434.                 test ! -e "$KEYMAP" && KEYMAP=$K
  435.             echo $KEYMAP > /etc/defkeymap.name
  436.             fi
  437.         fi
  438.     esac
  439.  
  440.     ;;
  441.     stop)
  442.     # enable start after stop.
  443.         echo -n "$0 stop"
  444.     rm -f /var/run/keymap
  445.     rc_status -v
  446.     ;;
  447.     check|status)
  448.     if test -r /var/run/keymap ; then
  449.         read current < /var/run/keymap
  450.         echo "Keymap $current is loaded."
  451.     else
  452.         rc_failed 3
  453.     fi
  454.     ;;
  455.     *)
  456.     echo "Usage: $0 {start|stop|restart|reload|force-reload|status|check}"
  457.     exit 2
  458.     ;;
  459. esac
  460. rc_exit
  461.