All pastes #811822 Raw Edit

Mine

public text v1 · immutable
·published 2007-12-11 07:32 UTC
rendered paste body
#!/bin/bash

# Copyright Jean-Philippe Guillemin <jp.guillemin@free.fr>. This program is free software;
# you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version. Please take a look at http://www.gnu.org/copyleft/gpl.htm

# This script :
# - probes for videocard, monitor and keyboard
# - ask for runlevel
# - writes a configured Xorg config file.



# Version 1.0 - 30/08/2005
#  * Added Xdialog support
# Version 1.1 - 27/09/2005
#  * Fixed bug in call to discover causing glibc error message
# Version 1.2 - 16/10/2005
#  * Fixed bug when 2 video cards are detected by discover
# Version 1.3 - 22/10/2005
#  * Improved/secured tempdir management
# Version 2.0 - 29/12/2005
#  * Monitor probing with edid/X-configure
# Version 2.1 - 17/06/2006
#  * Removed discover support
# Version 2.2 - 17/06/2006
#  * Improved modules detection
# Version 3.2 - 29/09/2006
#  * Ported to Xorg 7.x
# Version 3.3 - 08/04/2007
#  * Compositor aware
# Version 3.4 - 18/04/2007
#  * Silent mode

# Take a look at "Xdialog" and use it instead of "dialog" in case X is running
if [[ "$DISPLAY" && "$(which Xdialog 2>&1 | grep -v "which: no")" ]]; then
	dialog="Xdialog --wrap --left"
else
	dialog="dialog"
fi

# Set the locale in en_US, to avoid problems with Xlib
LANG=en_US

# Path needs to be extended in case you're only half a root :)
export PATH="${PATH}:/usr/sbin:/sbin"

# create the buffer directory
export buffer="/tmp/videoconfig"
mkdir -p $buffer


# Create the xorg.conf file
writexorg() {

cp -f /etc/X11/xorg.conf /etc/X11/xorg.old 2>/dev/null

# Header
cat << EOF >  /etc/X11/xorg.conf

# **********************************************************************
# This file was generated by videoconfig (Zenwalk Xorg configuration tool)
# If you changed your video card or monitor, please run videoconfig again
# from runlevel 3. Don't modify this file yourself until you know what you do ;)
# **********************************************************************

EOF

# Files section
cat << EOF >>  /etc/X11/xorg.conf

# **********************************************************************
# Files section.  This allows default font and rgb paths to be set
# **********************************************************************

EOF

cat $buffer/xorg.files >> /etc/X11/xorg.conf

# Modules section
cat << EOF >>  /etc/X11/xorg.conf

# **********************************************************************
# Module section -- this  section  is used to specify
# which dynamically loadable modules to load.
# **********************************************************************

EOF

cat $buffer/xorg.modules >> /etc/X11/xorg.conf


# Remaining sections

cat << EOF >>  /etc/X11/xorg.conf

# **********************************************************************
# Server flags section.
# **********************************************************************

Section "ServerFlags"
#    Option     "NoTrapSignals"
#    Option     "DontVTSwitch"
#    Option     "DontZap"
#    Option     "DontZoom"
#    Option     "DisableVidModeExtension"
#    Option     "AllowNonLocalXvidtune"
#    Option     "DisableModInDev"
#    Option     "AllowNonLocalModInDev"
#    Option      "blank time"    "10"    # 10 minutes
#    Option      "standby time"  "20"
#    Option      "suspend time"  "30"
#    Option      "off time"      "60"

# Option   "EstimateSizesAggresively" "0"

EndSection


# **********************************************************************
# DRI section
# **********************************************************************

Section "dri"
# Access to OpenGL ICD is allowed for all users:
    Mode 0666
# Access to OpenGL ICD is restricted to a specific user group:
#    Group 100    # users
EndSection


# **********************************************************************
# Extensions section.
# **********************************************************************

Section "Extensions"
        Option "Composite" "Disable"
EndSection


# **********************************************************************
# Core keyboard's InputDevice section
# **********************************************************************
Section "InputDevice"
	Identifier	"Keyboard1"
	Driver	"kbd"
#	Option     "Protocol"      "Xqueue"
#	Option     "AutoRepeat"    "500 5"
#	Option     "Xleds" "1 2 3"
#	Option     "XkbDisable"

	Option     "XkbRules"      "xorg"
	Option     "XkbModel"      "pc105"
	Option     "XkbLayout"     "$xkblayout"
#	Option     "XkbVariant"    "us"
	Option     "XkbOptions"    "$xkboptions"
EndSection


# **********************************************************************
# Core Pointer's InputDevice section
# **********************************************************************

Section "InputDevice"

# Identifier and driver
	Identifier "Mouse1"
	Driver	     "mouse"
	Option	     "Protocol" "Auto"
	Option	     "Device" "/dev/mouse"
#	Option     "Protocol" "Xqueue"
#	Option     "BaudRate" "9600"
#	Option     "SampleRate"	"150"
#	Option     "Emulate3Buttons"
#	Option     "Emulate3Timeout" "50"
#	Option     "ChordMiddle"
	Option     "ZAxisMapping" "4 5"
EndSection


# **********************************************************************
# Monitor section
# **********************************************************************

Section "Monitor"
	Identifier     "Monitor1"
$monitorvendorname
$monitormodelname
$horizsync
$vertrefresh
$useedidfreqs
$dpms
EndSection


# **********************************************************************
# Graphics device section
# **********************************************************************

# Any number of graphics device sections may be present

Section "Device"
	Identifier     "Videocard1"
$cardvendorname
	BoardName   "$videocard"
	Driver     "$driver"
$busid
	Option "RenderAccel" "true"
EndSection

# **********************************************************************
# Screen sections
# **********************************************************************

Section "Screen"
    Identifier  "Videoconfig"
    Device      "Videocard1"
    Monitor     "Monitor1"

   DefaultDepth 24

    Subsection "Display"
        Depth       8
        Modes "1280x1024" "1024x768" "800x600" "640x480"
    EndSubsection
    Subsection "Display"
        Depth       16
        Modes "1280x1024" "1024x768" "800x600" "640x480"
    EndSubsection
    Subsection "Display"
        Depth       24
        Modes "1280x1024" "1024x768" "800x600" "640x480"
    EndSubsection
    Subsection "Display"
        Depth       32
        Modes "1280x1024" "1024x768" "800x600" "640x480"
    EndSubsection
EndSection

# **********************************************************************
# ServerLayout sections.
# **********************************************************************

Section "ServerLayout"
    Identifier     "Simple Layout"
    Screen      "Videoconfig"
    InputDevice     "Mouse1" "CorePointer"
    InputDevice     "Keyboard1" "CoreKeyboard"
EndSection

EOF

}


# Probe monitor model, frequencies and videocard driver #################################
function xprob(){

  useedidfreqs=''
  currenthome=$HOME
  HOME=$buffer
  /usr/bin/X -configure 2>/dev/null
  HOME=$currenthome
  
  monitorvendorname="$( sed -n '/^ *Section *\"Monitor\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new \
  | grep "VendorName" \
  | grep -v "Monitor Vendor" )"
  if [ ! "$monitorvendorname" ] ; then
    monitorvendorname="$(/usr/sbin/get-edid 2>/dev/null | /usr/sbin/parse-edid 2>/dev/null | grep "VendorName")"
    [ ! "$monitorvendorname" ] && monitorvendorname='     VendorName "Monitor Vendor"'
  fi

  monitormodelname="$( sed -n '/^ *Section *\"Monitor\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new \
  | grep "ModelName" \
  | grep -v "Monitor Model" )"
  if [ ! "$monitormodelname" ] ; then
    monitormodelname="$(/usr/sbin/get-edid 2>/dev/null | /usr/sbin/parse-edid 2>/dev/null | grep "ModelName")"
    [ ! "$monitormodelname" ] && monitormodelname='     ModelName "The monitor"'
  fi

  horizsync="$( sed -n '/^ *Section *\"Monitor\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new | grep "HorizSync")"
  if [ ! "$horizsync" ] ; then
    horizsync="$(/usr/sbin/get-edid 2>/dev/null | /usr/sbin/parse-edid 2>/dev/null | grep "HorizSync")"
    if [ ! "$horizsync" ] ; then
      horizsync='     HorizSync 31.5 - 50.0'
      useedidfreqs='     Option "UseEdidFreqs" "1"'
    fi
  fi

  vertrefresh="$( sed -n '/^ *Section *\"Monitor\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new | grep "VertRefresh")"
  if [ ! "$vertrefresh" ] ; then
    vertrefresh="$(/usr/sbin/get-edid 2>/dev/null | /usr/sbin/parse-edid 2>/dev/null | grep "VertRefresh")"
    if [ ! "$vertrefresh" ] ; then
      vertrefresh='     VertRefresh 40-90'
      useedidfreqs='     Option "UseEdidFreqs" "1"'
    fi
  fi

  dpms="$( sed -n '/^ *Section *\"Monitor\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new | grep "DPMS")"

  cardvendorname="$( sed -n '/^ *Section *\"Device\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new | grep "VendorName" )"

  driver="$( sed -n '/^ *Section *\"Device\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new \
  | grep -v "##" \
  | grep "Driver" \
  | sed -e 's/^[ \t]*Driver[ \t]*\"\(.*\)\".*$/\1/')"
  [ ! "$driver" ] && driver='vesa'


  videocard="$( sed -n '/^ *Section *\"Device\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new \
  | grep "BoardName" \
  | grep -v "Unknown" \
  | sed -e 's/^[ \t]*BoardName[ \t]*\"\(.*\)\".*$/\1/' )"
  [ ! "$videocard" ] && videocard="Video device"


  busid="$( sed -n '/^ *Section *\"Device\" *$/,/^ *EndSection *$/p' $buffer/xorg.conf.new | grep "BusID" )"

  # The module section of xorg.conf
  sed -n '/Section \"Module\"/,/EndSection/p' $buffer/xorg.conf.new > $buffer/xorg.modules

  # The files section of xorg.conf
  sed -n '/Section \"Files\"/,/EndSection/p' $buffer/xorg.conf.new > $buffer/xorg.files

}



##################################################################
# Converts keyboard map from kmap (/usr/share/kbd/keymaps) to xkb (/etc/X11/xkb)
function xkbconvert(){

# Probing the keymap

  key="$(cat /etc/rc.d/rc.keymap \
    | grep "^[[:space:]]*\/usr\/bin\/loadkeys" \
    | sed -e 's/^.*loadkeys *\([^\.]*\)\(\.map\)*$/\1/')"



	# We convert keymap into XkbLayout  -- The fields are  keymap | XkbLayout | XkbOptions

	cat << "EOF" | grep "^$key|.*|.*" \
	  | sed -e "s/^.*|\(.*\)|\(.*\)/\1|\2/" > $buffer/xkb
ANSI-dvorak|dvorak|
al|al|
am|am|
ar|ar|
azerty|fr|
az|az|
be-latin1|be|
bg-cp1251|bg|
bg-cp855|bg|
bg_bds-cp1251|bg|
bg_bds-utf8|bg|
bg_pho-cp1251|bg|
bg_pho-utf8|bg|
br-abnt2|br|
br-abnt|br|
br-latin1-abnt2|br|
br-latin1-us|br|
brdk|brdk|
by|by|
by|by|
cf|ca_enhanced|
croat|hr|
cz-cp1250|cz|
cz-lat2-prog|cz|
cz-lat2|cz|
cz-us-qwertz|cz_qwerty|
cz|cz|
de-latin1-nodeadkeys|de|
de-latin1|de|
de_CH-latin1|de_CH|
de|de|
dk-latin1|dk|
dk|dk|
dvorak-l|dvorak|
dvorak-r|dvorak|
dvorak|dvorak|
es-cp850|es|
es|es|
fi-latin1|fi|
fi-latin9|fi|
fi|fi|
fr-latin1|fr|
fr-latin9|fr|
fr-pc|fr|
fr_CH-latin1|fr_CH|
fr_CH|fr_CH|
fr|fr|
gr-pc|us,el|grp:alt_shift_toggle
gr|us,el|grp:alt_shift_toggle
hu|hu|
il-heb|il|
il-phonetic|il|
il|il|
is-latin1-us|is|
is-latin1|is|
it-ibm|it|
it2|it|
it|it|
jp106|jp|
lt.baltic|lt_std|
lt.l4|lt_std|
lt|lt_std|
lt|lt|
mk-cp1251|mk|
mk-utf|mk|
mk0|mk|
mk|mk|
nl2|nl|
nl|nl|
nl|nl|
no-latin1|no|
no|no|
pl2|pl2|
pl|pl|
pt-latin1|pt|
pt-latin9|pt|
ro_win|ro_microsoft|
ru-cp1251|ru|
ru-ms|ru|
ru-yawerty|ru|
ru1|ru|
ru2|ru|
ru3|ru|
ru4|ru|
ru_win|ru|
ru|ru|
se-fi-ir209|se_FI|
se-fi-lat6|se_FI|
se-ir209|se_SE|
se-lat6|se_SE|
sg-latin1-lk450|sg|
sg-latin1|de_CH|
sg|de_CH|
sk-prog-qwerty|sk_qwerty|
sk-prog-qwertz|sk_qwerty|
sk-prog-qwertz|sk|
sk-qwerty|sk_qwerty|
sk-qwertz|sk_qwerty|
slovene|si|
sr-cy|sry|
sv-latin1|sv|
syr|syr|
tel|tel|
th_pat|th_pat|
th_tis|th_tis|
th|th|
tj|tj|
tml|tml|
tr_f-latin5|tr_f|
tr_q-latin5|tr|
tralt|tr|
tralt|tr|
trq|tr|
ua-utf-ws|ua|
ua-utf|ua|
ua-ws|ua|
ua|ua|
ua|ua|
uk|gb|
us-acentos|us|
us|us|
uz|uz|
vn|vn|
wangbe2|fr|
wangbe|fr|
EOF

	xkblayout="$(sed -e "s/^\(.*\)|.*/\1/" $buffer/xkb)"
	xkboptions="$(sed -e "s/^.*|\(.*\)/\1/" $buffer/xkb)"

	rm -f $buffer/xkb
	# Fall back to keymap if no xkb maping available
	if [ ! "$xkblayout" ]; then
	  xkblayout="$key"
	  xkboptions=""
	fi

}

##################################################################
function updatefc(){
	# Update the X font indexes
	if [ -x /usr/bin/fc-cache ]; then
		for dir in /usr/share/fonts/* ; do touch $dir ; done
		/usr/bin/fc-cache 2>&1 1>/dev/null &
	fi
}


##################################################################
function updatemime(){
	# Update the X font indexes
	if [ -x /usr/bin/update-mime-database ]; then
		/usr/bin/update-mime-database /usr/share/mime 2>&1 1>/dev/null &
	fi
}

##################################################################
function updatescrollkeeper(){
	# Generate GNOME documentation
	if [ -x /usr/bin/scrollkeeper-update ]; then
		/usr/bin/scrollkeeper-update 2>&1 1>/dev/null &
	fi
}


     ########################################
########### HERE COMES THE SUN ####################
     ########################################



if [ "$DISPLAY" ]; then

	$dialog --msgbox "To probe for the video driver and monitor please run \"$(basename $0)\" from runlevel 3" 8 70

else

	
	if [ "$1" = "silent" ] ; then
		echo "Configuring the X server"
		(
		xprob
		xkbconvert
		writexorg
		updatefc
		updatemime	
		sed -i "s/^id:.*:initdefault:$/id:4:initdefault:/" /etc/inittab
		sed -i 's/^\([ \t]*Option.*Composite.*\)\".*\".*$/\1\"Enable\"/' /etc/X11/xorg.conf 
		) 2>&1 1>/dev/null
		exit
	fi
	
	

	# probe for videocard/monitor specs if we are called from runlevel 3
	clear
	xprob
	clear

  $dialog \
  --title "X11 configuration" \
  --icon "videoconfig" \
  --menu \
" Videocard : $videocard \n\
 Driver : \"$driver\" \n\
 Do you want to use this configuration (recommended) ?\n\n" \
14 75 3 \
   "Yes" "Configure X11" \
   "No" "keep existing configuration" 2> $buffer/configxorg

	configxorg=$(cat $buffer/configxorg)
	rm -f $buffer/configxorg

	case $configxorg in
	  Yes)
		$dialog --infobox "Configuring the X server..." 8 45
		sleep 1
		xkbconvert
		writexorg
		;;
	  No)
		;;
	esac

fi


# Compositor support ?

  $dialog \
  --title "Compositor" \
  --icon "videoconfig" \
  --menu \
"Do you want to enable the compositor (transparency, shadows, ... it can be slow on some videocards) ?\n\n" \
14 75 3 \
   "Yes" "Enable the compositor" \
   "No" "Disable the compositor" 2> $buffer/compositor

compositor=$(cat $buffer/compositor)
rm -f $buffer/compositor

case $compositor in
  Yes)
    $dialog --infobox "Enabling compositor extension..." 8 45
    sleep 1
	sed -i 's/^\([ \t]*Option.*Composite.*\)\".*\".*$/\1\"Enable\"/' /etc/X11/xorg.conf 
    ;;
  No)
    $dialog --infobox "Disabling compositor extension..." 8 45
    sleep 1  
	sed -i 's/^\([ \t]*Option.*Composite.*\)\".*\".*$/\1\"Disable\"/' /etc/X11/xorg.conf   
    ;;
esac


updatefc
updatemime

# Runlevel 3 or 4 ?

  $dialog --title "Login mode configuration" --icon "videoconfig" --menu \
"Select the login mode you want to enable on startup:\n\n" \
16 76 3 \
   "Text" "Text mode login - runlevel 3" \
   "Graphical" "Graphical Xwindow login - runlevel 4" \
   "Skip" "No change" 2> $buffer/runlevel

runlevel=$(cat $buffer/runlevel)
rm -f $buffer/runlevel

case $runlevel in
  Text)
    $dialog --infobox "Setting $runlevel login..." 8 45
    sleep 1
    sed -i "s/^id:.*:initdefault:$/id:3:initdefault:/" /etc/inittab
    ;;
  Graphical)
    $dialog --infobox "Setting $runlevel login..." 8 45
    sleep 1
    sed -i "s/^id:.*:initdefault:$/id:4:initdefault:/" /etc/inittab
    ;;
  Skip)
    $dialog --infobox "Keeping current configuration." 8 45
    sleep 1
    ;;
esac