home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #(c) Barry Kauler 2005/2006 www.puppylinux.com
- #keyboard/mouse wizard for Puppy Linux
- #based on code from /usr/X11R6/bin/xwin
-
- if [ "`which gtkdialog`" = "" ];then
- xmessage -center -title "ERROR" "This distribution of Puppy is lacking the application gtkdialog,
- which in turn requires the gtk2 libraries package.
- Gtkdialog is needed to run this Wizard.
-
- Press OK button to quit..."
- exit
- fi
-
-
- export MouseKeyboardWizard="
- <vbox>
- <hbox>
- <text>
- <label>Choose keyboard layout for your country...</label>
- </text>
- <button>
- <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
- <label>KEY1BUTTON</label>
- </button>
- </hbox>
- <hbox>
- <text>
- <label>Choose keyboard layout, older 2-letter method...</label>
- </text>
- <button>
- <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
- <label>KEY2BUTTON</label>
- </button>
- </hbox>
- <hbox>
- <text>
- <label>Choose keyboard interface...</label>
- </text>
- <button>
- <input file>/usr/local/lib/X11/mini-icons/mini-keyboard.xpm</input>
- <label>KEY3BUTTON</label>
- </button>
- </hbox>
- <hbox>
- <text>
- <label>Choose type of mouse...</label>
- </text>
- <button>
- <input file>/usr/local/lib/X11/mini-icons/Mouse.xpm</input>
- <label>MOUSE1BUTTON</label>
- </button>
- </hbox>
-
- <hbox>
- <button ok></button>
- </hbox>
- </vbox>
- "
-
- CHECK1="false"
-
-
- askoldkbdlayout ()
- {
- KEYBOARD=""
- 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
- [ $? != 0 ] && return 1
- KEYBOARD="`cat /tmp/kbdextlayout.txt`"
- return 0
- }
-
-
- #thanks to Stefan Talpalaru (blueflops distro) for ideas for this func...
- askkbdlayout ()
- {
- KEYBOARD=""
- FONTMAP=""
- CODEPAGE=""
- #while :; do
- Xdialog --title "Keyboard Wizard" --cancel-label "Cancel" --menu "Select the keyboard layout:" 0 0 0\
- $( 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 )\
- 2> /tmp/kbdextlayout.txt
- [ $? != 0 ] && return 1
- KEYBOARD="`cat /tmp/kbdextlayout.txt`"
- case $KEYBOARD in
- cz|hu101|pl|ro_win|sk-qwerty|croat|cz-us-qwertz|hu|slovene)
- FONTMAP=/usr/share/kbd/consolefonts/lat2-12.psfu
- CODEPAGE=ISO-8859-2
- #break
- ;;
- *)
- FONTMAP=/usr/share/kbd/consolefonts/lat1-12.psfu
- CODEPAGE=ISO-8859-1
- #break
- ;;
- esac
- #done
- KEYBOARD=$KEYBOARD.map #.gz
- return 0
- }
-
- #big while loop...
- while :; do
- KMAP=""
- unset MouseWizard
- unset KeyboardFeaturesWizard
-
- #put some code in here to ask keyboard layout, keyboard ps2/usb, mouse serial/ps2/usb setup?
- #also offer the old 2-letter layout...
- eval `gtkdialog --program=MouseKeyboardWizard | grep "EXIT"`
-
- case $EXIT in
-
- KEY1BUTTON)
- askkbdlayout #this is extended menu, func above.
- #...this sets KEYBOARD, FONTMAP, CODEPAGE variables.
- if [ $? -eq 0 ];then
- KMAP="$KEYBOARD"
- fi
- ;;
-
- KEY2BUTTON)
- askoldkbdlayout
- if [ $? -eq 0 ];then
- KMAP="$KEYBOARD"
- fi
- ;;
-
- KEY3BUTTON)
- KEYBRDTYPE="`cat /etc/keyboardtype`"
- CHECKKEY1="false"
- if [ "$KEYBRDTYPE" = "usb" ];then
- CHECKKEY1="true"
- fi
- export KeyboardFeaturesWizard="
- <vbox>
- <frame Keyboard interface>
- <vbox>
- <text>
- <label>Changing this only takes effect after Puppy is rebooted!</label>
- </text>
- <checkbox>
- <label>Keyboard has USB interface</label>
- <default>$CHECKKEY1</default>
- </checkbox>
- </vbox>
- </frame>
- <hbox>
- <button cancel></button>
- <button ok></button>
- </hbox>
- </vbox>
- "
- RETPARAMS=`gtkdialog --program=KeyboardFeaturesWizard`
- echo "$RETPARAMS"
- if [ ! "`echo "$RETPARAMS" | grep "EXIT" | grep "OK"`" = "" ];then
- if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX002" | grep "true"`" = "" ];then
- echo -n "usb" > /etc/keyboardtype
- if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
- modprobe usbhid 2> /dev/null #maybe then just need to restart X.
- else
- modprobe hid #v2.0.0
- modprobe keybdev #v2.0.0 just in case it got removed.
- fi
- else
- modprobe -r keybdev #v2.0.0
- echo -n "ps/2" > /etc/keyboardtype
- fi
- fi
- ;;
-
- MOUSE1BUTTON)
- MOUSEDEV="`cat /etc/mousedevice`"
- #RADIOBUTTONS="$RADIO2$RADIO1$RADIO3" #serial
- DEF1="false"
- DEF2="true"
- DEF3="false"
- if [ "$MOUSEDEV" = "psaux" ];then
- #RADIOBUTTONS="$RADIO1$RADIO2$RADIO3"
- DEF1="true"
- DEF2="false"
- DEF3="false"
- fi
- if [ "$MOUSEDEV" = "input/mice" ];then
- #RADIOBUTTONS="$RADIO3$RADIO2$RADIO1"
- DEF1="false"
- DEF2="false"
- DEF3="true"
- fi
-
- RADIO1=" <radiobutton>
- <label>PS/2 mouse (most common)</label>
- <variable>RADIO001</variable>
- <default>$DEF1</default>
- <action>if true disable:COMPORT</action>
- </radiobutton>
- "
- RADIO2=" <radiobutton>
- <label>Serial mouse</label>
- <variable>RADIO002</variable>
- <default>$DEF2</default>
- <action>if true enable:COMPORT</action>
- </radiobutton>
- "
- RADIO3=" <radiobutton>
- <label>USB mouse</label>
- <variable>RADIO003</variable>
- <default>$DEF3</default>
- <action>if true disable:COMPORT</action>
- </radiobutton>
- "
- RADIOBUTTONS="$RADIO1$RADIO2$RADIO3"
-
-
- MOUSEBUTTONS="`cat /etc/mousebuttons`"
- CHECK1="false"
- if [ "$MOUSEBUTTONS" = "5" ];then
- CHECK1="true"
- fi
-
- #v1.0.7
- CHECKM="false"
- if [ ! "`cat /etc/xextraoptions | grep "\\-2button"`" = "" ];then
- CHECKM="true"
- fi
- #v2.01
- CHECKH="false"
- IDLETIME="0"
- if [ -f /etc/mousehide ];then
- IDLETIME="`cat /etc/mousehide | cut -f 1 -d ','`"
- [ ! "$IDLETIME" = "0" ] && CHECKH="true"
- fi
-
- #v1.0.7 modified for gtkdialog2...
- export MouseWizard="
- <wtitle>Mouse Wizard</wtitle>
- <vbox>
- <frame Mouse interface>
- <hbox>
- <vbox>
- $RADIOBUTTONS
- </vbox>
- <vbox>
- <text><label>Serial port:</label></text>
- <combobox>
- <item>ttyS0</item>
- <item>ttyS1</item>
- <item>ttyS2</item>
- <item>ttyS3</item>
- <variable>COMPORT</variable>
- <visible>disabled</visible>
- </combobox>
- </vbox>
- </hbox>
- </frame>
- <frame Mouse features>
- <vbox>
- <checkbox>
- <label>Mouse has a scroll wheel</label>
- <variable>CHECKBOX009</variable>
- <default>$CHECK1</default>
- </checkbox>
- <checkbox>
- <label>Middle button emulated on a 2-button mouse</label>
- <variable>CHECKBOX010</variable>
- <default>$CHECKM</default>
- </checkbox>
- <checkbox>
- <label>Auto-hide mouse cursor when not moving</label>
- <variable>CHECKBOX011</variable>
- <default>$CHECKH</default>
- </checkbox>
- </vbox>
- </frame>
- <hbox>
- <button cancel></button>
- <button ok></button>
- </hbox>
- </vbox>
- "
-
- RETPARAMS=`gtkdialog2 --program=MouseWizard`
- echo "$RETPARAMS"
- if [ ! "`echo "$RETPARAMS" | grep "EXIT" | grep "OK"`" = "" ];then
- if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
- modprobe -r psmouse 2> /dev/null #v1.0.2 k2.6
- modprobe -r sermouse 2> /dev/null #v1.0.2 k2.6
- else
- #modprobe -r usbmouse 2> /dev/null #v1.0.2
- modprobe -r mousedev #v2.0.0
- fi
- if [ ! "`echo "$RETPARAMS" | grep "RADIO001" | grep "true"`" = "" ];then
- MOUSEDEV="psaux" #ps/2 mouse.
- ln -sf /dev/psaux /dev/mouse
- #k2.4 has ps/2 mouse support inbuilt.
- if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
- modprobe psmouse 2> /dev/null #v1.0.2 k2.6
- fi
- fi
- if [ ! "`echo "$RETPARAMS" | grep "RADIO002" | grep "true"`" = "" ];then
- eval `echo "$RETPARAMS" | grep "COMPORT"`
- MOUSEDEV="$COMPORT" #ttyS0,1,2,3
- ln -sf /dev/$COMPORT /dev/mouse
- #2.4 kernel has serial mouse support inbuilt.
- if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
- modprobe 8250_pci
- modprobe sermouse
- fi
- fi
- if [ ! "`echo "$RETPARAMS" | grep "RADIO003" | grep "true"`" = "" ];then
- MOUSEDEV="input/mice" #usb mouse
- if [ -e /lib/modules/2.6 ];then #v1.0.2 k2.6...
- modprobe usbhid 2> /dev/null
- else
- #modprobe usbmouse
- modprobe hid #v2.0.0
- modprobe mousedev #v2.0.0
- fi
- ln -sf /dev/input/mice /dev/mouse
- fi
- echo -n "$MOUSEDEV" > /etc/mousedevice
-
- if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX011" | grep "true"`" = "" ];then #v2.01
- [ "$IDLETIME" = "0" ] && IDLETIME="3"
- echo -n "${IDLETIME}," && > /etc/mousehide
- [ "`pidof unclutter`" = "" ] && unclutter -idle $IDLETIME &
- else
- echo -n '0,' > /etc/mousehide
- [ ! "`pidof unclutter`" = "" ] && killall unclutter
- fi
-
- #v1.0.7 emulate middle button
- #v2.02 Dougal has suggested changes for 3-button emulation...
- MBUTOUT="`cat /etc/xextraoptions | sed -e 's/ \-[23]button//g'`"
- if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX010" | grep "true"`" = "" ];then
- #'-2button' tells Xvesa that want 3rd-button emulation...
- echo -n "$MBUTOUT -2button" > /etc/xextraoptions
- echo -n "2" > /etc/mousebuttons
- if [ -f /etc/X11/xorg.conf ];then
- #\W\+ means one or more whitespace chars...
- cat /etc/X11/xorg.conf | tr -s '#' | sed -e 's/#Option\W\+"Emulate3Buttons"/Option "Emulate3Buttons"/g' > /tmp/xorg.conf.tmp2
- sync
- cat /tmp/xorg.conf.tmp2 | tr -s '#' | sed -e 's/#Option\W\+"Emulate3Timeout"/Option "Emulate3Timeout"/g' > /tmp/xorg.conf.tmp
- fi
- else
- #'-3button' tells Xvesa that mouse has 3 buttons so do not want emulation...
- #echo -n "$MBUTOUT -3button" > /etc/xextraoptions
- #umm, no, leave it off, for case of 2-button mouse without emulation...
- #no need to have a explicit '-3button' entry...
- echo -n "$MBUTOUT" > /etc/xextraoptions
- echo -n "3" > /etc/mousebuttons
- if [ -f /etc/X11/xorg.conf ];then
- cat /etc/X11/xorg.conf | sed -e 's/Option\W\+"Emulate3Buttons"/#Option "Emulate3Buttons"/g' | tr -s '#' > /tmp/xorg.conf.tmp2
- sync
- cat /tmp/xorg.conf.tmp2 | sed -e 's/Option\W\+"Emulate3Timeout"/#Option "Emulate3Timeout"/g' | tr -s '#' > /tmp/xorg.conf.tmp
- fi
- fi
- sync
- if [ -f /tmp/xorg.conf.tmp ];then
- cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
- fi
-
- if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX009" | grep "true"`" = "" ];then
- echo -n "5" > /etc/mousebuttons #enable scrollwheel.
- if [ -f /etc/X11/xorg.conf ];then
- 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
- fi
- else
- # echo -n "3" > /etc/mousebuttons ...v1.0.7 moved up.
- if [ -f /etc/X11/xorg.conf ];then
- 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
- fi
- fi
- if [ -f /etc/X11/xorg.conf ];then
- cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
- fi
- sync
-
- #v1.0.7 fix mouse protocol for Xorg...
- if [ -f /etc/X11/xorg.conf ];then
-
- # if [ "`cat /etc/mousedevice`" = "input/mice" ];then
- # 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
- # else
- # 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
- # fi
-
- case `cat /etc/mousedevice | cut -b 1-4` in
- "inpu") #"input/mice", usb
- 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
- ;;
- "ttyS") #ttyS0,1,2,3, serial
- 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
- ;;
- *)
- 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
- ;;
- esac
-
- sync
- cp -f /tmp/xorg.conf.tmp2 /etc/X11/xorg.conf
- sync
- rm -f /tmp/xorg.conf.tmp2
- fi
-
- fi
- ;;
-
- *)
- break
- ;;
- esac
-
-
-
- if [ "$KMAP" ];then
- echo -n "$KMAP" > /etc/keymap
- if [ "$FONTMAP" ];then
- echo -n "$FONTMAP" > /etc/fontmap
- fi
- if [ "$CODEPAGE" ];then
- echo -n "$CODEPAGE" > /etc/codepage
- fi
- #in rc.local0, so this will happen every bootup...
- cat /etc/keymap | grep "\\.map" > /dev/null 2>&1 #looking for .map
- if [ $? -eq 0 ];then #=0 found.
- #key layout maps are in /usr/share/kbd, using "kbd" package...
- /usr/sbin/loadkeys $KMAP
- #xwin also set these...
- #echo -e "Loading fontmap \"${FONTMAP}\"..."
- #setfont $FONTMAP #cat /etc/fontmap | loadfont
- #...this needs work. messes up font set required by dialog program. see also rc.local0.
- #um, also have /etc/codepage, don't know how to do anything with that.
- else
- #this is the technique up to Puppy v0.8.6. KMAP is just a 2-letter code...
- /bin/gzip -dcf /lib/keymaps/$KMAP.gz | /sbin/loadkmap
- fi
- KMAPMSG="You have chosen \"$KMAP\" keyboard map.
- Note, this information is saved in file /etc/keymap
- Puppy has now loaded and is using this layout.
-
- Press OK button to continue Wizard..."
- Xdialog --title "Keyboard Wizard" --msgbox "$KMAPMSG" 0 0
- fi
-
-
- done #end while loop.
- unset MouseKeyboardWizard
- unset MouseWizard
- unset KeyboardFeaturesWizard
-
-