home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / input-wizard < prev    next >
Encoding:
Text File  |  2006-07-04  |  13.3 KB  |  453 lines

  1. #!/bin/sh
  2. #(c) Barry Kauler 2005/2006 www.puppylinux.com
  3. #keyboard/mouse wizard for Puppy Linux
  4. #based on code from /usr/X11R6/bin/xwin
  5.  
  6. if [ "`which gtkdialog`" = "" ];then
  7.  xmessage -center -title "ERROR" "This distribution of Puppy is lacking the application gtkdialog,
  8. which in turn requires the gtk2 libraries package.
  9. Gtkdialog is needed to run this Wizard.
  10.  
  11. Press OK button to quit..."
  12.  exit
  13. fi
  14.  
  15.  
  16. export MouseKeyboardWizard="
  17.  <vbox>
  18.   <hbox>
  19.    <text>
  20.     <label>Choose keyboard layout for your country...</label>
  21.    </text>
  22.    <button>
  23.     <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
  24.     <label>KEY1BUTTON</label>
  25.    </button>
  26.   </hbox>
  27.   <hbox>
  28.    <text>
  29.     <label>Choose keyboard layout, older 2-letter method...</label>
  30.    </text>
  31.    <button>
  32.     <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
  33.     <label>KEY2BUTTON</label>
  34.    </button>
  35.   </hbox>
  36.   <hbox>
  37.    <text>
  38.     <label>Choose keyboard interface...</label>
  39.    </text>
  40.    <button>
  41.     <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
  42.     <label>KEY3BUTTON</label>
  43.    </button>
  44.   </hbox>
  45.   <hbox>
  46.    <text>
  47.     <label>Choose type of mouse...</label>
  48.    </text>
  49.    <button>
  50.     <input file>/usr/local/lib/X11/mini-icons/Mouse.xpm</input>
  51.     <label>MOUSE1BUTTON</label>
  52.    </button>
  53.   </hbox>
  54.  
  55.   <hbox>
  56.    <button ok></button>
  57.   </hbox>
  58.  </vbox>
  59. "
  60.  
  61. CHECK1="false"
  62.  
  63.  
  64. askoldkbdlayout ()
  65. {
  66.  KEYBOARD=""
  67.   Xdialog --title "Keyboard Wizard" --cancel-label "Cancel" --no-tags --menu "Select the keyboard layout:" 0 0 0  be "be (Belgium)" br "br (Brazil)" cf "cf (Central African Republic)" de "de (Germany)" dk "dk (Denmark)" es "es (Spain)" fi "fi (Finland)" fr "fr (France)" gr "gr (Greece)" hu "hu (Hungary)" it "it (Italy)" jp "jp (Japan)" no "no (Norway)" pl "pl (Poland)" ru "ru (Russia)" se "se (Sweden)" uk "uk (United Kingdom)" us "us (USA)"  2> /tmp/kbdextlayout.txt
  68.   [ $? != 0 ] && return 1
  69.   KEYBOARD="`cat /tmp/kbdextlayout.txt`"
  70.  return 0
  71. }
  72.  
  73.  
  74. #thanks to Stefan Talpalaru (blueflops distro) for ideas for this func...
  75. askkbdlayout ()
  76. {
  77.  KEYBOARD=""
  78.  FONTMAP=""
  79.  CODEPAGE=""
  80.  #while :; do
  81.   Xdialog --title "Keyboard Wizard" --cancel-label "Cancel" --menu "Select the keyboard layout:" 0 0 0\
  82.     $( for F in `ls /usr/share/kbd/keymaps/i386/[^i]*/*`; do echo $F | cut -d '/' -f 8 | sed 's/.map//g'; echo " "$F | cut -d '/' -f 7 ; done )\
  83.  2> /tmp/kbdextlayout.txt
  84.   [ $? != 0 ] && return 1
  85.   KEYBOARD="`cat /tmp/kbdextlayout.txt`"
  86.   case $KEYBOARD in 
  87.    cz|hu101|pl|ro_win|sk-qwerty|croat|cz-us-qwertz|hu|slovene)
  88.     FONTMAP=/usr/share/kbd/consolefonts/lat2-12.psfu
  89.     CODEPAGE=ISO-8859-2
  90.     #break
  91.     ;;
  92.    *)
  93.     FONTMAP=/usr/share/kbd/consolefonts/lat1-12.psfu
  94.     CODEPAGE=ISO-8859-1
  95.     #break
  96.     ;;
  97.   esac
  98.  #done
  99.  KEYBOARD=$KEYBOARD.map  #.gz
  100.  return 0
  101. }
  102.  
  103. #big while loop...
  104. while :; do
  105.  KMAP=""
  106.  unset MouseWizard
  107.  unset KeyboardFeaturesWizard
  108.  
  109.  #put some code in here to ask keyboard layout, keyboard ps2/usb, mouse serial/ps2/usb setup?
  110.  #also offer the old 2-letter layout...
  111.  eval `gtkdialog --program=MouseKeyboardWizard | grep "EXIT"`
  112.  
  113.  case $EXIT in
  114.  
  115.  KEY1BUTTON)
  116.   askkbdlayout #this is extended menu, func above.
  117.   #...this sets KEYBOARD, FONTMAP, CODEPAGE variables.
  118.   if [ $? -eq 0 ];then
  119.    KMAP="$KEYBOARD"
  120.   fi
  121.   ;;
  122.  
  123.  KEY2BUTTON)
  124.   askoldkbdlayout
  125.   if [ $? -eq 0 ];then
  126.    KMAP="$KEYBOARD"
  127.   fi
  128.   ;;
  129.  
  130.  KEY3BUTTON)
  131.   KEYBRDTYPE="`cat /etc/keyboardtype`"
  132.   CHECKKEY1="false"
  133.   if [ "$KEYBRDTYPE" = "usb" ];then
  134.    CHECKKEY1="true"
  135.   fi
  136.   export KeyboardFeaturesWizard="
  137.  <vbox>
  138.   <frame Keyboard interface>
  139.    <vbox>
  140.     <text>
  141.      <label>Changing this only takes effect after Puppy is rebooted!</label>
  142.     </text>
  143.     <checkbox>
  144.      <label>Keyboard has USB interface</label>
  145.      <default>$CHECKKEY1</default>
  146.     </checkbox>
  147.    </vbox>
  148.   </frame>
  149.   <hbox>
  150.    <button cancel></button>
  151.    <button ok></button>
  152.   </hbox>
  153.  </vbox>
  154. "
  155.   RETPARAMS=`gtkdialog --program=KeyboardFeaturesWizard`
  156.   echo "$RETPARAMS"
  157.   if [ ! "`echo "$RETPARAMS" | grep "EXIT" | grep "OK"`" = "" ];then
  158.    if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX002" | grep "true"`" = "" ];then
  159.     echo -n "usb" > /etc/keyboardtype
  160.     if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
  161.      modprobe usbhid 2> /dev/null #maybe then just need to restart X.
  162.     else
  163.      modprobe hid #v2.0.0
  164.      modprobe keybdev #v2.0.0 just in case it got removed.
  165.     fi
  166.    else
  167.     modprobe -r keybdev #v2.0.0
  168.     echo -n "ps/2" > /etc/keyboardtype
  169.    fi
  170.   fi
  171.   ;;
  172.  
  173.  MOUSE1BUTTON)
  174.   MOUSEDEV="`cat /etc/mousedevice`"
  175.   #RADIOBUTTONS="$RADIO2$RADIO1$RADIO3" #serial
  176.   DEF1="false"
  177.   DEF2="true"
  178.   DEF3="false"
  179.   if [ "$MOUSEDEV" = "psaux" ];then
  180.    #RADIOBUTTONS="$RADIO1$RADIO2$RADIO3"
  181.    DEF1="true"
  182.    DEF2="false"
  183.    DEF3="false"
  184.   fi
  185.   if [ "$MOUSEDEV" = "input/mice" ];then
  186.    #RADIOBUTTONS="$RADIO3$RADIO2$RADIO1"
  187.    DEF1="false"
  188.    DEF2="false"
  189.    DEF3="true"
  190.   fi
  191.  
  192.   RADIO1="     <radiobutton>
  193.       <label>PS/2 mouse (most common)</label>
  194.       <variable>RADIO001</variable>
  195.       <default>$DEF1</default>
  196.       <action>if true disable:COMPORT</action>
  197.      </radiobutton>
  198. "
  199.   RADIO2="     <radiobutton>
  200.       <label>Serial mouse</label>
  201.       <variable>RADIO002</variable>
  202.       <default>$DEF2</default>
  203.       <action>if true enable:COMPORT</action>
  204.      </radiobutton>
  205. "
  206.   RADIO3="     <radiobutton>
  207.       <label>USB mouse</label>
  208.       <variable>RADIO003</variable>
  209.       <default>$DEF3</default>
  210.       <action>if true disable:COMPORT</action>
  211.      </radiobutton>
  212. "
  213.   RADIOBUTTONS="$RADIO1$RADIO2$RADIO3"
  214.  
  215.  
  216.   MOUSEBUTTONS="`cat /etc/mousebuttons`"
  217.   CHECK1="false"
  218.   if [ "$MOUSEBUTTONS" = "5" ];then
  219.    CHECK1="true"
  220.   fi
  221.  
  222.   #v1.0.7
  223.   CHECKM="false"
  224.   if [ ! "`cat /etc/xextraoptions | grep "\\-2button"`" = "" ];then
  225.    CHECKM="true"
  226.   fi
  227.   #v2.01
  228.   CHECKH="false"
  229.   IDLETIME="0"
  230.   if [ -f /etc/mousehide ];then
  231.    IDLETIME="`cat /etc/mousehide | cut -f 1 -d ','`"
  232.    [ ! "$IDLETIME" = "0" ] && CHECKH="true"
  233.   fi
  234.  
  235.   #v1.0.7 modified for gtkdialog2...
  236.   export MouseWizard="
  237.  <wtitle>Mouse Wizard</wtitle>
  238.  <vbox>
  239.   <frame Mouse interface>
  240.    <hbox>
  241.     <vbox>
  242.      $RADIOBUTTONS
  243.     </vbox>
  244.     <vbox>
  245.        <text><label>Serial port:</label></text>
  246.        <combobox>
  247.          <item>ttyS0</item>
  248.          <item>ttyS1</item>
  249.          <item>ttyS2</item>
  250.          <item>ttyS3</item>
  251.          <variable>COMPORT</variable>
  252.          <visible>disabled</visible>
  253.        </combobox>
  254.     </vbox>
  255.    </hbox>
  256.   </frame>
  257.   <frame Mouse features>
  258.    <vbox>
  259.     <checkbox>
  260.      <label>Mouse has a scroll wheel</label>
  261.      <variable>CHECKBOX009</variable>
  262.      <default>$CHECK1</default>
  263.     </checkbox>
  264.     <checkbox>
  265.      <label>Middle button emulated on a 2-button mouse</label>
  266.      <variable>CHECKBOX010</variable>
  267.      <default>$CHECKM</default>
  268.     </checkbox>
  269.     <checkbox>
  270.      <label>Auto-hide mouse cursor when not moving</label>
  271.      <variable>CHECKBOX011</variable>
  272.      <default>$CHECKH</default>
  273.     </checkbox>
  274.    </vbox>
  275.   </frame>
  276.   <hbox>
  277.    <button cancel></button>
  278.    <button ok></button>
  279.   </hbox>
  280.  </vbox>
  281. "
  282.  
  283.   RETPARAMS=`gtkdialog2 --program=MouseWizard`
  284.   echo "$RETPARAMS"
  285.   if [ ! "`echo "$RETPARAMS" | grep "EXIT" | grep "OK"`" = "" ];then
  286.    if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
  287.     modprobe -r psmouse 2> /dev/null #v1.0.2 k2.6
  288.     modprobe -r sermouse 2> /dev/null #v1.0.2 k2.6
  289.    else
  290.     #modprobe -r usbmouse 2> /dev/null #v1.0.2
  291.     modprobe -r mousedev #v2.0.0
  292.    fi
  293.    if [ ! "`echo "$RETPARAMS" | grep "RADIO001" | grep "true"`" = "" ];then
  294.     MOUSEDEV="psaux" #ps/2 mouse.
  295.     ln -sf /dev/psaux /dev/mouse
  296.     #k2.4 has ps/2 mouse support inbuilt.
  297.     if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
  298.      modprobe psmouse 2> /dev/null #v1.0.2 k2.6
  299.     fi
  300.    fi
  301.    if [ ! "`echo "$RETPARAMS" | grep "RADIO002" | grep "true"`" = "" ];then
  302.     eval `echo "$RETPARAMS" | grep "COMPORT"`
  303.     MOUSEDEV="$COMPORT" #ttyS0,1,2,3
  304.     ln -sf /dev/$COMPORT /dev/mouse
  305.     #2.4 kernel has serial mouse support inbuilt.
  306.     if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
  307.      modprobe 8250_pci 
  308.      modprobe sermouse 
  309.     fi
  310.    fi
  311.    if [ ! "`echo "$RETPARAMS" | grep "RADIO003" | grep "true"`" = "" ];then
  312.     MOUSEDEV="input/mice" #usb mouse
  313.     if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
  314.      modprobe usbhid 2> /dev/null
  315.     else
  316.      #modprobe usbmouse
  317.      modprobe hid #v2.0.0
  318.      modprobe mousedev #v2.0.0
  319.     fi
  320.     ln -sf /dev/input/mice /dev/mouse
  321.    fi
  322.    echo -n "$MOUSEDEV" > /etc/mousedevice
  323.  
  324.    if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX011" | grep "true"`" = "" ];then #v2.01
  325.     [ "$IDLETIME" = "0" ] && IDLETIME="3"
  326.     echo -n "${IDLETIME}," &&  > /etc/mousehide
  327.     [ "`pidof unclutter`" = "" ] && unclutter -idle $IDLETIME &
  328.    else
  329.     echo -n '0,' > /etc/mousehide
  330.     [ ! "`pidof unclutter`" = "" ] && killall unclutter
  331.    fi
  332.  
  333.    #v1.0.7 emulate middle button
  334.    #v2.02 Dougal has suggested changes for 3-button emulation...
  335.    MBUTOUT="`cat /etc/xextraoptions | sed -e 's/ \-[23]button//g'`"
  336.    if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX010" | grep "true"`" = "" ];then
  337.     #'-2button' tells Xvesa that want 3rd-button emulation...
  338.     echo -n "$MBUTOUT -2button" > /etc/xextraoptions
  339.     echo -n "2" > /etc/mousebuttons
  340.     if [ -f /etc/X11/xorg.conf ];then
  341.      #\W\+ means one or more whitespace chars...
  342.      cat /etc/X11/xorg.conf | tr -s '#' | sed -e 's/#Option\W\+"Emulate3Buttons"/Option      "Emulate3Buttons"/g' > /tmp/xorg.conf.tmp2
  343.      sync
  344.      cat /tmp/xorg.conf.tmp2 | tr -s '#' | sed -e 's/#Option\W\+"Emulate3Timeout"/Option      "Emulate3Timeout"/g' > /tmp/xorg.conf.tmp
  345.     fi
  346.    else
  347.     #'-3button' tells Xvesa that mouse has 3 buttons so do not want emulation...
  348.     #echo -n "$MBUTOUT -3button" > /etc/xextraoptions
  349.     #umm, no, leave it off, for case of 2-button mouse without emulation...
  350.     #no need to have a explicit '-3button' entry...
  351.     echo -n "$MBUTOUT" > /etc/xextraoptions
  352.     echo -n "3" > /etc/mousebuttons
  353.     if [ -f /etc/X11/xorg.conf ];then
  354.      cat /etc/X11/xorg.conf | sed -e 's/Option\W\+"Emulate3Buttons"/#Option      "Emulate3Buttons"/g' | tr -s '#' > /tmp/xorg.conf.tmp2
  355.      sync
  356.      cat /tmp/xorg.conf.tmp2 | sed -e 's/Option\W\+"Emulate3Timeout"/#Option      "Emulate3Timeout"/g' | tr -s '#' > /tmp/xorg.conf.tmp
  357.     fi
  358.    fi
  359.    sync
  360.    if [ -f /tmp/xorg.conf.tmp ];then
  361.     cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
  362.    fi
  363.  
  364.    if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX009" | grep "true"`" = "" ];then
  365.     echo -n "5" > /etc/mousebuttons #enable scrollwheel.
  366.     if [ -f /etc/X11/xorg.conf ];then
  367.      cat /etc/X11/xorg.conf | tr -s '#' | sed -e 's/#Option\W\+"ZAxisMapping"\W\+"4 5"/Option      "ZAxisMapping" "4 5"/g' > /tmp/xorg.conf.tmp
  368.     fi
  369.    else
  370.    # echo -n "3" > /etc/mousebuttons ...v1.0.7 moved up.
  371.     if [ -f /etc/X11/xorg.conf ];then
  372.      cat /etc/X11/xorg.conf | sed -e 's/Option\W\+"ZAxisMapping"\W\+"4 5"/#Option      "ZAxisMapping" "4 5"/g' | tr -s '#' > /tmp/xorg.conf.tmp
  373.     fi
  374.    fi
  375.    if [ -f /etc/X11/xorg.conf ];then
  376.     cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
  377.    fi
  378.    sync
  379.  
  380.    #v1.0.7 fix mouse protocol for Xorg...
  381.    if [ -f /etc/X11/xorg.conf ];then
  382.  
  383. #    if [ "`cat /etc/mousedevice`" = "input/mice" ];then
  384. #     cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"auto"\W\+#mouse0protocol/    Option        "Protocol" "IMPS\/2" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  385. #    else
  386. #     cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"IMPS\/2"\W\+#mouse0protocol/    Option        "Protocol" "auto" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  387. #    fi
  388.  
  389.     case `cat /etc/mousedevice | cut -b 1-4` in
  390.      "inpu") #"input/mice", usb
  391.       cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\w\+\W\+#mouse0protocol/    Option        "Protocol" "IMPS\/2" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  392.       ;;
  393.      "ttyS") #ttyS0,1,2,3, serial
  394.       cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\w\+\W\+#mouse0protocol/    Option        "Protocol" "Microsoft" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  395.       ;;
  396.      *)
  397.       cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\w\+\W\+#mouse0protocol/    Option        "Protocol" "auto" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  398.       ;;
  399.     esac
  400.  
  401.     sync
  402.     cp -f /tmp/xorg.conf.tmp2 /etc/X11/xorg.conf
  403.     sync
  404.     rm -f /tmp/xorg.conf.tmp2
  405.    fi
  406.  
  407.   fi
  408.   ;;
  409.  
  410.  *)
  411.   break
  412.   ;;
  413.  esac
  414.  
  415.  
  416.  
  417.  if [ "$KMAP" ];then
  418.   echo -n "$KMAP" > /etc/keymap
  419.   if [ "$FONTMAP" ];then
  420.    echo -n "$FONTMAP" > /etc/fontmap
  421.   fi
  422.   if [ "$CODEPAGE" ];then
  423.    echo -n "$CODEPAGE" > /etc/codepage
  424.   fi
  425.   #in rc.local0, so this will happen every bootup...
  426.   cat /etc/keymap | grep "\\.map" > /dev/null 2>&1 #looking for .map
  427.   if [ $? -eq 0 ];then #=0 found.
  428.    #key layout maps are in /usr/share/kbd, using "kbd" package...
  429.    /usr/sbin/loadkeys $KMAP
  430.    #xwin also set these...
  431.    #echo -e "Loading fontmap \"${FONTMAP}\"..."
  432.    #setfont $FONTMAP  #cat /etc/fontmap | loadfont
  433.    #...this needs work. messes up font set required by dialog program. see also rc.local0.
  434.    #um, also have /etc/codepage, don't know how to do anything with that.
  435.   else
  436.    #this is the technique up to Puppy v0.8.6. KMAP is just a 2-letter code...
  437.    /bin/gzip -dcf /lib/keymaps/$KMAP.gz | /sbin/loadkmap
  438.   fi
  439.   KMAPMSG="You have chosen \"$KMAP\" keyboard map.
  440. Note, this information is saved in file /etc/keymap
  441. Puppy has now loaded and is using this layout.
  442.  
  443. Press OK button to continue Wizard..." 
  444.   Xdialog --title "Keyboard Wizard" --msgbox "$KMAPMSG" 0 0
  445.  fi
  446.  
  447.  
  448. done #end while loop.
  449. unset MouseKeyboardWizard
  450. unset MouseWizard
  451. unset KeyboardFeaturesWizard
  452.  
  453.