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 / framebufferwizard < prev    next >
Encoding:
Text File  |  2005-11-28  |  14.1 KB  |  449 lines

  1. #!/bin/sh
  2. #(c) Copyright 2005 Barry Kauler www.goosee.com/puppy
  3. #pup up to 1.0.3 only used Xvesa Kdrive server.
  4. #v1.0.4 introduces framebuffer Xfbdev Kdriver server, choice
  5. #at first bootup.
  6.  
  7. PSFND="`ps`"
  8. MSGWIN="WARNING: CHOOSING \"YES\" WILL CAUSE IMMEDIATE REBOOT!"
  9. if [ ! "`echo -n "$PSFND" | grep "/bin/xwin"`" = "" ];then
  10.  MSGWIN="PLEASE CLOSE ALL OTHER WINDOWS BEFORE CHOOSE \"YES\"!
  11. DO THAT RIGHT NOW IF YOU ARE GOING TO CHOOSE THE \"YES\" OPTION!"
  12. fi
  13. MSGFB="
  14. CURRENT STATUS:
  15. The Xfbdev Kdrive framebuffer X server is currently not running.
  16. "
  17. if [ "`readlink /usr/X11R6/bin/X`" = "Xfbdev"  ];then
  18.  MSGFB="
  19. CURRENT STATUS:
  20. The Xfbdev Kdrive framebuffer X server is currently running,
  21. and the video setting currently is:
  22.  `cat /etc/videofb`
  23. "
  24. fi
  25. if [ "`readlink /usr/X11R6/bin/X`" = "Xvesa"  ];then
  26.  MSGFB="
  27. The Xfbdev Kdrive framebuffer X server is currently not running.
  28. The Xvesa Kdrive X server is now running.
  29. To keep the current situation, select \"No\" button.
  30. To adjust Xvesa settings, run the Xvesa Video Wizard.
  31. "
  32. fi
  33.  
  34. #will call this script from /etc/rc.d/rc.local0, after /usr is loaded,
  35. #as this script and modinfo are both in /usr/sbin/.
  36. #rc.local0 appends "boot" on the commandline...
  37. if [ ! "$1" = "boot" ];then
  38.  if [ ! -f /usr/X11R6/bin/Xfbdev ];then #precaution.
  39.   dialog --title "Xfbdev Video Wizard" --msgbox "Sorry, this build of Puppy does not
  40. have the Xfbdev Kdrive X server.
  41.  
  42. Press ENTER key to exit..." 0 0
  43.   exit
  44.  fi
  45.  dialog --title "Xfbdev Video Wizard" --yesno "Welcome to the Framebuffer Wizard!
  46. Puppy has two different Kdrive X servers, Xvesa and Xfbdev.
  47. Xvesa is the default and works on most PCs. Xfbdev may work
  48. on some video hardware that Xvesa does not work properly on,
  49. also Xfbdev allows adjustment of the screen refresh frequency.
  50.  
  51. The Framebuffer Wizard can only make changes at bootup, so if
  52. you answer \"Yes\" here, the PC will reboot immediately and the
  53. Wizard will run.
  54. $MSGFB
  55. $MSGWIN
  56. Press ENTER key while \"Yes\" highlighted (for immediate reboot)
  57. otherwise TAB or RIGHT-ARROW to highlight \"No\" then ENTER..." 0 0
  58.  if [ $? -eq 0 ];then
  59.   #rm -f /usr/X11R6/bin/X
  60.   echo -n "1" > /root/.fbbootflag
  61.   sync
  62.   if [ "`echo -n "$PSFND" | grep "/bin/xwin"`" = "" ];then
  63.    exec reboot #running without X.
  64.   else
  65.    exec /usr/X11R6/bin/fvwmreboot #a window manager is running.
  66.   fi
  67.  fi
  68.  exit
  69. fi
  70. #did pass "boot" param, so continuing...
  71.  
  72.  
  73. loadfbfunc() {
  74.  case $VIDEOMODULE in
  75.   sisfb)
  76.    MODEXEC="modprobe sisfb mode=$RESXYB rate=$FBRATE"
  77.    modprobe sisfb mode=$RESXYB rate=$FBRATE 2> /tmp/fbmnterr.txt
  78.    RETVAL=$?
  79.    ;;
  80.   tridentfb)
  81.    MODEXEC="modprobe tridentfb mode=$RESXYN bpp=$RESBPP"
  82.    modprobe tridentfb mode=$RESXYN bpp=$RESBPP 2> /tmp/fbmnterr.txt
  83.    RETVAL=$?
  84.    ;;
  85.   intelfb)
  86.    MODEXEC="modprobe intelfb mode=${RESXYN}-${RESBPP}@${FBRATE} accel=1 mtrr=1"
  87.    modprobe intelfb mode=${RESXYN}\-${RESBPP}@${FBRATE} accel=1 mtrr=1 2> /tmp/fbmnterr.txt
  88.    RETVAL=$?
  89.    ;;
  90.   neofb)
  91.    MODEXEC='modprobe neofb #note, no params.'
  92.    modprobe neofb  2> /tmp/fbmnterr.txt #note, no params?
  93.    RETVAL=$?
  94.    ;;
  95.   rivafb)
  96.    MODEXEC='modprobe rivafb #note, no params.'
  97.    modprobe rivafb  2> /tmp/fbmnterr.txt #note, no params?
  98.    RETVAL=$?
  99.    ;;
  100.  esac
  101. }
  102.  
  103. #just use the existing configuration if /root/.fbbootflag=0...
  104. if [ ! -f /root/.fbbootflag ];then
  105.  echo -n "1" > /root/.fbbootflag
  106. fi
  107. if [ "`cat /root/.fbbootflag`" = "0" ];then
  108.  if [ "`readlink /usr/X11R6/bin/X`" = "Xfbdev"  ];then
  109.   if [ -f /etc/videofb ];then #precaution
  110.    VIDEOFB="`cat /etc/videofb`"
  111.    VIDEOMODULE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "module=" | cut -f 2 -d '='`"
  112.    FBRATE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "rate=" | cut -f 2 -d '='`"
  113.    RESXYB="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mode=" | cut -f 2 -d '='`"
  114.    FBMEM="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mem=" | cut -f 2 -d '='`"
  115.    RESXYN="`echo -n "$RESXYB" | cut -f 1-2 -d 'x'`"
  116.    RESBPP="`echo -n "$RESXYB" | cut -f 3 -d 'x'`"
  117.    loadfbfunc
  118.    sleep 1
  119.    if [ ! $RETVAL -eq 0 ];then
  120.     ln -sf Xvesa /usr/X11R6/bin/X
  121.    fi
  122.   else #precaution
  123.    ln -sf Xvesa /usr/X11R6/bin/X
  124.   fi
  125.  else
  126.   #well, do not need the fb modules...
  127.   rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  128.   rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  129.   rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  130.   rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  131.  fi
  132.  exit #use Xvesa, or whatever X points to.
  133. fi
  134.  
  135.  
  136. ###############################################
  137. #okay, this is the wizard part of the script...
  138.  
  139. if [ -f /usr/X11R6/bin/Xvesa ];then
  140.  Xvesa -listmodes > /tmp/Xmodes.txt 2>&1
  141. else
  142.  echo -n "" > /tmp/Xmodes.txt
  143. fi
  144.  
  145. FBMODE=""
  146. MSG0=""
  147. #if [ -f /etc/videomode ];then
  148. # FBMODE="`cat /etc/videomode`"
  149. #fi
  150. FBMODE="1024x768x16"
  151. FBMODULE=""
  152. FBMEM=""
  153. VIDEOFB=""
  154. if [ -f /etc/videofb ];then
  155.  VIDEOFB="`cat /etc/videofb`"
  156.  FBMODULE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "module=" | cut -f 2 -d '='`"
  157.  FBRATE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "rate=" | cut -f 2 -d '='`"
  158.  FBMODE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mode=" | cut -f 2 -d '='`"
  159.  FBMEM="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mem=" | cut -f 2 -d '='`"
  160.  #MSG0="(Note, your last choice was the $FBMODULE module)
  161.  MSG0="(Previous: $VIDEOFB)
  162. "
  163. fi
  164. if [ ! "$FBRATE" ];then
  165.  FBRATE="60"
  166. fi
  167.  
  168. #VIDEOINFO="`cat /proc/pci | grep --ignore-case --extended-regexp "vga|video"`"
  169. VIDEOINFO="`cat /proc/pci | grep "VGA" | cut -f 2-4 -d ':'`"
  170. VIDEOMODULE=""
  171.  
  172. if [ ! "`echo "$VIDEOINFO" | grep "SiS"`" = "" ];then
  173.  VIDEOCHIP="SiS"
  174.  VIDEOMODULE="sisfb"
  175.  #FBDESCRIPTION="SiS 300/540/630/730/315/550/65x/661/74x/330/760 framebuffer device"
  176. fi
  177. if [ ! "`echo "$VIDEOINFO" | grep "Trident"`" = "" ];then
  178.  VIDEOCHIP="Trident"
  179.  VIDEOMODULE="tridentfb"
  180.  #FBDESCRIPTION="Framebuffer driver for Trident cards"
  181. fi
  182. if [ ! "`echo "$VIDEOINFO" | grep "Intel"`" = "" ];then
  183.  VIDEOCHIP="Intel"
  184.  VIDEOMODULE="intelfb"
  185.  #FBDESCRIPTION="Framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G chipset"
  186. fi
  187. if [ ! "`echo "$VIDEOINFO" | grep -i "NeoMagic"`" = "" ];then
  188.  VIDEOCHIP="NeoMagic"
  189.  VIDEOMODULE="neofb"
  190. fi
  191. if [ ! "`echo "$VIDEOINFO" | grep -i "nVidia"`" = "" ];then
  192.  VIDEOCHIP="nVidia"
  193.  VIDEOMODULE="rivafb"
  194. fi
  195.  
  196. if [ -f /usr/X11R6/bin/Xvesa ];then
  197.  MSGXVESA=" Puppy will default to using the Xvesa Kdrive X server,
  198.  which works on most PCs and is usually best choice."
  199.  DEFLABEL="Xvesa"
  200. else
  201.  MSGXVESA=" Puppy would like to fall back to the Xvesa Kdrive X server,
  202.  but it is not installed. So, cannot run X with Xvesa."
  203.  DEFLABEL="Default"
  204. fi
  205.  
  206. #okay to run modinfo as /usr/sbin is available...
  207. FBDESCRIPTION="`modinfo $VIDEOMODULE | grep "description:" | cut -f 2-4 -d ':' | cut -b 1-68`"
  208.  
  209. if [ "$VIDEOMODULE" ];then
  210.  MSG1="Your PC has a $VIDEOCHIP video chip, described as:
  211.  $VIDEOINFO
  212. The $VIDEOMODULE framebuffer driver module description:
  213.  $FBDESCRIPTION
  214. ...so perhaps will work with your video chip?
  215. $MSG0
  216. If you just press the ENTER key, Puppy will default to not using
  217. a framebuffer driver and the default will be:
  218. $MSGXVESA
  219.  
  220. Note: you can try both. Choose the default now maybe, later you
  221. will be able to run the Video Wizard and make a different choice.
  222.  
  223. Press ENTER key while \"${DEFLABEL}\" highlighted for default, else TAB or
  224. ARROW-KEY to highlight \"Framebuffer\" then ENTER for framebuffer..."
  225. else
  226.  #framebuffer option not currently supported.
  227.  dialog --title "Xfbdev Video Wizard" --msgbox "This version of Puppy does not seem to have any suitable
  228. kernel framebuffer driver module for the video hardware.
  229. So, defaulting to:
  230. $MSGXVESA
  231.  
  232. Press ENTER key to continue..."
  233.  rm -f /etc/videofb
  234.  if [ -f /usr/X11R6/bin/Xvesa ];then
  235.   ln -sf Xvesa /usr/X11R6/bin/X #precaution.
  236.  fi
  237.  #to prevent wizard from running in setup mode at next entry...
  238.  echo -n "0" > /root/.fbbootflag #precaution.
  239.  #well, do not need the fb modules...
  240.  rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  241.  rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  242.  rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  243.  rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  244.  exit
  245. fi
  246.  
  247. dialog --title "Xfbdev Video Wizard" --yes-label "$DEFLABEL" --no-label "Framebuffer" --yesno "$MSG1" 0 0
  248. if [ $? -eq 0 ];then
  249.  #rm -f /etc/videofb
  250.  if [ -f /usr/X11R6/bin/Xvesa ];then
  251.   ln -sf Xvesa /usr/X11R6/bin/X
  252.  fi
  253.  #to prevent wizard from running in setup mode at next entry...
  254.  echo -n "0" > /root/.fbbootflag
  255.  #well, do not need the fb modules...
  256.  rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  257.  rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  258.  rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  259.  rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  260.  exit
  261. fi
  262.  
  263. ALLVIDCHOICES="640x480x16
  264. 640x480x24
  265. 800x600x16
  266. 800x600x24
  267. 1024x768x16
  268. 1024x768x24
  269. 1280x960x16
  270. 1280x1024x16
  271. 1280x1024x24
  272. 1600x1200x16
  273. 1600x1200x24
  274. 1920x1440x16
  275. 1920x1440x24"
  276.  
  277. VIDEOCHOICES="`cat /tmp/Xmodes.txt | grep --extended-regexp "640x480x16|640x480x24|800x600x16|800x600x24|1024x768x16|1024x768x24|1280x960x16|1280x1024x16|1280x1024x24|1600x1200x16|1600x1200x24|1920x1440x16|1920x1440x24" | tr ':' ' ' | tr -s ' ' | cut -f 2 -d " " | sort`"
  278. NEWCHOICES="`echo -n "$VIDEOCHOICES" | grep -v "$FBMODE" | tr "\n" "V" | sed -e 's/V/_supported off V/g' | tr "V" "\n"`"
  279. OLDCHOICE=""
  280. if [ "$FBMODE" ];then
  281.  if [ "`echo -n "$VIDEOCHOICES" | grep "$FBMODE"`" = "" ];then
  282.   OLDCHOICE="${FBMODE}_unknown on 
  283. "
  284.  else
  285.   OLDCHOICE="${FBMODE}_supported on 
  286. "
  287.  fi
  288.  
  289.  #OLDCHOICE="`echo -n "$VIDEOCHOICES" | grep "$FBMODE" | tr "\n" "V" | sed -e 's/V/_supported on V/g' | tr "V" "\n"`"
  290.  #if [ ! "$OLDCHOICE" ];then
  291.  # OLDCHOICE="`echo "$FBMODE" | tr "\n" "V" | sed -e 's/V/_unknown on V/g' | tr "V" "\n"`"
  292.  #fi
  293. fi
  294.  
  295. #find unsupported modes...
  296. #and insert column 1 with a tag number...
  297. BADCHOICES=""
  298. FINALCHOICES=""
  299. for ONEMODE in `echo -n "$ALLVIDCHOICES" | tr "\n" " "`
  300. do
  301.  TAGCNT="$ONEMODE"
  302.  if [ "`echo -n "$OLDCHOICE$NEWCHOICES" | grep "$ONEMODE"`" = "" ];then
  303.   FINALCHOICES="${FINALCHOICES} ${TAGCNT} ${ONEMODE}_unknown off "
  304.  else
  305.   ONEMODE="`echo -n "$OLDCHOICE$NEWCHOICES" | grep "$ONEMODE"`"
  306.   FINALCHOICES="${FINALCHOICES} ${TAGCNT} ${ONEMODE}"
  307.  fi
  308. done
  309.  
  310.  
  311. dialog --title "Xfbdev Video Wizard" --radiolist "Please choose a video mode. The format is widthxheightxbits.
  312. Width and height are in pixels, 16/24 bits = 65,536/16,777,216 colors.
  313. Note: _supported means mode confirmed supported by the video card.
  314.       _unknown   will not work with Xvesa but may work with framebuffer.
  315.  
  316. Use DOWN-ARROW then press SPACEBAR on desired choice then
  317. press ENTER key..." 0 0 0 $FINALCHOICES 2>/tmp/tag.txt
  318.  
  319. CHOSENTAG="`cat /tmp/tag.txt 2>/dev/null`"
  320. if [ "$CHOSENTAG" ];then
  321.  FBMODE="$CHOSENTAG"
  322. else
  323.  if [ ! "$FBMODE" ];then
  324.   FBMODE="1024x768x16"
  325.  fi
  326. fi
  327.  
  328.  
  329. RATES='56 Hertz_for_very_low_quality_monitor
  330. 60 Hertz_for_low_quality_monitor_or_high_res
  331. 72 Hertz
  332. 75 Hertz
  333. 85 Hertz
  334. 90 Hertz'
  335. NEWRATES="`echo "$RATES" | grep -v "$FBRATE" | tr "\n" "W" | sed -e 's/W/ off /g'`"
  336. OLDRATE="`echo "$FBRATE" | tr "\n" "W" | sed -e 's/W/ Hertz on /g'`"
  337.  
  338. dialog --title "Xfbdev Video Wizard" --radiolist "You have chosen $FBMODE.
  339. Now you need to choose the screen refresh frequency.
  340. Please be very careful about this -- choosing a higher rate
  341. than your monitor is specified for can damage the monitor.
  342. IF IN DOUBT, CHOOSE 60Hz.
  343. (a really old 14 inch monitor may be limited to 800x600-56)
  344.  
  345. NOTE: If make wrong choice, there is opportunity to try again.
  346.  
  347. Use DOWN-ARROW then press SPACEBAR on desired choice then
  348. press ENTER key..." 0 0 0 $OLDRATE$NEWRATES 2>/tmp/tag.txt
  349.  
  350. CHOSENTAG="`cat /tmp/tag.txt 2>/dev/null`"
  351. if [ "$CHOSENTAG" ];then
  352.  FBRATE="$CHOSENTAG"
  353. fi
  354.  
  355. #so far we have these. examples:
  356. #VIDEOMODULE="sisfb" FBMODE="0x0117 1024x768x16" FBRATE="60"
  357. #now need to decide on a mem= allocation for each mode.
  358. #1024x768x16 needs 12288K ...maybe we can leave this out, let it auto-assign.
  359.  
  360. #then compose the /etc/videofb line:
  361. # sisfb mode=1024x768x16 rate=60 mem=12288
  362. #this can be executed as a postfix to modprobe.
  363. RESXYB="`echo -n "$FBMODE" | cut -f 2 -d " "`"
  364. RESXYN="`echo -n "$RESXYB" | cut -f 1-2 -d 'x'`"
  365. RESBPP="`echo -n "$RESXYB" | cut -f 3 -d 'x'`"
  366. if [ -f /etc/videofb ];then
  367.  cp -f /etc/videofb /etc/videofb.old
  368. fi
  369. echo "module=$VIDEOMODULE mode=$RESXYB rate=$FBRATE mem=" > /etc/videofb
  370.  
  371. dialog --title "Xfbdev Video Wizard" --msgbox "Okay, just about to take the plunge.
  372. Here are the choices you have made:
  373.  `cat /etc/videofb`
  374.  
  375. If the next screen shows a nice dialog box, like this one, then the
  376. video mode change was successful. If the screen is blank or garbage,
  377. then failure.
  378. If successful, press ENTER key within 30 seconds.
  379. If failure, either hit CTRL-ALT-DEL to cause immediate reboot, or
  380. wait for 30 seconds and timeout will assume failure.
  381.  
  382. REMEMBER, Garbage screen: CTRL-ALT-DEL or wait 30 second timeout!
  383.  
  384. Press ENTER key now to switch to new video mode..." 0 0
  385.  
  386. #load fb module...
  387. loadfbfunc
  388. sleep 3
  389.  
  390. #if loading of fb modules succeeds, relink /usr/X11R6/bin/X to Xfbdev,
  391. #otherwise to Xvesa.
  392. if [ $RETVAL -eq 0 ];then
  393.  dialog --timeout 30 --title "Xfbdev Video Wizard" --msgbox "Okay, have loaded framebuffer driver with this command:
  394. $MODEXEC
  395. which seems to have been successful.
  396. X graphics mode will run with the Xfbdev Kdrive X server.
  397. NOTE: framebufferwizard can run from the console if X not work.
  398.  
  399. PLEASE PRESS ENTER KEY WITHIN 30 SECONDS OF THIS WINDOW APPEARING
  400. OTHERWISE FAILURE WILL BE ASSUMED!
  401.  
  402. Press the ENTER key to continue..." 0 0
  403.  if [ $? -eq 0 ];then
  404.   #works.
  405.   ln -sf Xfbdev /usr/X11R6/bin/X
  406.  else
  407.   #failure
  408.   if [ -f /usr/X11R6/bin/Xvesa ];then
  409.    ln -sf Xvesa /usr/X11R6/bin/X #precaution.
  410.   fi
  411.   sync
  412.   exec reboot
  413.   #...wizard will start again on reboot.
  414.  fi
  415. else
  416.  MSGFIN1=""
  417.  if [ -f /usr/X11R6/bin/Xvesa ];then
  418.   MSGFIN1="Note, if you choose \"Quit\", Puppy will use the Xvesa server.
  419. "
  420.  fi
  421.  dialog --title "Xfbdev Video Wizard" --yes-label "Rerun" --no-label "Quit" --yesno "Attempted to load framebuffer driver with this command:
  422. $MODEXEC
  423. but it was unsuccessful. This is the error message:
  424. `cat /tmp/fbmnterr.txt | head -n 5`
  425.  
  426. Select \"Rerun\" button to rerun the Framebuffer Wizard and
  427. try again, or \"Quit\" to quit.
  428. $MSGFIN1
  429. NOTE: framebufferwizard can run from the console if X not work." 0 0
  430.  if [ $? -eq 0 ];then
  431.   sync
  432.   exec /usr/sbin/framebufferwizard
  433.   #...exits from script.
  434.  else
  435.   if [ -f /etc/videofb.old ];then
  436.    cp -f /etc/videofb.old /etc/videofb
  437.   fi
  438.   if [ -f /usr/X11R6/bin/Xvesa ];then
  439.    ln -sf Xvesa /usr/X11R6/bin/X #precaution.
  440.   fi
  441.  fi
  442. fi
  443. sync
  444.  
  445. #to prevent wizard from running in setup mode at next entry...
  446. echo -n "0" > /root/.fbbootflag
  447.  
  448. #END#
  449.