home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #(c) Copyright Barry Kauler 2003,2004,2005,2006 www.puppylinux.com
- echo "This script will run X windows for you..."
-
- #PMEDIA is a broad description of the boot media, ex "usbflash" or "idehd"...
- [ -f /etc/rc.d/PMEDIA ] && PMEDIA="`cat /etc/rc.d/PMEDIA`"
-
- #0.9.9 enables to start a specific w.m. from commandline...
- if [ $1 ];then
- echo -n "$1" > /etc/windowmanager
- #note, /root/.xinitrc uses this file.
- fi
-
- #v1.0.7
- HAVEX="`readlink /usr/X11R6/bin/X`"
- if [ "$HAVEX" = "XF86_SVGA" ];then
- #xf86config v3.3.6 creates config file at /etc, wrong place...
- [ -f /etc/XF86Config ] && mv -f /etc/XF86Config /etc/X11/XF86Config
- fi
-
- #thanks to Stefan Talpalaru (blueflops distro) for ideas for this func...
- askkbdlayout ()
- {
- KEYBOARD=""
- FONTMAP=""
- CODEPAGE=""
- while :; do
- #removed this: --cancel-label "BACK"
- dialog --no-cancel --menu "Select the keyboard map:\n(UP/DOWN arrows then ENTER key)" 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
- }
-
- if [ "$HAVEX" = "Xvesa" ];then #0.9.9
- #want to start 1st time with a safe video mode...
- if [ ! -e /etc/videomode ];then
- if [ ! -e /tmp/videomode ];then
- echo -n "0x0111 640x480x16" > /tmp/videomode
- rm -f /tmp/Xflag #precaution.
- fi
- fi
- #...if /tmp/videomode exists, video-wizard is started in ~/.xinitrc
- #...note, if /etc/videomode exists instead, normal X startup.
- fi
-
- #note, mouse and keyboard types are autodetected in /etc/rc.d/rc.local0 at every bootup,
- #so /etc/mousedevice and /etc/keyboardtype have autodetected values in them
- #(changeable by Mouse/Keyboard Wizard, but rc.local0 will override if interface not found).
-
- if [ ! -e /etc/keymap ];then
- while :; do
- # echo " "
- # echo "When Puppy booted for the very first time, the keyboard layout"
- # echo "was set to \"us\" (USA). You now have the opportunity to change"
- # echo "to a different country, however note that THE CHANGE WILL ONLY"
- # echo "TAKE EFFECT WHEN YOU REBOOT PUPPY."
- # echo
- # echo "These are your choices:"
- # echo "be br cf de dk es fi fr gr hu it jp no pl ru se uk us"
- # echo
- # echo "The choices shown here are very limited. If you need something else,"
- # echo "such as Dvorak layout, or you are unable to type the required letters,"
- # echo "just hit the ENTER key only. This will bring up an extended menu that"
- # echo "you can navigate with the arrow keys..."
- # echo -n "Enter 2-digit code for your country (or just ENTER): "
- # read KMAP
- # if [ "$KMAP" = "" ];then
- askkbdlayout #this is extended menu, func above.
- #...this sets KEYBOARD, FONTMAP, CODEPAGE variables.
- if [ $? -eq 0 ];then
- KMAP="$KEYBOARD"
- break
- else #cancel, error exit.
- KMAP="us"
- fi
- # else
- # break
- # fi
- done #end while loop.
- echo -n "$KMAP" > /etc/keymap
- echo "You have chosen \"$KMAP\" keyboard map."
- echo "Note, this information is saved in file /etc/keymap"
- if [ "$FONTMAP" ];then
- echo -n "$FONTMAP" > /etc/fontmap
- fi
- if [ "$CODEPAGE" ];then
- echo -n "$CODEPAGE" > /etc/codepage
- fi
- #0.9.6 have copied this code from 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...
- echo -e "Loading \"$KMAP.gz\" keyboard map... "
- KMAP="`echo -n "$KMAP" | cut -f 1 -d '.'`" #v1.0.5 get rid of .map
- /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...
- echo -e "Loading \"$KMAP\" keyboard map... "
- /bin/gzip -dcf /lib/keymaps/$KMAP.gz | /sbin/loadkmap
- fi
- fi
-
- #update xorg.conf if mouse has changed...
- MOUSEDEV="`cat /etc/mousedevice`" #autodetected in rc.local0
- OLDMOUSEDEV="`cat /tmp/oldmousedevice`" #set in rc.local0
- if [ ! "$OLDMOUSEDEV" = "nothing" ];then #"nothing" on first boot.
- if [ ! "$OLDMOUSEDEV" = "$MOUSEDEV" ];then
- if [ -f /etc/X11/xorg.conf ];then
- 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
- fi
- #ask about scrollwheel... DO NOT ASK, ASSUME YES...
- if [ ! -f /etc/mousebuttons ];then
- #dialog --yesno "Do you have a wheel/scroll type of mouse?" 0 0
- #if [ $? -eq 0 ];then
- echo -n "5" > /etc/mousebuttons
- echo -e "The file /etc/mousebuttons has been created, with content \"5\"."
- 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
- sync
- cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
- fi
- #else
- # echo -n "3" > /etc/mousebuttons
- # echo -e "...you chose \"no\"."
- # echo -e "The file /etc/mousebuttons has been created, with content \"3\"."
- # 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
- # sync
- # cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
- # fi
- #fi
- fi
-
- #now done in /etc/rc.d/rc.modules...
- ##alsa sound setup...
- #if [ "`cat /etc/modprobe.conf | grep 'snd\-card\-0'`" = "" ];then
- # #auto option created by BK for fast operation, less questions...
- # alsaconf --auto
- #fi
-
- #rc.modules now does this...
- ##v2.0.0 load correct -agp driver...
- #AGPDRIVER="`findhostbridge`" #in /usr/sbin.
- #if [ ! "$AGPDRIVER" = "" ];then
- # [ "`lsmod | grep "${AGPDRIVER}"`" = "" ] && modprobe "$AGPDRIVER" 2>/dev/null
- #fi
- ##note, could write $AGPDRIVER to /etc/modprobe.preload to load it at kernel boot.
- ##note, it also loads agpgart.ko.
-
- #v1.0.7 Puppy XorgWizard...
- if [ -f /usr/X11R6/bin/Xorg ];then
- if [ ! -f /etc/X11/xorg.conf ];then
- rm -f /etc/.XLOADED 2> /dev/null #not necessary, precaution.
- #1st dialog offers to use Xvesa...
- /usr/sbin/xorgwizard
- HAVEX="`readlink /usr/X11R6/bin/X`"
- fi
- fi
- #v1.0.7 J_Reys idea (see note further down)...
- if [ -f /etc/.XLOADED ];then
- if [ "`cat /etc/.XLOADED`" = "true" ];then
- #last time X ran, PC hung and had to be rebooted...
- echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
- echo '
- It seems that last time X ran, the computer hung and you had to reboot.
- Have now dropped down to the commandline. If you want to run the Xorg
- Video Wizrd, type "xorgwizard", and after configuring /etc/X11/xorg.conf
- (hopefully correctly this time!) type "xwin" to start X.'
- echo -e "\\033[0;39m"
- rm -f /etc/.XLOADED #otherwise cannot start X.
- exit
- fi
- fi
-
- if [ "$HAVEX" = "Xvesa" ];then #0.9.9
- #/tmp/videomode exists if starting X with new video test mode...
- if [ -e /tmp/videomode ];then
- cat /tmp/videomode | grep "0x0111"
- if [ $? -eq 0 ];then #=0 if found.
- if [ -e /tmp/Xflag ];then
- #we have just attempted 640x480x16 and aborted with ctrl-alt-backspace
- #so have failed.
- echo "An attempt has just been made to run X at 640x480x16 but it has"
- echo "not worked (or it did but you did not press the OK button in the"
- echo "Video-wizard). It is not feasible to run Puppy at any lower resolution"
- echo -e "or color. If you want to try again, type \"xwin\" at the prompt."
- echo "It may be helpful to look in /tmp/xerrs.txt for error messages"
- rm -f /tmp/videomode
- rm -f /tmp/Xflag
- echo -n "0x0111 640x480x16" > /etc/videomode
- exit 0
- else
- #flag to prevent endless loop X restarting...
- touch /tmp/Xflag
- #...pressing a button in video-wizard removes this file.
- #...however, aborting X will leave it in existence.
- fi
- fi
- fi
- #/tmp/videomode exists if starting X with new video test mode...
- if [ -e /tmp/videomode ];then
- #stored in format "0x0111 640x480x16"
- VIDMODE="`cat /tmp/videomode | cut -f 1 -d ' '`"
- VIDSCRN="`cat /tmp/videomode | tr -s ' ' | cut -f 2 -d ' '`"
- else
- #stored in format "0x0111 640x480x16"
- VIDMODE="`cat /etc/videomode | cut -f 1 -d ' '`"
- VIDSCRN="`cat /etc/videomode | tr -s ' ' | cut -f 2 -d ' '`"
- fi
- fi
-
- MOUSEBUTTONS=3
- if [ -e /etc/mousebuttons ];then
- MOUSEBUTTONS=`cat /etc/mousebuttons`
- fi
- #v2.02 fix bug discovered by Dougal...
- if [ $MOUSEBUTTONS -eq 2 ];then
- #the problem is, if /etc/xextraoptions has '-2button' which turns on middle-button
- #emulation, if leave MOUSEBUTTONS=2 then the right button does not work.
- #have to pass '3' to Xvesa, meaning effectively 3 buttons available...
- [ ! "`cat /etc/xextraoptions | grep ' \-2button'`" = "" ] && MOUSEBUTTONS=3
- fi
-
- #0.9.8
- XEXTRAOPTIONS=""
- if [ -e /etc/xextraoptions ];then
- XEXTRAOPTIONS="`cat /etc/xextraoptions`"
- fi
-
- #finally, start X...
- #J_Rey had a good idea, flag XLOADED... and set to false on exit.
- #but if PC hangs, XLOADED will still be true, so will know it is broken.
- echo -n "true" > /etc/.XLOADED
- case $HAVEX in
- Xvesa)
- echo "Starting X with video mode $VIDMODE and mouse $MOUSEDEV..."
- #startx $VIDMODE $MOUSEDEV > /tmp/xerrs.txt 2>&1
- #Puppy 0.8.4 no need for startx script...
- VIDFREQ="`echo -n "$VIDSCRN" | cut -f 4 -d "x"`"
- if [ ! "$VIDFREQ" ];then
- echo "$VIDMODE" > /tmp/currentvideomode
- /usr/X11R6/bin/xinit /root/.xinitrc -- -mode $VIDMODE $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
- else
- #also, want to have adjustable frequency, VIDSCRN=widthxheightxdepthxfreq...
- echo "$VIDSCRN" > /tmp/currentvideomode
- /usr/X11R6/bin/xinit /root/.xinitrc -- -screen $VIDSCRN $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
- fi
- ;;
- Xfbdev)
- echo "Starting X with Xfbdev Kdrive X server, mouse $MOUSEDEV..."
- /usr/X11R6/bin/xinit /root/.xinitrc -- -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
- ;;
- Xi810) #v1.0.7
- echo "Starting X with Xi810 Kdrive X server, mouse $MOUSEDEV..."
- #echo "(experimental, currently fixed to 1024x768x16x72 in /usr/X11R6/bin/xwin)"
- /usr/X11R6/bin/xinit /root/.xinitrc -- -screen $VIDSCRN -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
- ;;
- XF86_SVGA)
- echo "Starting X, specs in /etc/X11/XF86Config, startup apps /root/.xinitrc..."
- /usr/X11R6/bin/xinit /root/.xinitrc -- -bpp 16 > /tmp/xerrs.txt 2>&1
- ;;
- Xorg)
- echo "Starting X, specs in /etc/X11/xorg.conf, startup apps /root/.xinitrc..."
- /usr/X11R6/bin/xinit /root/.xinitrc -- -nolisten tcp > /tmp/xerrs.txt 2>&1
- ;;
- *)
- /usr/X11R6/bin/xinit /root/.xinitrc -- > /tmp/xerrs.txt 2>&1
- ;;
- esac
- echo -n "false" > /etc/.XLOADED #see note above.
- #...if PC hung, run xorgwizard at next bootup (see further up).
-
- echo 'Exited from X. Type "xwin [fvwm95|jwm]" to restart X ([ ] mean optional).'
- echo '(To shutdown PC type "poweroff", to reboot PC type "reboot")'
- if [ -f /usr/X11R6/bin/Xfbdev ];then
- echo '(To run the Xfbdev Framebuffer Wizard, type "framebufferwizard")'
- fi
- if [ "$HAVEX" = "XF86_SVGA" ];then #v1.0.7
- echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
- echo 'If X failed to start, type "xf86config" to setup X'
- echo ' -- you will need to know type of mouse, keyboard and video chip'
- echo ' -- thix X is for pre-2000 video chips, but many recent chips backwards-compat.'
- echo ' -- accept default save /etc/XF86Config, Puppy will move this to /etc/X11'
- echo ' -- (XF86Config is the configuration file for X and can be edited manually)'
- echo -n ' -- LAST RESORT, drop back to Xvesa by typing "ln -sf Xvesa /usr/X11R6/bin/X"'
- echo -e "\\033[0;39m"
- fi
- if [ "$HAVEX" = "Xorg" ];then #v1.0.7
- echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
- echo -n 'If X failed to start, type "xorgwizard" to setup X'
- echo -e "\\033[0;39m"
- fi
-
- if [ "$HAVEX" = "Xvesa" ];then
- if [ -e /tmp/videomode ];then
- exec xwin #restart X.
- fi
- fi
-
- #v0.9.8
- #/root/.fvwm95rc or .jwmrc calls /usr/X11R6/bin/wmreboot or wmpoweroff at exit,
- #which create /tmp/wmexitmode.txt then kill all X processes.
- #0.9.9 ditto for w.m. restart calls /usr/X11R6/bin/restartwm.
- if [ -f /tmp/wmexitmode.txt ];then
- WMEXITMODE="`cat /tmp/wmexitmode.txt`"
- #rm -f /tmp/wmexitmode.txt ...no, removed in rc.shutdown.
- if [ "$WMEXITMODE" = "poweroff" ];then
- exec /sbin/poweroff
- fi
- if [ "$WMEXITMODE" = "reboot" ];then
- exec /sbin/reboot
- fi
- #0.9.9 restart window manager...
- #make a gross assumption, if wmexitmode.txt exists, haven't already exited this script, then want
- #to restart maybe with different window manager. /etc/windowmanager already has desired w.m.
- rm -f /tmp/wmexitmode.txt #definitely delete it now.
- #v1.0.5 thanks GuestToo for advice on this, works with chooselocale script...
- NEWLANG="`cat /etc/profile | grep "LANG=" | cut -f 2 -d '='`"
- if [ "$NEWLANG" ];then #precaution
- if [ ! "$NEWLANG" = "$LANG" ];then
- export LANG=$NEWLANG
- fi
- fi
- exec xwin
- fi
-
- #the end#
-