home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / X11R6 / bin / xwin < prev   
Encoding:
Text File  |  2006-07-04  |  13.7 KB  |  366 lines

  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2003,2004,2005,2006 www.puppylinux.com
  3. echo "This script will run X windows for you..."
  4.  
  5. #PMEDIA is a broad description of the boot media, ex "usbflash" or "idehd"...
  6. [ -f /etc/rc.d/PMEDIA ] && PMEDIA="`cat /etc/rc.d/PMEDIA`"
  7.  
  8. #0.9.9 enables to start a specific w.m. from commandline...
  9. if [ $1 ];then
  10.  echo -n "$1" > /etc/windowmanager
  11.  #note, /root/.xinitrc uses this file.
  12. fi
  13.  
  14. #v1.0.7
  15. HAVEX="`readlink /usr/X11R6/bin/X`"
  16. if [ "$HAVEX" = "XF86_SVGA" ];then
  17.  #xf86config v3.3.6 creates config file at /etc, wrong place...
  18.  [ -f /etc/XF86Config ] && mv -f /etc/XF86Config /etc/X11/XF86Config
  19. fi
  20.  
  21. #thanks to Stefan Talpalaru (blueflops distro) for ideas for this func...
  22. askkbdlayout ()
  23. {
  24.  KEYBOARD=""
  25.  FONTMAP=""
  26.  CODEPAGE=""
  27.  while :; do
  28.   #removed this: --cancel-label "BACK"
  29.   dialog --no-cancel --menu "Select the keyboard map:\n(UP/DOWN arrows then ENTER key)" 0 0 0\
  30.     $( 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 )\
  31.  2> /tmp/kbdextlayout.txt
  32.   [ $? != 0 ] && return 1
  33.   KEYBOARD=`cat /tmp/kbdextlayout.txt`
  34.   case $KEYBOARD in 
  35.    cz|hu101|pl|ro_win|sk-qwerty|croat|cz-us-qwertz|hu|slovene)
  36.     FONTMAP=/usr/share/kbd/consolefonts/lat2-12.psfu
  37.     CODEPAGE=ISO-8859-2
  38.     break
  39.     ;;
  40.    *)
  41.     FONTMAP=/usr/share/kbd/consolefonts/lat1-12.psfu
  42.     CODEPAGE=ISO-8859-1
  43.     break
  44.     ;;
  45.   esac
  46.  done
  47.  KEYBOARD=$KEYBOARD.map  #.gz
  48.  return 0
  49. }
  50.  
  51. if [ "$HAVEX" = "Xvesa" ];then #0.9.9
  52.  #want to start 1st time with a safe video mode...
  53.  if [ ! -e /etc/videomode ];then
  54.   if [ ! -e /tmp/videomode ];then
  55.    echo -n "0x0111 640x480x16" > /tmp/videomode
  56.    rm -f /tmp/Xflag #precaution.
  57.   fi
  58.  fi
  59.  #...if /tmp/videomode exists, video-wizard is started in ~/.xinitrc
  60.  #...note, if /etc/videomode exists instead, normal X startup.
  61. fi
  62.  
  63. #note, mouse and keyboard types are autodetected in /etc/rc.d/rc.local0 at every bootup,
  64. #so /etc/mousedevice and /etc/keyboardtype have autodetected values in them
  65. #(changeable by Mouse/Keyboard Wizard, but rc.local0 will override if interface not found).
  66.  
  67. if [ ! -e /etc/keymap ];then
  68.  while :; do
  69. #  echo " "
  70. #  echo "When Puppy booted for the very first time, the keyboard layout"
  71. #  echo "was set to \"us\" (USA). You now have the opportunity to change"
  72. #  echo "to a different country, however note that THE CHANGE WILL ONLY"
  73. #  echo "TAKE EFFECT WHEN YOU REBOOT PUPPY."
  74. #  echo
  75. #  echo "These are your choices:"
  76. #  echo "be br cf de dk es fi fr gr hu it jp no pl ru se uk us"
  77. #  echo
  78. #  echo "The choices shown here are very limited. If you need something else,"
  79. #  echo "such as Dvorak layout, or you are unable to type the required letters,"
  80. #  echo "just hit the ENTER key only. This will bring up an extended menu that"
  81. #  echo "you can navigate with the arrow keys..."
  82. #  echo -n "Enter 2-digit code for your country (or just ENTER): "
  83. #  read KMAP
  84. #  if [ "$KMAP" = "" ];then
  85.    askkbdlayout #this is extended menu, func above.
  86.    #...this sets KEYBOARD, FONTMAP, CODEPAGE variables.
  87.    if [ $? -eq 0 ];then
  88.     KMAP="$KEYBOARD"
  89.     break
  90.    else #cancel, error exit.
  91.     KMAP="us"
  92.    fi
  93. #  else
  94. #   break
  95. #  fi
  96.  done #end while loop.
  97.  echo -n "$KMAP" > /etc/keymap
  98.  echo "You have chosen \"$KMAP\" keyboard map."
  99.  echo "Note, this information is saved in file /etc/keymap" 
  100.  if [ "$FONTMAP" ];then
  101.   echo -n "$FONTMAP" > /etc/fontmap
  102.  fi
  103.  if [ "$CODEPAGE" ];then
  104.   echo -n "$CODEPAGE" > /etc/codepage
  105.  fi
  106.  #0.9.6 have copied this code from rc.local0, so this will happen every bootup...
  107.  cat /etc/keymap | grep ".map" > /dev/null 2>&1 #looking for .map
  108.  if [ $? -eq 0 ];then #=0 found.
  109.   #key layout maps are in /usr/share/kbd, using "kbd" package...
  110.   echo -e "Loading \"$KMAP.gz\" keyboard map... "
  111.   KMAP="`echo -n "$KMAP" | cut -f 1 -d '.'`" #v1.0.5 get rid of .map
  112.   /usr/sbin/loadkeys $KMAP
  113.   #xwin also set these...
  114.   #echo -e "Loading fontmap \"${FONTMAP}\"..."
  115.   #setfont $FONTMAP  #cat /etc/fontmap | loadfont
  116.   #...this needs work. messes up font set required by dialog program. see also rc.local0.
  117.   #um, also have /etc/codepage, don't know how to do anything with that.
  118.  else
  119.   #this is the technique up to Puppy v0.8.6. KMAP is just a 2-letter code...
  120.   echo -e "Loading \"$KMAP\" keyboard map... "
  121.   /bin/gzip -dcf /lib/keymaps/$KMAP.gz | /sbin/loadkmap
  122.  fi
  123. fi
  124.  
  125. #update xorg.conf if mouse has changed...
  126. MOUSEDEV="`cat /etc/mousedevice`" #autodetected in rc.local0
  127. OLDMOUSEDEV="`cat /tmp/oldmousedevice`" #set in rc.local0
  128. if [ ! "$OLDMOUSEDEV" = "nothing" ];then #"nothing" on first boot.
  129.  if [ ! "$OLDMOUSEDEV" = "$MOUSEDEV" ];then
  130.   if [ -f /etc/X11/xorg.conf ];then
  131.    case `cat /etc/mousedevice | cut -b 1-4` in
  132.     "inpu") #"input/mice", usb
  133.      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
  134.      ;;
  135.     "ttyS") #ttyS0,1,2,3, serial
  136.      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
  137.      ;;
  138.     *)
  139.      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
  140.      ;;
  141.    esac
  142.    sync
  143.    cp -f /tmp/xorg.conf.tmp2 /etc/X11/xorg.conf
  144.    sync
  145.    rm -f /tmp/xorg.conf.tmp2
  146.   fi
  147.  fi
  148. fi
  149. #ask about scrollwheel... DO NOT ASK, ASSUME YES...
  150. if [ ! -f /etc/mousebuttons ];then
  151.  #dialog --yesno "Do you have a wheel/scroll type of mouse?" 0 0
  152.  #if [ $? -eq 0 ];then
  153.   echo -n "5" > /etc/mousebuttons
  154.   echo -e "The file /etc/mousebuttons has been created, with content \"5\"."
  155.   if [ -f /etc/X11/xorg.conf ];then
  156.    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
  157.    sync
  158.    cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
  159.   fi
  160.  #else
  161.  # echo -n "3" > /etc/mousebuttons
  162.  # echo -e "...you chose \"no\"."
  163.  # echo -e "The file /etc/mousebuttons has been created, with content \"3\"."
  164.  # if [ -f /etc/X11/xorg.conf ];then
  165.  #  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
  166.  #  sync
  167.  #  cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
  168.  # fi
  169.  #fi
  170. fi
  171.  
  172. #now done in /etc/rc.d/rc.modules...
  173. ##alsa sound setup...
  174. #if [ "`cat /etc/modprobe.conf | grep 'snd\-card\-0'`" = "" ];then
  175. # #auto option created by BK for fast operation, less questions...
  176. # alsaconf --auto
  177. #fi
  178.  
  179. #rc.modules now does this...
  180. ##v2.0.0 load correct -agp driver...
  181. #AGPDRIVER="`findhostbridge`" #in /usr/sbin.
  182. #if [ ! "$AGPDRIVER" = "" ];then
  183. # [ "`lsmod | grep "${AGPDRIVER}"`" = "" ] && modprobe "$AGPDRIVER" 2>/dev/null
  184. #fi
  185. ##note, could write $AGPDRIVER to /etc/modprobe.preload to load it at kernel boot.
  186. ##note, it also loads agpgart.ko.
  187.  
  188. #v1.0.7 Puppy XorgWizard...
  189. if [ -f /usr/X11R6/bin/Xorg ];then
  190.  if [ ! -f /etc/X11/xorg.conf ];then
  191.   rm -f /etc/.XLOADED 2> /dev/null #not necessary, precaution.
  192.   #1st dialog offers to use Xvesa...
  193.   /usr/sbin/xorgwizard
  194.   HAVEX="`readlink /usr/X11R6/bin/X`"
  195.  fi
  196. fi
  197. #v1.0.7 J_Reys idea (see note further down)...
  198. if [ -f /etc/.XLOADED ];then
  199.  if [ "`cat /etc/.XLOADED`" = "true" ];then
  200.   #last time X ran, PC hung and had to be rebooted...
  201.   echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  202.   echo '
  203. It seems that last time X ran, the computer hung and you had to reboot.
  204. Have now dropped down to the commandline. If you want to run the Xorg
  205. Video Wizrd, type "xorgwizard", and after configuring /etc/X11/xorg.conf
  206. (hopefully correctly this time!) type "xwin" to start X.'
  207.   echo -e "\\033[0;39m"
  208.   rm -f /etc/.XLOADED #otherwise cannot start X.
  209.   exit
  210.  fi
  211. fi
  212.  
  213. if [ "$HAVEX" = "Xvesa" ];then #0.9.9
  214.  #/tmp/videomode exists if starting X with new video test mode...
  215.  if [ -e /tmp/videomode ];then
  216.   cat /tmp/videomode | grep "0x0111"
  217.   if [ $? -eq 0 ];then #=0 if found.
  218.    if [ -e /tmp/Xflag ];then
  219.     #we have just attempted 640x480x16 and aborted with ctrl-alt-backspace
  220.     #so have failed.
  221.     echo "An attempt has just been made to run X at 640x480x16 but it has"
  222.     echo "not worked (or it did but you did not press the OK button in the"
  223.     echo "Video-wizard). It is not feasible to run Puppy at any lower resolution"
  224.     echo -e "or color. If you want to try again, type \"xwin\" at the prompt."
  225.     echo "It may be helpful to look in /tmp/xerrs.txt for error messages"
  226.     rm -f /tmp/videomode
  227.     rm -f /tmp/Xflag
  228.     echo -n "0x0111 640x480x16" > /etc/videomode
  229.     exit 0
  230.    else
  231.     #flag to prevent endless loop X restarting...
  232.     touch /tmp/Xflag
  233.     #...pressing a button in video-wizard removes this file.
  234.     #...however, aborting X will leave it in existence.
  235.    fi
  236.   fi
  237.  fi
  238.  #/tmp/videomode exists if starting X with new video test mode...
  239.  if [ -e /tmp/videomode ];then
  240.   #stored in format "0x0111 640x480x16"
  241.   VIDMODE="`cat /tmp/videomode | cut -f 1 -d ' '`"
  242.   VIDSCRN="`cat /tmp/videomode | tr -s ' ' | cut -f 2 -d ' '`"
  243.  else
  244.   #stored in format "0x0111 640x480x16"
  245.   VIDMODE="`cat /etc/videomode | cut -f 1 -d ' '`"
  246.   VIDSCRN="`cat /etc/videomode | tr -s ' ' | cut -f 2 -d ' '`"
  247.  fi
  248. fi
  249.  
  250. MOUSEBUTTONS=3
  251. if [ -e /etc/mousebuttons ];then
  252.  MOUSEBUTTONS=`cat /etc/mousebuttons`
  253. fi
  254. #v2.02 fix bug discovered by Dougal...
  255. if [ $MOUSEBUTTONS -eq 2 ];then
  256.  #the problem is, if /etc/xextraoptions has '-2button' which turns on middle-button
  257.  #emulation, if leave MOUSEBUTTONS=2 then the right button does not work.
  258.  #have to pass '3' to Xvesa, meaning effectively 3 buttons available...
  259.  [ ! "`cat /etc/xextraoptions | grep ' \-2button'`" = "" ] && MOUSEBUTTONS=3
  260. fi
  261.  
  262. #0.9.8
  263. XEXTRAOPTIONS=""
  264. if [ -e /etc/xextraoptions ];then
  265.  XEXTRAOPTIONS="`cat /etc/xextraoptions`"
  266. fi
  267.  
  268. #finally, start X...
  269. #J_Rey had a good idea, flag XLOADED... and set to false on exit.
  270. #but if PC hangs, XLOADED will still be true, so will know it is broken.
  271. echo -n "true" > /etc/.XLOADED
  272. case $HAVEX in
  273.  Xvesa)
  274.   echo "Starting X with video mode $VIDMODE and mouse $MOUSEDEV..."
  275.   #startx $VIDMODE $MOUSEDEV > /tmp/xerrs.txt 2>&1
  276.   #Puppy 0.8.4 no need for startx script...
  277.   VIDFREQ="`echo -n "$VIDSCRN" | cut -f 4 -d "x"`"
  278.   if [ ! "$VIDFREQ" ];then
  279.    echo "$VIDMODE" > /tmp/currentvideomode
  280.    /usr/X11R6/bin/xinit /root/.xinitrc -- -mode $VIDMODE $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
  281.   else
  282.    #also, want to have adjustable frequency, VIDSCRN=widthxheightxdepthxfreq...
  283.    echo "$VIDSCRN" > /tmp/currentvideomode
  284.    /usr/X11R6/bin/xinit /root/.xinitrc -- -screen $VIDSCRN $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
  285.   fi
  286.   ;;
  287.  Xfbdev)
  288.   echo "Starting X with Xfbdev Kdrive X server, mouse $MOUSEDEV..."
  289.   /usr/X11R6/bin/xinit /root/.xinitrc -- -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
  290.   ;;
  291.  Xi810) #v1.0.7
  292.   echo "Starting X with Xi810 Kdrive X server, mouse $MOUSEDEV..."
  293.   #echo "(experimental, currently fixed to 1024x768x16x72 in /usr/X11R6/bin/xwin)"
  294.    /usr/X11R6/bin/xinit /root/.xinitrc -- -screen $VIDSCRN -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.txt 2>&1
  295.   ;;
  296.  XF86_SVGA)
  297.   echo "Starting X, specs in /etc/X11/XF86Config, startup apps /root/.xinitrc..."
  298.   /usr/X11R6/bin/xinit /root/.xinitrc -- -bpp 16 > /tmp/xerrs.txt 2>&1
  299.   ;;
  300.  Xorg)
  301.   echo "Starting X, specs in /etc/X11/xorg.conf, startup apps /root/.xinitrc..."
  302.   /usr/X11R6/bin/xinit /root/.xinitrc -- -nolisten tcp > /tmp/xerrs.txt 2>&1
  303.   ;;
  304.  *)
  305.   /usr/X11R6/bin/xinit /root/.xinitrc --  > /tmp/xerrs.txt 2>&1
  306.   ;;
  307. esac
  308. echo -n "false" > /etc/.XLOADED #see note above.
  309. #...if PC hung, run xorgwizard at next bootup (see further up).
  310.  
  311. echo 'Exited from X. Type "xwin [fvwm95|jwm]" to restart X ([ ] mean optional).'
  312. echo '(To shutdown PC type "poweroff", to reboot PC type "reboot")'
  313. if [ -f /usr/X11R6/bin/Xfbdev ];then
  314.  echo '(To run the Xfbdev Framebuffer Wizard, type "framebufferwizard")'
  315. fi
  316. if [ "$HAVEX" = "XF86_SVGA" ];then #v1.0.7
  317.  echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  318.  echo 'If X failed to start, type "xf86config" to setup X'
  319.  echo '  -- you will need to know type of mouse, keyboard and video chip'
  320.  echo '  -- thix X is for pre-2000 video chips, but many recent chips backwards-compat.'
  321.  echo '  -- accept default save /etc/XF86Config, Puppy will move this to /etc/X11'
  322.  echo '  -- (XF86Config is the configuration file for X and can be edited manually)'
  323.  echo -n '  -- LAST RESORT, drop back to Xvesa by typing "ln -sf Xvesa /usr/X11R6/bin/X"'
  324.  echo -e "\\033[0;39m"
  325. fi
  326. if [ "$HAVEX" = "Xorg" ];then #v1.0.7
  327.  echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  328.  echo -n 'If X failed to start, type "xorgwizard" to setup X'
  329.  echo -e "\\033[0;39m"
  330. fi
  331.  
  332. if [ "$HAVEX" = "Xvesa" ];then
  333.  if [ -e /tmp/videomode ];then
  334.   exec xwin #restart X.
  335.  fi
  336. fi
  337.  
  338. #v0.9.8
  339. #/root/.fvwm95rc or .jwmrc calls /usr/X11R6/bin/wmreboot or wmpoweroff at exit,
  340. #which create /tmp/wmexitmode.txt then kill all X processes.
  341. #0.9.9 ditto for w.m. restart calls /usr/X11R6/bin/restartwm.
  342. if [ -f /tmp/wmexitmode.txt ];then
  343.  WMEXITMODE="`cat /tmp/wmexitmode.txt`"
  344.  #rm -f /tmp/wmexitmode.txt ...no, removed in rc.shutdown.
  345.  if [ "$WMEXITMODE" = "poweroff" ];then
  346.   exec /sbin/poweroff
  347.  fi
  348.  if [ "$WMEXITMODE" = "reboot" ];then
  349.   exec /sbin/reboot
  350.  fi
  351.  #0.9.9 restart window manager...
  352.  #make a gross assumption, if wmexitmode.txt exists, haven't already exited this script, then want
  353.  #to restart maybe with different window manager. /etc/windowmanager already has desired w.m.
  354.  rm -f /tmp/wmexitmode.txt #definitely delete it now.
  355.   #v1.0.5 thanks GuestToo for advice on this, works with chooselocale script...
  356.   NEWLANG="`cat /etc/profile | grep "LANG=" | cut -f 2 -d '='`"
  357.   if [ "$NEWLANG" ];then #precaution
  358.    if [ ! "$NEWLANG" = "$LANG" ];then
  359.     export LANG=$NEWLANG
  360.    fi
  361.   fi
  362.  exec xwin
  363. fi
  364.  
  365. #the end#
  366.