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
# 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
# create the buffer directory
buffer="$(mktemp -d -p /tmp temp.XXXXXXXX)"
# remove the buffer directory on any type of exit
trap 'rm -rf $buffer 2>/dev/null' TERM INT EXIT
# Create the xorg.conf file
writexorg() {
cp -f /etc/X11/xorg.conf /etc/X11/xorg.old
# 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
# **********************************************************************
# 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" ""
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
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
keymap="$(cat /etc/rc.d/rc.keymap \
| grep "^[[:space:]]*\/usr\/bin\/loadkeys" \
| sed -e 's/^.*loadkeys *\([^\.]*\)\(\.map\)*$/\1/')"
############ Converting keymap into XkbLayout ##########
# The fields are xkb : kmap : Description
cat <<EOF | egrep -E "^.*:$keymap:.*" \
| sed -e "s/^\(.*\):.*:.*/\1/" > $buffer/xkblayout
fr:azerty:
be:be-latin1:Belgian
fr:fr-latin1:French
fr:fr-latin9:French
fr:fr-pc:
fr:fr:French
fr:wangbe:
fr:wangbe2:
dvorak:ANSI-dvorak:
brdk:brdk:Brasilian dvorak
dvorak:dvorak-l:
dvorak:dvorak-r:
dvorak:dvorak:Dvorak
bg:bg-cp1251:
bg:bg-cp855:
bg:bg_bds-cp1251:
bg:bg_bds-utf8:
bg:bg_pho-cp1251:
bg:bg_pho-utf8:
br:br-abnt:
br:br-abnt2:
br:br-latin1-abnt2:
br:br-latin1-us:Brazilian
by:by:Belarusian
ca_enhanced:cf:French Canadian
cz:cz-cp1250:
cz:cz-lat2-prog:
cz:cz-lat2:
cz:cz:
dk:dk-latin1:
dk:dk:Danish
es:es-cp850:
es:es:Spanish
fi:fi-latin1:
fi:fi-latin9:
fi:fi:Finnish
el:gr-pc:Greek
el:gr:
il:il-heb:Israeli
il:il-phonetic:
il:il:
is:is-latin1-us:
is:is-latin1:
it:it-ibm:
it:it:Italian
it:it2:
jp:jp106:Japanese
lt_std:lt.baltic:
lt_std:lt.l4:
lt:lt:Lithuanian qwerty "numeric"
lt_std:lt:Lithuanian azerty standard
mk:mk-cp1251:
mk:mk-utf:
mk:mk:Macedonian
mk:mk0:
nl:nl:Dutch
nl:nl2:
no:no-latin1:
no:no:Norwegian
pl:pl:Polish
pl2:pl2:Polish (qwertz)
pt:pt-latin1:Portuguese
pt:pt-latin9:
ro_microsoft:ro_win:
ru:ru-cp1251:
ru:ru-ms:
ru:ru-yawerty:
ru:ru:Russian
ru:ru1:
ru:ru2:
ru:ru3:
ru:ru4:
ru:ru_win:
se_FI:se-fi-ir209:
se_FI:se-fi-lat6:Northern Saami (Finland)
se_SE:se-ir209:
se_SE:se-lat6:
sk_qwerty:sk-prog-qwerty:
sk_qwerty:sk-qwerty:
sry:sr-cy:
sv:sv-latin1:
tr:tr_q-latin5:
tr:tralt:Turkish
tr:trq:
ua:ua-utf-ws:
ua:ua-utf:
ua:ua-ws:
ua:ua:Ukrainian
gb:uk:United Kingdom
us:us-acentos:
us:us:U.S. English
hr:croat:Croatian
cz_qwerty:cz-us-qwertz:
de:de-latin1-nodeadkeys:German latin1
de:de-latin1:German latin1
de:de:German
de_CH:de_CH-latin1:
fr_CH:fr_CH-latin1:
fr_CH:fr_CH:Swiss French
hu:hu:Hungarian
sg:sg-latin1-lk450:
de_CH:sg-latin1:Swiss German
de_CH:sg:Swiss German
sk:sk-prog-qwertz:Slovak
sk_qwerty:sk-prog-qwertz:Slovak (qwerty)
sk_qwerty:sk-qwertz:
si:slovene:Slovenian
al:al:Albanian
ar:ar:Arabic
am:am:Armenian
az:az:Azerbaijani
by:by:Belarusian
nl:nl:Dutch
syr:syr:Syriac
tj:tj:Tajik
tml:tml:Tamil
tel:tel:Telugu
th:th:Thai (Kedmanee)
th_tis:th_tis:Thai (TIS-820.2538)
th_pat:th_pat:Thai (Pattachote)
tr:tralt:Turkish
tr_f:tr_f-latin5:Turkish (F)
ua:ua:Ukrainian
uz:uz:Uzbek
vn:vn:Vietnamese
EOF
xkblayout=$(cat $buffer/xkblayout)
rm -f $buffer/xkblayout
# Fall back to keymap if no xkb maping available
if [ ! "$xkblayout" ]; then
xkblayout="$keymap"
fi
}
########################################
########### HERE COMES THE MAIN SCRIPT ####################
########################################
if [ "$DISPLAY" ]; then
$dialog --msgbox "To configure X11 : please run \"$(basename $0)\" in text mode" 8 70
else
# probe for videocard/monitor specs
xprob
$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" "Change the xorg.conf file to use \"$driver\" driver" \
"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 2
xkbconvert
writexorg
;;
No)
;;
esac
fi
$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 2
sed -i "s/^id:.*:initdefault:$/id:3:initdefault:/" /etc/inittab
;;
Graphical)
$dialog --infobox "Setting $runlevel login..." 8 45
sleep 2
sed -i "s/^id:.*:initdefault:$/id:4:initdefault:/" /etc/inittab
;;
Skip)
$dialog --infobox "Keeping current configuration." 8 45
sleep 2
;;
esac