xwin 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2003,2004,2005,2006,2007 www.puppylinux.com
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #v3.90 rawpup, update for Xvesa.
  5. #v3.94, v3.95, recognise Classmate, EeePC laptops.
  6. #v3.98 change to home directory.
  7. #v3.98 forced reboot handling improved by pizzasgood.
  8. #v3.99 automatically handle problematic video adapters that hang Xvesa.
  9. #v405 added support for xvesa 1024x600.
  10. #v408 BK k2.6.25.16 serial mouse driver now a module 'sermouse'.
  11. #v411 rerwin: mouse improvements.
  12. #w001 fixes for woof, /usr/X11R7 not used.
  13. #w460 fixes to get Xvesa running with woof build. fix for X restart after exit.
  14. #w477, w478 more fixes Xvesa restart after first 'Exit to prompt'.
  15. #w479 older Xvesa server may not recognise '-sp' option.
  16. #w479 k2.6.18.8 need awful hack, Xorg, '-nolisten tcp' causes hang!
  17. #v424 bad hack to fix serial mouse.
  18. #100127 make sure xorg keyboard layout matches console setting (same code in xorgwizard).
  19. #100130 typo fix.
  20. #100215 moved sync code for console/xorg kbd layout from xwin to /usr/sbin/input-wizard.
  21. #100501 monitor probe returns random 'manufacture' data from one of my monitors.
  22. #100520 attempt fix keyboard layout not getting updated.
  23. #100608 jemimah: added 1366x768.
  24. #20110328 for xorg, run xorgwizard-automatic instead of xorgwizard, for xorg 7.5.
  25. #110413 variable DISTRO_XORG_AUTO in /etc/DISTRO_SPECS, set in Woof '3builddistro'.
  26. #110622 fix handling of DISTRO_XORG_AUTO.
  27. #110721 o/p to /dev/null when modprobe modules that are builtin to kernel.
  28. #110804 /etc/profile has fix for double-login. need to output '# ' when exit xwin.
  29. #110807 revert 110804
  30. #120131 rodin.s: internationalized.
  31. #120301 load console font on exit from X.
  32. #120505 automatic network reconnect. refer /usr/sbin/hostname-set
  33. #120511 hostname-set changed HOSTNAME, via quicksetup, X is restarted, update $HOSTNAME (was exported at bootup in /etc/profile)...
  34. #120517 arm hardware does not support ddcprobe.
  35. #120723 simplify xorg auto logic (refer 3builddistro).
  36. #130609 L18L testing 'fido', reported /etc/.XLOADED could not be deleted.
  37. #130527 /etc/.XLOADED has been moved to /root, refer also remasterpup2.
  38. #130725 quiet if no /etc/oldmousedevice file.
  39. export TEXTDOMAIN=xwin
  40. export OUTPUT_CHARSET=UTF-8
  41. eval_gettext () {
  42. local myMESSAGE=$(gettext "$1")
  43. eval echo \"$myMESSAGE\"
  44. }
  45. export LANGORG=$LANG
  46. HOSTNAMEORIG=$HOSTNAME #120511
  47. #NUMXWINS=`pidof xwin | wc -w` #w478
  48. #[ $NUMXWINS -gt 1 ] && exit #w478
  49. [ -z $DISPLAY ] || exit #v2.11 from GuestToo.
  50. #echo "This script will run X windows for you..."
  51. cd ~/ #v3.98 Ensure current directory is root, in case changed at command prompt, so rox icon and menu item open only at home directory. rerwin
  52. #variables created at bootup by init script in initrd...
  53. . /etc/rc.d/PUPSTATE #v2.02
  54. #PUPMODE=current operating configuration,
  55. #PDEV1=the partition have booted off, DEV1FS=f.s. of PDEV1,
  56. #PUPSFS=puppy.sfs main part of puppy, stored on PDEV1, PUPSAVE=vfat,sda1,/pup_save.3fs
  57. #PMEDIA is a broad description of the boot media, ex "usbflash" or "idehd".
  58. . /etc/DISTRO_SPECS #110413
  59. . /etc/rc.d/BOOTCONSTRAINED #120723
  60. KERNELVER="`uname -r`" #w479
  61. #120505 automatic network reconnect. refer /usr/sbin/hostname-set
  62. if [ -f /tmp/simple_network_setup/network_default_reconnect_required_flag ];then
  63. rm -f /tmp/simple_network_setup/network_default_reconnect_required_flag
  64. IFCONFIG="`ifconfig | grep '^[pwe]' | grep -v 'wmaster'`" #precaution.
  65. if [ "$IFCONFIG" = "" ];then
  66. network_default_connect #/usr/sbin
  67. fi
  68. fi
  69. #0.9.9 enables to start a specific w.m. from commandline...
  70. if [ $1 ];then
  71. echo -n "$1" > /etc/windowmanager
  72. #note, /root/.xinitrc uses this file.
  73. fi
  74. #v1.0.7
  75. HAVEX="`readlink /usr/bin/X`"
  76. if [ "$HAVEX" = "XF86_SVGA" ];then
  77. #xf86config v3.3.6 creates config file at /etc, wrong place...
  78. [ -f /etc/XF86Config ] && mv -f /etc/XF86Config /etc/X11/XF86Config
  79. fi
  80. #v3.90 expanded to auto run best video mode...
  81. if [ "$HAVEX" = "Xvesa" ];then #0.9.9
  82. if [ ! -f /tmp/videomode -a ! -f /etc/videomode ];then #v2.21
  83. ddcprobe >/tmp/ddcprobe.txt
  84. #weird (ddcprobe is very weird), on some hardware, edid monitor probe fails
  85. #every alternate run of ddcprobe...
  86. case "`cat /tmp/ddcprobe.txt`" in *edidfail*)
  87. sleep 1
  88. ddcprobe >/tmp/ddcprobe.txt
  89. ;;
  90. esac
  91. #v3.99 begin
  92. if [ -f /etc/xorgoverrides ] && grep -q -f /etc/xorgoverrides /tmp/ddcprobe.txt;then
  93. rm -f /root/.XLOADED 2> /dev/null #not necessary, precaution.
  94. #1st dialog offers to use Xvesa...
  95. /usr/sbin/xorgwizard
  96. HAVEX="`readlink /usr/bin/X`"
  97. [ "$HAVEX" != "Xorg" ] && exit #go to command line if not Xorg
  98. fi
  99. fi
  100. fi
  101. #Repeat earlier tests in case Xserver now Xorg and to retain indentation levels.
  102. if [ "$HAVEX" = "Xvesa" ];then #0.9.9
  103. BASEMODE=""
  104. if [ ! -f /tmp/videomode -a ! -f /etc/videomode ];then #v2.21
  105. #v3.99 end
  106. #v3.97 improved method: CM=Classmate, 915=chip 10=generation#...
  107. [ "`dmidecode -s bios-version | grep '^CM91510'`" != "" ] && echo 'timing: 800x480@60' >> /tmp/ddcprobe.txt
  108. #v3.95 recognise more special screens...
  109. DMIDECODE="`dmidecode`"
  110. #recognise EeePC Asus laptop...
  111. [ "`echo "$DMIDECODE" | grep 'Product Name: 701'`" != "" ] && [ "`echo "$DMIDECODE" | grep 'Serial Number: EeePC'`" != "" ] && echo 'timing: 800x480@60' >> /tmp/ddcprobe.txt
  112. echo -e '\n'$(gettext 'If initialization freezes here, press ctrl-c and type "xorgwizard",\nselect "Xorg", choose monitor type and choose video mode.')'' #v3.99
  113. grep '^oem:' /tmp/ddcprobe.txt > /tmp/ddcprobeoem.txt #v3.99 current adapter signature
  114. #get too many weird resolutions, maybe better just only allow these...
  115. #want widescreen/non-vesa resolutions only...
  116. VESAMODES="`Xvesa -listmodes 2>&1 | grep '^0x' | tr ':' ' ' | tr -s ' ' | cut -f 1,2 -d ' '`"
  117. rm /tmp/ddcprobeoem.txt #v3.99 didn't hang in Xvesa, so delete signature
  118. #100608 jemimah: added 1366x768...
  119. MONCHOICES="`grep -F 'timing:' /tmp/ddcprobe.txt | grep -E -v 'Apple|8514A|Mac II|\(XGA2\)' | grep -E ' 800x480@| 1024x600@| 1280x768@| 1280x800@| 1280x1024@| 1360x768@| 1366x768@| 1400x1050@| 1440x900@| 1600x1200@| 1680x1050@| 1920x1080@| 1920x1200@' | cut -f 2 -d ' ' | sort -u`"
  120. if [ "$MONCHOICES" != "" ];then
  121. MONCUTXY="`echo "$MONCHOICES" | cut -f 1 -d '@' | tr '\n' ' '`"
  122. #v2.21 code to handle widescreen with intel video chips...
  123. if [ ! -f /etc/resolutionfix ];then
  124. if grep -F 'oem:' /tmp/ddcprobe.txt | grep -F -q 'Intel' ;then
  125. MISSINGXY=""
  126. for ONECUTXY in $MONCUTXY #ex: each field 1024x768
  127. do
  128. OPATTERN=" ${ONECUTXY}x"
  129. [ "`echo "$VESAMODES" | grep "$ONECUTXY"`" = "" ] && MISSINGXY="$ONECUTXY"
  130. done
  131. if [ "$MISSINGXY" != "" ];then
  132. MYXRES="`echo -n "$MISSINGXY" | cut -f 1 -d 'x'`"
  133. MYYRES="`echo -n "$MISSINGXY" | cut -f 2 -d 'x'`"
  134. 915resolution 38 $MYXRES $MYYRES
  135. #...replaces mode 38 (1024x768).
  136. #create something for /etc/profile to execute at bootup...
  137. echo "915resolution 38 $MYXRES $MYYRES" > /etc/resolutionfix
  138. VESAMODES="`Xvesa -listmodes 2>&1 | grep '^0x' | tr ':' ' ' | tr -s ' ' | cut -f 1,2 -d ' '`"
  139. PPATTERN=" ${MYXRES}x${MYYRES}x"
  140. #BASEMOD is res that we are going to start X with...
  141. BASEMODE="`echo "$VESAMODES" | grep "$PPATTERN" | grep -E 'x16$|x24$|x32$' | head -n 1`"
  142. fi
  143. fi
  144. fi
  145. #find out if there is just one native mode...
  146. if [ "$BASEMODE" = "" ];then
  147. if [ "`echo "$MONCUTXY" | wc -l`" = "1" ];then
  148. QPATTERN=" ${MONCUTXY}x"
  149. BASEMODE="`echo "$VESAMODES" | grep "$QPATTERN" | grep -E 'x16$|x24$|x32$' | head -n 1`"
  150. fi
  151. fi
  152. if [ "$BASEMODE" != "" ];then
  153. echo "$BASEMODE" > /etc/videomode #no need for wizard after startup!
  154. rm -f /tmp/videomode 2>/dev/null #w460 make sure can exit from X.
  155. fi
  156. fi
  157. if [ "$BASEMODE" = "" ];then
  158. BASEMODE="`echo "$VESAMODES" | grep ' 800x600x16' | head -n 1`"
  159. if [ "$BASEMODE" != "" ];then
  160. echo "$BASEMODE" > /tmp/videomode
  161. else
  162. echo -n "0x0111 640x480x16" > /tmp/videomode
  163. #...desparate, not a practical mode.
  164. fi
  165. fi
  166. rm -f /tmp/Xflag #precaution.
  167. #...if /tmp/videomode exists, video-wizard is started in ~/.xinitrc
  168. #...note, if /etc/videomode exists instead, normal X startup.
  169. fi
  170. fi
  171. #v411 restored after removal in v407...
  172. #update xorg.conf if mouse has changed...
  173. MOUSEDEV="`cat /etc/mousedevice`" #autodetected in rc.sysinit
  174. OLDMOUSEDEV="`cat /etc/oldmousedevice 2>/dev/null`" #set in rc.sysinit. 130725
  175. if [ ! "$OLDMOUSEDEV" = "$MOUSEDEV" ];then
  176. if [ ! "$OLDMOUSEDEV" = "nothing" ];then #"nothing" on first boot.
  177. if [ -f /etc/X11/xorg.conf ];then
  178. case `cat /etc/mousedevice | cut -c 1-4` in
  179. "inpu") #"input/mice", usb
  180. cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\(\(\w\+\/\w\+\)\|\(\w\+\)\)\W\+#mouse0protocol/ Option "Protocol" "IMPS\/2" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  181. ;;
  182. "ttyS") #ttyS0,1,2,3, serial
  183. cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\(\(\w\+\/\w\+\)\|\(\w\+\)\)\W\+#mouse0protocol/ Option "Protocol" "Microsoft" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  184. ;;
  185. *)
  186. cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\(\(\w\+\/\w\+\)\|\(\w\+\)\)\W\+#mouse0protocol/ Option "Protocol" "auto" #mouse0protocol/g' > /tmp/xorg.conf.tmp2
  187. ;;
  188. esac
  189. sync
  190. cp -f /tmp/xorg.conf.tmp2 /etc/X11/xorg.conf
  191. sync
  192. rm -f /tmp/xorg.conf.tmp2
  193. fi
  194. fi
  195. OLDMOUSEDEV="$MOUSEDEV" #v411 old is now current mouse
  196. echo -n "$OLDMOUSEDEV" > /etc/oldmousedevice #v411
  197. fi
  198. #v408 k2.6.25.16 has serial driver as a module... 110721 o/p to null...
  199. [ "`grep 'ttyS' /etc/mousedevice`" != "" ] && modprobe sermouse > /dev/null 2>&1
  200. #v411 precaution... 110721 o/p to null...
  201. [ "`grep 'input/mice' /etc/mousedevice`" != "" ] && modprobe usbhid > /dev/null 2>&1
  202. #ask about scrollwheel... DO NOT ASK, ASSUME YES...
  203. if [ ! -f /etc/mousebuttons ];then
  204. #dialog --yesno "Do you have a wheel/scroll type of mouse?" 0 0
  205. #if [ $? -eq 0 ];then
  206. echo -n "5" > /etc/mousebuttons
  207. echo -e "The file /etc/mousebuttons has been created, with content \"5\"."
  208. if [ -f /etc/X11/xorg.conf ];then
  209. 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
  210. sync
  211. cp -f /tmp/xorg.conf.tmp /etc/X11/xorg.conf
  212. fi
  213. fi
  214. #v2.11 find out if xorg video drvr exists, else use xorg vesa...
  215. if [ -f /usr/bin/Xorg ];then
  216. if [ -f /etc/X11/xorg.conf ];then
  217. #find location of video chip drivers...
  218. SPECVESA="`find /usr/lib /usr/X11R7/lib -noleaf -mount -type f -name vesa_drv.so 2>/dev/null | grep -v 'backup' | grep -m1 'vesa_drv.so'`" #1201031 bug fix.
  219. if [ "$SPECVESA" ];then
  220. DRVRSPATH="`dirname $SPECVESA`"
  221. #get current driver...
  222. DRVRCURR="`cat /etc/X11/xorg.conf | grep '#card0driver' | cut -f 2 -d '"'`" #'
  223. if [ "$DRVRCURR" ];then
  224. #if [ ! -f $DRVRSPATH/${DRVRCURR}_drv.so ];then
  225. #one driver is mtx_drv.o hmmm, okay do it this way (pakt)...
  226. ls -1 $DRVRSPATH/* | grep $DRVRCURR >/dev/null
  227. if [ $? -ne 0 ];then
  228. APATTERN="s/.*#card0driver/ Driver \"vesa\" #card0driver/g"
  229. sed -i -e "$APATTERN" /etc/X11/xorg.conf
  230. fi
  231. fi
  232. fi
  233. fi
  234. fi
  235. #Puppy Xorg Video Wizard...
  236. if [ -f /usr/bin/Xorg ];then
  237. if [ -f /etc/X11/xorg.conf ];then
  238. if [ "`readlink /usr/bin/X`" = "Xorg" ];then
  239. if [ "`which ddcprobe`" = "" ];then #120517
  240. #arm board, does not support ddcprobe (refer also /usr/sbin/xorgwizard-automatic)...
  241. HARDWAREPROFILE='armsystem'
  242. else
  243. #v2.13 video hardware profile (must be same as in xorgwizard)...
  244. DDCPROBE="`ddcprobe`"
  245. #v2.17 patch from Nightflyer... as in xwin, may have to run ddcprobe twice...
  246. case "`echo "$DDCPROBE"`" in
  247. *edidfail*)
  248. sleep 1
  249. DDCPROBE="`ddcprobe`"
  250. ;;
  251. esac
  252. PROFILECHIP="`echo "$DDCPROBE" | grep '^oem: ' | head -n 1 | cut -f 2-4 -d ' ' | tr ' ' '_' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
  253. #v3.95 'eisa:' and 'id:' return fluctuating values on some PCs, so search in this order...
  254. PROFILEMONITOR="`echo "$DDCPROBE" | grep '^monitorid: ' | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
  255. [ "$PROFILEMONITOR" = "" ] && PROFILEMONITOR="`echo "$DDCPROBE" | grep '^monitorname: ' | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
  256. [ "$PROFILEMONITOR" = "" ] && PROFILEMONITOR="`echo "$DDCPROBE" | grep '^monitorrange: ' | head -n 1 | cut -f 2 -d ':' | tr -d ' ' | sed -e 's/[^0-9a-zA-Z]/_/g'`"
  257. HARDWAREPROFILE="${PROFILECHIP}${PROFILEMONITOR}"
  258. fi
  259. #find out if current xorg.conf matches this profile...
  260. CURRENTPROFILE="`cat /etc/X11/xorg.conf | grep '^#PuppyHardwareProfile' | cut -f 2 -d '=' | cut -f 1 -d ' '`"
  261. if [ ! "$CURRENTPROFILE" = "$HARDWAREPROFILE" ];then
  262. #video hardware has changed. either changed monitor or booting different PC.
  263. #same current xorg.conf as a profiled filename...
  264. mv -f /etc/X11/xorg.conf /etc/X11/xorg.conf.${CURRENTPROFILE}
  265. #if a previous profiled filename for new hardware, use that...
  266. [ -f /etc/X11/xorg.conf.${HARDWAREPROFILE} ] && cp -af /etc/X11/xorg.conf.${HARDWAREPROFILE} /etc/X11/xorg.conf
  267. fi
  268. fi
  269. fi
  270. if [ ! -f /etc/X11/xorg.conf ];then
  271. rm -f /root/.XLOADED 2> /dev/null #not necessary, precaution.
  272. if [ "$DISTRO_XORG_AUTO" = "yes" ];then #see /etc/DISTRO_SPECS.
  273. /usr/sbin/xorgwizard-automatic
  274. else
  275. #1st dialog offers to use Xvesa...
  276. /usr/sbin/xorgwizard
  277. HAVEX="`readlink /usr/bin/X`"
  278. [ "$HAVEX" = "Xvesa" ] && exec xwin #w482 need to restart xwin.
  279. fi
  280. fi
  281. fi
  282. #v1.0.7 J_Reys idea (see note further down)...
  283. if [ -f /root/.XLOADED ];then
  284. if [ "`cat /root/.XLOADED`" = "true" ];then
  285. #last time X ran, PC hung and had to be rebooted...
  286. dialog --timeout 30 --title "$(gettext 'Warning')" --yes-label "$(gettext 'Ignore')" --no-label "$(gettext 'Commandline')" --yesno "$(gettext 'X seems to have exited uncleanly the last time you ran Puppy. This is usually because of an improper shutdown (such as a power failure), but may be because something is broken.')
  287. $(gettext 'If it was just something like a power failure, wait for 30 seconds or choose <Ignore> for normal startup of X...')
  288. $(gettext 'If there is a problem, such as X not working, choose <Commandline> to drop out to a commandline. There will then be further advice how to fix X...')
  289. $(gettext 'If undecided, wait 30 seconds for normal startup of X...')" 0 0
  290. if [ ! $? = 1 ]; then
  291. rm /root/.XLOADED
  292. else
  293. echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  294. echo '
  295. '$(gettext 'It seems that last time X ran, the computer hung and you had to reboot.')'
  296. '$(gettext 'Have now dropped down to the commandline. If you want to run the Xorg')'
  297. '$(gettext 'Video Wizard, type "xorgwizard", and after configuring /etc/X11/xorg.conf')'
  298. '$(gettext '(hopefully correctly this time!) type "xwin" to start X.')''
  299. echo -e "\\033[0;39m"
  300. rm -f /root/.XLOADED #otherwise cannot start X.
  301. exit
  302. fi
  303. fi
  304. fi
  305. if [ "$HAVEX" = "Xvesa" ];then #0.9.9
  306. #/tmp/videomode exists if starting X with new video test mode...
  307. if [ -e /tmp/videomode ];then
  308. cat /tmp/videomode | grep " 800x600"
  309. if [ $? -eq 0 ];then #=0 if found.
  310. if [ -e /tmp/Xflag ];then
  311. #we have just attempted 800x600x16 and aborted with ctrl-alt-backspace
  312. #so have failed.
  313. echo "$(gettext 'An attempt has just been made to run X at 800x600x16 but it has')"
  314. echo "$(gettext 'not worked (or it did but you did not press the OK button in the')"
  315. echo "$(gettext 'Video-wizard). It is not feasible to run Puppy at any lower resolution')"
  316. echo -e "$(gettext 'or color. If you want to try again, type "xwin" at the prompt.')"
  317. echo "$(gettext 'It may be helpful to look in /tmp/xerrs.txt for error messages')"
  318. rm -f /tmp/videomode
  319. rm -f /tmp/Xflag
  320. echo -n "0x0111 640x480x16" > /etc/videomode #desparate.
  321. exit 0
  322. else
  323. #flag to prevent endless loop X restarting...
  324. touch /tmp/Xflag
  325. #...pressing a button in video-wizard removes this file.
  326. #...however, aborting X will leave it in existence.
  327. fi
  328. fi
  329. fi
  330. #/tmp/videomode exists if starting X with new video test mode...
  331. if [ -e /tmp/videomode ];then
  332. #stored in format "0x0111 640x480x16"
  333. VIDMODE="`cat /tmp/videomode | cut -f 1 -d ' '`"
  334. VIDSCRN="`cat /tmp/videomode | tr -s ' ' | cut -f 2 -d ' '`"
  335. else
  336. #stored in format "0x0111 640x480x16"
  337. VIDMODE="`cat /etc/videomode | cut -f 1 -d ' '`"
  338. VIDSCRN="`cat /etc/videomode | tr -s ' ' | cut -f 2 -d ' '`"
  339. fi
  340. fi
  341. MOUSEBUTTONS=3
  342. if [ -e /etc/mousebuttons ];then
  343. MOUSEBUTTONS=`cat /etc/mousebuttons`
  344. fi
  345. #v2.02 fix bug discovered by Dougal...
  346. if [ $MOUSEBUTTONS -eq 2 ];then
  347. #the problem is, if /etc/xextraoptions has '-2button' which turns on middle-button
  348. #emulation, if leave MOUSEBUTTONS=2 then the right button does not work.
  349. #have to pass '3' to Xvesa, meaning effectively 3 buttons available...
  350. [ ! "`cat /etc/xextraoptions | grep ' \-2button'`" = "" ] && MOUSEBUTTONS=3
  351. fi
  352. #0.9.8
  353. XEXTRAOPTIONS=""
  354. if [ -e /etc/xextraoptions ];then
  355. XEXTRAOPTIONS="`cat /etc/xextraoptions`"
  356. fi
  357. #v424 bad hack, i somehow get /dev/mouse pointing to psaux when chose a serial mouse, don't know why...
  358. [ "`grep 'ttyS' /etc/mousedevice`" != "" ] && ln -snf $MOUSEDEV /dev/mouse
  359. #100520 attempt fix keyboard layout not getting updated...
  360. [ ! -f /etc/keymap ] && echo -n "us" > /etc/keymap #maybe lupu needs this.
  361. [ ! -f /etc/keymap_previous ] && echo -n "us" > /etc/keymap_previous
  362. KEYMAPNOW="`cat /etc/keymap`"
  363. KEYMAPPREV="`cat /etc/keymap_previous`"
  364. if [ "$KEYMAPNOW" != "$KEYMAPPREV" ];then
  365. cp -f /etc/keymap /etc/keymap_previous
  366. #100520 bring this code back again...
  367. #100215 moved this code to /usr/sbin/input-wizard, avoid automatic overwriting of any user edit of xorg.conf...
  368. #100127 make sure xorg keyboard layout matches console setting (same code in xorgwizard)...
  369. if [ "$HAVEX" = "Xorg" ];then
  370. xCONSKEYMAP="`cat /etc/keymap | cut -c 1-2`"
  371. [ "$xCONSKEYMAP" = "" ] && xCONSKEYMAP="us"
  372. case $xCONSKEYMAP in
  373. az) XKEYMAP="fr" ;; #azerty
  374. wa) XKEYMAP="fr" ;; #wangbe
  375. dv) XKEYMAP="dvorak" ;; #dvorak
  376. cr) XKEYMAP="cz" ;; #croat
  377. sl) XKEYMAP="si" ;; #slovene v2.12 bugfix, changed from 'sk' to 'si' (sk is slovakia)
  378. sv) XKEYMAP="se" ;; #sweden
  379. uk) XKEYMAP="gb" ;; #united kingdom
  380. *) XKEYMAP="$xCONSKEYMAP" ;;
  381. esac
  382. if [ -d /etc/X11/xkb/symbols/pc ];then #100127 fallback...
  383. if [ ! -f /etc/X11/xkb/symbols/pc/${XKEYMAP} ];then
  384. if [ ! -f /etc/X11/xkb/symbols/${XKEYMAP} ];then
  385. echo "$(gettext 'ERROR: Console keyboard') `cat /etc/keymap` $(gettext 'no matching Xorg layout. PLEASE REPORT TO BK')"
  386. XKEYMAP='us'
  387. fi
  388. fi
  389. fi
  390. currXKEYMAP="`grep '#xkeymap0' /etc/X11/xorg.conf | tr '\t' ' ' | tr -s ' ' | cut -f 4 -d '"'`" #'geany fix
  391. if [ "$currXKEYMAP" != "$XKEYMAP" ];then
  392. skPATTERN="s%.*#xkeymap0% Option \"XkbLayout\" \"${XKEYMAP}\" #xkeymap0%"
  393. sed -i -e "${skPATTERN}" /etc/X11/xorg.conf #100130
  394. fi
  395. fi
  396. fi
  397. #finally, start X...
  398. #J_Rey had a good idea, flag XLOADED... and set to false on exit.
  399. #but if PC hangs, XLOADED will still be true, so will know it is broken.
  400. echo -n "true" > /root/.XLOADED
  401. #chmod 666 /root/.XLOADED #130609 precaution, if change to user 'fido' at X shutdown, need to be able to delete this at next boot.
  402. case $HAVEX in
  403. Xvesa)
  404. echo "`eval_gettext \"Starting X with video mode \\\$VIDMODE and mouse \\\$MOUSEDEV...\"`"
  405. #w479 older Xvesa server may not recognise the '-sp' option...
  406. if [ "`Xvesa -help 2>&1 | grep '^\-sp '`" = "" ];then
  407. SPOPTION=''
  408. else
  409. SPOPTION='-sp /usr/lib/xserver/SecurityPolicy'
  410. fi
  411. #startx $VIDMODE $MOUSEDEV > /tmp/xerrs.txt 2>&1
  412. #Puppy 0.8.4 no need for startx script...
  413. VIDFREQ="`echo -n "$VIDSCRN" | cut -f 4 -d "x"`"
  414. if [ ! "$VIDFREQ" ];then
  415. echo "$VIDMODE" > /tmp/currentvideomode
  416. #w460 added -fp and -sp options...
  417. /usr/bin/xinit /root/.xinitrc -- -mode $VIDMODE $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS -fp /usr/share/X11/fonts/misc/,/usr/share/X11/fonts/TTF/,/usr/share/X11/fonts/Type1/ $SPOPTION > /tmp/xerrs.log 2>&1
  418. else
  419. #also, want to have adjustable frequency, VIDSCRN=widthxheightxdepthxfreq...
  420. echo "$VIDSCRN" > /tmp/currentvideomode
  421. /usr/bin/xinit /root/.xinitrc -- -screen $VIDSCRN $XEXTRAOPTIONS -mouse /dev/mouse,$MOUSEBUTTONS -fp /usr/share/X11/fonts/misc/,/usr/share/X11/fonts/TTF/,/usr/share/X11/fonts/Type1/ $SPOPTION > /tmp/xerrs.log 2>&1
  422. fi
  423. ;;
  424. Xfbdev)
  425. echo "$(gettext 'Starting X with Xfbdev Kdrive X server, mouse') $MOUSEDEV..."
  426. /usr/bin/xinit /root/.xinitrc -- -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.log 2>&1
  427. ;;
  428. Xi810) #v1.0.7
  429. echo "$(gettext 'Starting X with Xi810 Kdrive X server, mouse') $MOUSEDEV..."
  430. #echo "(experimental, currently fixed to 1024x768x16x72 in /usr/bin/xwin)"
  431. /usr/bin/xinit /root/.xinitrc -- -screen $VIDSCRN -mouse /dev/mouse,$MOUSEBUTTONS > /tmp/xerrs.log 2>&1
  432. ;;
  433. XF86_SVGA)
  434. echo "$(gettext 'Starting X, specs in /etc/X11/XF86Config, startup apps /root/.xinitrc...')"
  435. /usr/bin/xinit /root/.xinitrc -- -bpp 16 > /tmp/xerrs.log 2>&1
  436. ;;
  437. Xorg)
  438. echo "$(gettext 'Starting X, specs in /etc/X11/xorg.conf, startup apps /root/.xinitrc...')"
  439. #v2.11 G2 suggested -br for black background instead of checked...
  440. #w479 ***AWFUL HACK*** running pup 218, retro k2.6.18.8, my laptop, Xorg hangs
  441. # if have '-nolisten tcp'. until find out why, this workaround...
  442. if [ "$KERNELVER" = "2.6.18.8" ];then
  443. /usr/bin/xinit /root/.xinitrc -- -br > /tmp/xerrs.log 2>&1
  444. else
  445. /usr/bin/xinit /root/.xinitrc -- -br -nolisten tcp > /tmp/xerrs.log 2>&1
  446. fi
  447. ;;
  448. *)
  449. /usr/bin/xinit /root/.xinitrc -- > /tmp/xerrs.log 2>&1
  450. ;;
  451. esac
  452. echo -n "false" > /root/.XLOADED #see note above.
  453. #...if PC hung, run xorgwizard at next bootup (see further up).
  454. load_consolefont #120301 seems have to do this on exit from X. (new script)
  455. #unicode_start #i18n rodin.s for unicode start after exit from X. ??????what is this??????
  456. #120224 ...console font is loaded in quicksetup if locale changed.
  457. echo ''$(gettext 'Exited from X. Type "xwin [fvwm95|jwm]" to restart X ([ ] mean optional).')''
  458. echo ''$(gettext '(To shutdown PC type "poweroff", to reboot PC type "reboot")')''
  459. if [ -f /usr/X11R7/bin/Xfbdev ];then
  460. echo ''$(gettext '(To run the Xfbdev Framebuffer Wizard, type "framebufferwizard")')''
  461. fi
  462. if [ "$HAVEX" = "XF86_SVGA" ];then #v1.0.7
  463. echo -en "\\033[1;31m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  464. echo ''$(gettext 'If X failed to start, type "xf86config" to setup X')''
  465. echo ' -- '$(gettext 'you will need to know type of mouse, keyboard and video chip')''
  466. echo ' -- '$(gettext 'thix X is for pre-2000 video chips, but many recent chips backwards-compat.')''
  467. echo ' -- '$(gettext 'accept default save /etc/XF86Config, Puppy will move this to /etc/X11')''
  468. echo ' -- '$(gettext '(XF86Config is the configuration file for X and can be edited manually)')''
  469. echo -n ' -- '$(gettext 'LAST RESORT, drop back to Xvesa by typing "ln -sf Xvesa /usr/bin/X"')''
  470. echo -e "\\033[0;39m"
  471. fi
  472. if [ "$HAVEX" = "Xorg" ];then #v1.0.7
  473. echo -en "\\033[1;35m" #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  474. echo -n ''$(gettext 'If X failed to start, type "xorgwizard" to setup X')''
  475. echo -e "\\033[0;39m"
  476. fi
  477. ##w477 weird situation. first boot, xvesa, 'Exit to prompt', X restarts.
  478. ##because there are two instances of xwin running, but I don't see how.
  479. ##not the best, but here is a workaround...
  480. #NUMXWINS=`pidof xwin | wc -w` #see above and below...
  481. if [ "$HAVEX" = "Xvesa" ];then
  482. if [ -e /tmp/videomode ];then
  483. exec xwin #restart X.
  484. fi
  485. fi
  486. #Shutdown menu calls wmreboot, wmpoweroff, wmexit or restartwm, which create this file...
  487. if [ -f /tmp/wmexitmode.txt ];then
  488. WMEXITMODE="`cat /tmp/wmexitmode.txt`"
  489. if [ "$WMEXITMODE" = "exit" ];then #see /usr/bin/wmexit.
  490. #[ $NUMXWINS -eq 1 ] && rm -f /tmp/wmexitmode.txt #w477 hack, see above.
  491. rm -f /tmp/wmexitmode.txt #w478
  492. #[ ! -f /tmp/xwin-firstexit ] && echo -n '# ' #110804 pretend prompt. 110807
  493. #touch /tmp/xwin-firstexit #110804 110807
  494. exit
  495. fi
  496. #rm -f /tmp/wmexitmode.txt ...no, removed in rc.shutdown.
  497. [ "$WMEXITMODE" = "poweroff" ] && exec /sbin/poweroff #see /usr/bin/wmpoweroff
  498. [ "$WMEXITMODE" = "reboot" ] && exec /sbin/reboot #see /usr/bin/wmreboot
  499. #restart window manager...
  500. #make a gross assumption, if wmexitmode.txt exists, haven't already exited this script, then want
  501. #to restart maybe with different window manager. /etc/windowmanager already has desired w.m.
  502. rm -f /tmp/wmexitmode.txt #definitely delete it now.
  503. #v1.0.5 thanks GuestToo for advice on this, works with chooselocale script...
  504. NEWLANG="`cat /etc/profile | grep '^LANG=' | cut -f 2 -d '='`"
  505. if [ "$NEWLANG" ];then #precaution
  506. if [ "$NEWLANG" != "$LANG" ];then
  507. export LANG=$NEWLANG
  508. fi
  509. fi
  510. #120511 hostname-set changed HOSTNAME, via quicksetup, X is restarted, update $HOSTNAME (was exported at bootup in /etc/profile)...
  511. NEWHOSTNAME="`cat /etc/hostname | tr -d '\n'`"
  512. if [ "$NEWHOSTNAME" ];then #over-the-top paranoid precaution.
  513. if [ "$NEWHOSTNAME" != "$HOSTNAME" ];then
  514. export HOSTNAME=$NEWHOSTNAME
  515. fi
  516. fi
  517. exec xwin
  518. fi
  519. #the end#