#!/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
XORG=`which Xorg`
# Now, this wouldn't make much sense either:
if [ ! -x $XORG ]; then
echo "No X found so bailing............"
sleep 8
exit
fi
if [ ! -d $TMP ]; then
mkdir -p $TMP
chmod 700 $TMP
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
# Have the X server create a default config file:
if ( lspci | grep -i vga | grep -iq " ati " ) then
fixati=1
/sbin/vxconf-ati
else
echo "Detecting Hardware"
$XORG -configure :2 2> /dev/null
if [ ! $? = 0 ]; then
# failure, bail.
exit
fi
fi
##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
# OK, so now that we have a default file in $HOME/xorg.conf.new
# we can set up a default color depth:
depth=24
##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
AutoConfig will get the max for the newest monitors with full DPMS support. \n
For most modern monitors a selection of 1024X768 is a good choice. \n
Oler monitors may only be able to do 800X600. \n
Please select a resolution now." 20 80 8 \
"AutoConfig" "Choose this if you have no idea, X will try to figure it out" \
"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" \
"1280x1024" "Very new monitors or lcd screens" \
"1440x900" "You know if you have this one...wow!" \
"1600x1200" "One word...SuperGamer!" 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" = "1440x900" ]; then
finalres="Modes \"1440x900\" \"1220x700\" \"1024x768\" \"800x600\" \"640x480\""
fi
if [ "$res" = "1600x1200" ]; then
finalres="Modes \"1600x1200\" \"1280x1024\" \"1024x768\" \"800x600\" \"640x480\""
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 "^HorizSync" 1> /dev/null
if [ $? = 0 ]; then
fixsync="no"
else
fixsync="yes"
fi
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
if [ "$nvidia" = 1 ];then
if echo $LINE | grep Section | grep Module\" 1> /dev/null ; then
if ! cat $HOME/xorg.conf.new | grep Load | grep glx\" 1> /dev/null ; then
echo Load \"glx\" >>/etc/X11/xorg.conf
fi
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
#echo $fixsync
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
cat /etc/X11/xorg.conf | grep Driver | grep "\"nv\"" 1> /dev/null
if [ $? = 0 ]; then
sed s'/nv/nv/'g /etc/X11/xorg.conf > /etc/X11/xorg.conf.new
mv /etc/X11/xorg.conf.new /etc/X11/xorg.conf
fixnv=1
fi
cat /etc/X11/xorg.conf | grep Driver | grep "\"nvidia\"" 1> /dev/null
if [ $? = 0 ]; then
sed s'/nvidia/nv/'g /etc/X11/xorg.conf > /etc/X11/xorg.conf.new
mv /etc/X11/xorg.conf.new /etc/X11/xorg.conf
fixnvidia=1
fi
cat /etc/X11/xorg.conf | grep Driver | grep "\"vesa\"" 1> /dev/null
if [ $? = 0 ]; then
sed s'/vesa/vesa/'g /etc/X11/xorg.conf > /etc/X11/xorg.conf.new
mv /etc/X11/xorg.conf.new /etc/X11/xorg.conf
fixonboard=1
fi
# echo "Installing Graphics Driver...........hold tight!!!!"
sleep 2
Xorg -probeonly :2 2> /dev/null
if [ $? = 0 ]; then
if [ "$fixnv" = 1 ];then
/sbin/vlnvidia-live
fi
if [ "$fixnvidia" = 1 ];then
/sbin/vlnvidia-live
fi
if [ "$fixonboard" = 1 ];then
/sbin/vlnvidia-live
fi
else
if [ "$fixati" = 1 ];then
if ( ls /var/log/packages | grep -iq fglrx ) then
/usr/share/ati/fglrx-uninstall.sh >/dev/null && removepkg fglrx >/dev/null
fi
/sbin/vxconf-ati
fi
yesnobox "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."
if [ $? = 0 ]; then
/usr/bin/mcedit /etc/X11/xorg.conf
fi
exit 1
fi