#!/bin/sh # Copyright 2001 BSDi, Inc, Concord, CA. Written by volkerdi@slackware.com. # Copyright 2004 Slackware Linux, Inc., Concord, CA. # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Modified by rs Lange of Vector Linux. Formally called xorgsetup vdir=`dirname $0` . $vdir/vasm-functions check_root if [ $DISPLAY ]; then DIALOG=Xdialog else DIALOG=dialog fi # If we aren't root, bail: if [ "$UID" = "0" ]; then TMP=/var/log/setup/tmp else clear echo "Only root can configure X......bailing" sleep 8 exit fi # Now, this wouldn't make much sense either: if [ ! -x /usr/X11R6/bin/Xorg ]; then echo "No X found so bailing............" sleep 8 exit fi $DIALOG --title "CONFIGURE X SERVER" --yesno \ " X will attempt to probe for your video hardware and mouse, and \n write an initial configuration file to /etc/X11/xorg.conf.\n Would you like to do this now?" 10 66 if [ ! $? = 0 ]; then exit fi if [ ! -d $TMP ]; then mkdir -p $TMP chmod 700 $TMP fi # OK, we'll warn the user if there's already an existing xorg.conf: CONFIG_EXISTS=false for xf86config in /etc/X11/xorg.conf /etc/xorg.conf /usr/X11R6/lib/X11/xorg.conf $HOME/xorg.conf ; do if [ -r $xf86config ]; then CONFIG_EXISTS=$xf86config fi done if [ ! "$CONFIG_EXISTS" = "false" ]; then $DIALOG --title "FOUND EXISTING xorg.conf in `dirname $CONFIG_EXISTS`" \ --msgbox "A previous X Window System configuration file has been found. \n You can now reconfigure X, replacing the file with a new version (and \n keeping a backup of the old file), or you can abort leaving the existing \n config file in place. Hit ENTER to rename the xorg.conf file to \n xorg.conf.backup and create a new one, or ESC to abort." 10 80 if [ ! $? = 0 ]; then exit fi fi # Have the X server create a default config file: /usr/X11R6/bin/X -configure :2 2> /dev/null if [ ! $? = 0 ]; then # failure, bail. exit fi # Move any existing config file(s) aside: for xf86config in /etc/X11/xorg.conf /etc/xorg.conf /usr/X11R6/lib/X11/xorg.conf $HOME/xorg.conf ; do if [ -r $xf86config ]; then mv $xf86config ${xf86config}.backup fi done ##We may need horiz and vert refresh rates later so lets get them now ddcxinfo -hsync > $TMP/hsync ddcxinfo -vsync > $TMP/vsync vert=`cat $TMP/vsync` horiz=`cat $TMP/hsync` if [ $vert = "0-0" ]; then vert="40-90" fi if [ $horiz = "0-0" ]; then horiz="31.5-64" fi # To force the nvidia module for a desired reolution /bin/grep ^Driver /etc/X11/xorg.conf | grep "nv" if [ $? == 0 ]; then if [ -e /lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ]; then echo module exists if [ -e /lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ]; then NV=`/bin/grep ^Driver /etc/X11/xorg.conf | grep "nv"|cut -d \" -f 2` if [ "$NV" == "nv" ];then sed s'/nv/nvidia/g' /etc/X11/xorg.conf >/etc/X11/xorg.conf.new mv /etc/X11/xorg.conf.new /etc/X11/xorg.conf fi fi # OK, so now that we have a default file in $HOME/xorg.conf.new # we can set up a default color depth: clear $DIALOG --title "SELECT DEFAULT COLOR DEPTH" \ --menu "Now you may select a default color depth for the X server:" 13 70 6 \ "24" "24 bit True Color" \ "16" "16 bit Pseudo Color" \ "8" "8 bit 256 Color" \ "4" "4 bit 16 Color" \ "1" "1 bit Mono B/W" \ "none" "Go with driver default (usually 8-bit)" 2> $TMP/colordepth if [ ! $? = 0 ]; then rm -f $TMP/colordepth exit 1 fi depth=`cat $TMP/colordepth` sleep 2 ############################################################## ##now lets get a default screen resolution clear $DIALOG --title "SELECT DEFAULT MONITOR RESOLUTION" \ --menu "Please select your default screen resolution from the menu below. \n The resolution selected should be the best your monitor will handle. \n For most modern monitors a selection of 1024X768 is a good choice, older monitors \n may only be able to do 800X600. Please select a resolution now." 16 70 6 \ "640x480" "The most basic vga monitor" \ "800x600" "Any SVGA monitor should be able to do this" \ "1024x768" "If you have a recent 15 or 17 inch monitor OK" \ "1280x1024" "Very new monitors or lcd screens" \ "1600x1200" "You know if you have this one...wow!" \ "none" "Choose this if you have no idea X will try to figure it out" 2> $TMP/resolution if [ ! $? = 0 ]; then rm -f $TMP/resolution exit 1 fi res=`cat $TMP/resolution` ##set resolution modes if [ "$res" = "640x480" ]; then finalres="Modes \"640x480\" \"800x600\"" fi if [ "$res" = "800x600" ]; then finalres="Modes \"800x600\" \"640x480\"" fi if [ "$res" = "1024x768" ]; then finalres="Modes \"1024x768\" \"800x600\" \"640x480\"" fi if [ "$res" = "1280x1024" ]; then finalres="Modes \"1280x1024\" \"1024x768\" \"800x600\" \"640x480\"" fi if [ "$res" = "1600x1200" ]; then finalres="Modes \"1600x1024\" \"1280x1024\" \"1024x768\" \"800x600\" \"640x480\"" fi #check the keyboard $DIALOG --title "KEEP DEFAULT KEYBOARD MAP AND LAYOUT" \ --yesno "Would you like to KEEP the default (US) keyboard setup? \n if you choose NO you can change both the keymap and keyboard type\n from the default Setting \ US and pc102" 8 70 2> /dev/null if [ ! $? = 0 ]; then vxkbset fi # I know this completely hoses the indentation of the xorg.conf file, but # really don't know a good way around that. Shoulda used perl. ;) START_LOOKING=false rm -f /etc/X11/xorg.conf . /etc/sysconfig/vector cat $HOME/xorg.conf.new | grep -w " HorizSync" 1> /dev/null if [ $? = 0 ]; then echo "no" > $TMP/fixsync else echo "yes" > $TMP/fixsync fi fixsync=`cat $TMP/fixsync` cat $HOME/xorg.conf.new | while read LINE ; do echo "$LINE" >> /etc/X11/xorg.conf if echo $LINE | grep Section | grep Screen 1> /dev/null ; then START_LOOKING=true fi if [ "$START_LOOKING" = "true" ]; then if echo $LINE | grep Monitor 1> /dev/null ; then if [ ! "$depth" = "none" ]; then echo "DefaultDepth $depth" >> /etc/X11/xorg.conf fi START_LOOKING=false fi fi ## add cyrillic fonts to font path if echo $LINE | grep 100dpi 1> /dev/null ; then echo "FontPath \"/usr/X11R6/lib/X11/fonts/truetype/\" FontPath \"/usr/X11R6/lib/X11/fonts/local/\" FontPath \"/usr/X11R6/lib/X11/fonts/cyrillic/\" " >> /etc/X11/xorg.conf fi ##lets try a default resolution if [ ! "$res" = "none" ]; then if echo $LINE | grep ^Depth 1> /dev/null ; then echo $finalres >> /etc/X11/xorg.conf fi fi ##now the wheel for a mouse #if echo $LINE | grep Device | grep mouse 1> /dev/null ; then # echo "Option \"ZAxisMapping\" \"4 5\"" >> /etc/X11/xorg.conf #fi ##now keyboard setting if none us if [ ! $XKBMAP ]; then XKBMAP=us fi if [ $XKBMAP ]; then if echo $LINE | grep Driver | grep kbd 1> /dev/null ; then echo "Option \"XkbLayout\" \"$XKBMAP\" ## KEYBOARD_MAP!" >> /etc/X11/xorg.conf fi fi if [ $XKBMODEL ]; then if echo $LINE | grep Driver | grep kbd 1> /dev/null ; then echo "Option \"XkbModel\" \"$XKBMODEL\"" >> /etc/X11/xorg.conf fi fi if [ $XKBVAR ]; then if echo $LINE | grep Driver | grep kbd 1> /dev/null ; then echo "Option \"Xkbvariant\" \"$XKBVAR\"" >> /etc/X11/xorg.conf fi fi ##last monitor refresh if not auto detected if [ "$fixsync" = "yes" ]; then if echo $LINE | grep ModelName 1> /dev/null ; then echo "HorizSync $horiz" >> /etc/X11/xorg.conf fi fi if [ "$fixsync" = "yes" ]; then if echo $LINE | grep ModelName 1> /dev/null ; then echo "VertRefresh $vert" >> /etc/X11/xorg.conf fi fi done echo Section \"DRI\" >> /etc/X11/xorg.conf echo Mode 0666 >> /etc/X11/xorg.conf echo EndSection >> /etc/X11/xorg.conf rm -f $TMP/colordepth rm -f $TMP/resolution rm -f $TMP/vsync rm -f $TMP/hsync rm -f $HOME/xorg.conf.new clear ## Test for 2 video cards if [ `grep "^Driver" /etc/X11/xorg.conf | grep -v kbd | grep -v mouse | wc | cut -d " " -f7` -gt 1 ]; then cards=`grep "^Vendor" /etc/X11/xorg.conf | grep -v Mon | cut -d " " -f3 | cut -c 2-` for i in $cards; do echo $i >>/tmp/cards card[$j]="$i" j=`expr $j + 1` done $DCMD --backtitle "$BACKTITLE" --title "Choose Video Card" --menu "\n We have found more than 1 video card, and for X to work \n we need to know which card your monitor is connected to.\n Choose which video card you would like to use" \ 20 74 8 \ ${card[0]} ${card[0]} \ ${card[1]} ${card[1]} \ ${card[2]} ${card[2]} \ 2> $freply cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup card1=`cat $freply` card2=`cat /tmp/cards | grep -v $card1` sed '/Card[0-2]/ d' /etc/X11/xorg.conf > /etc/X11/xorg.conf.1 rm /etc/X11/xorg.conf cat /etc/X11/xorg.conf.1 | while read LINE ; do echo "$LINE" >> /etc/X11/xorg.conf.2 if echo $LINE | grep $card1 1> /dev/null ; then echo Identifier \"Card0\" >> /etc/X11/xorg.conf.2 fi if echo $LINE | grep Section | grep Screen 1> /dev/null ; then echo Device \"Card0\" >> /etc/X11/xorg.conf.2 fi done cat /etc/X11/xorg.conf.2 | while read LINE ; do echo "$LINE" >> /etc/X11/xorg.conf if echo $LINE | grep $card2 1> /dev/null ; then echo Identifier \"Card1\" >> /etc/X11/xorg.conf fi done rm /tmp/cards rm /etc/X11/xorg.conf.1 rm /etc/X11/xorg.conf.2 fi ### intel i810 video has a problem without this hack cat /etc/X11/xorg.conf | grep Driver | grep i810 1> /dev/null if [ $? = 0 ]; then uname -r | cut -f 1,2 -d '.' > $TMP/kernel kernel=`cat $TMP/kernel` rm -f $TMP/kernel if [ $kernel = "2.6" ]; then /sbin/modprobe intel-agp && echo "/sbin/modprobe intel-agp" >> /etc/rc.d/rc.modules fi fi echo "Testing configuration...........hold tight!!!!" sleep 2 Xorg -probeonly :2 2> /dev/null if [ $? = 0 ]; then $DIALOG --title "X WAS CONFIGURED SUCCESSFULLY" \ --msgbox "Your new X configuration file has been saved to /etc/X11/xorg.conf. You may still need to add or adjust some values in the file to achieve the desired screen resolution. For example, some monitors would require \"HorizSync 30-55\" in the \"Monitor\" section of the configuration file. For complete information about making these adjustments, please refer to \"man xorg.conf\"." \ 11 76 else $DIALOG --title "ERROR ERROR" \ --yesno "There was an error in your X configuration. Would you like to edit the \n /etc/X11/xorg.conf file as autoconfig must have stumbled somewhere? \n Choosing yes here will start a text mode configuration utility. \n Choose no if you wish to edit later from the installation." \ 11 66 2> /dev/null if [ $? = 0 ]; then /usr/X11R6/bin/xorgcfg -textmode fi exit 1 fi