LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 738|回复: 6

Auto-configure X.org

[复制链接]
发表于 2005-5-16 14:30:41 | 显示全部楼层 |阅读模式
转贴来自:http://forums.gentoo.org/viewtopic-t-332150.html
作者:DremK

该sh自动配置X.org (它是可能的配置XFree86 太) 。
它根据' X - 配置' 并且它使用' ddcprobe ' 从' ddcxinfo-knoppix ' 。

但我增加了新改善:


字体
它增加所有目录与发现在/usr/share/fonts/。和安置他们这样的形式是因而的字体:

"/usr/share/fonts/misc/"
"/usr/share/fonts/TTF/"
其它dirs ttf
"/usr/share/fonts/Type1/"
其它dirs type1
"/usr/share/fonts/CID/"
其它dirs cid
"/usr/share/fonts/75dpi/"
"/usr/share/fonts/100dpi/"
其它dirs 位图

并且它核实, 那些主要目录(混杂, TTF, Type1 、CID 、75dpi, 100dpi) 存在和谁他们把字体, 他们是commentd 外面。并且如果视频模式比1024x768, 那么它伟大或相等的改变命令在75dpi 和100dpi 之间。


显示器
它增加DPMS 选择来保存能量。


屏幕
它选择2 个更好的方式达成协议"更高的赫兹是更好的" 方法为各深度。并且它作为缺省选择好深度(搜寻深度与1024x768 作为极小值, 800x600) 。


卡片
它增加' 部分DRI ' 来3d 卡片并且它可能设置选择为某一卡片作为' SWcursor ' 为三叉戟卡片。


输入装置
在键盘设备里它增加XkbModel, XkbLayout, XkbVariant (nodeadkeys) 选择
在老鼠设备里它增加ZAxisMapping 选择
并且它查出touchpad 并且它增加。


我会想, 它被测试了在膝上计算机, TFT 和没有EDID 显示器, 核实如果失败就选上的决议。

重要: 不要探查在显示器non-EDID (Plug'n'Play) (显示器buil 在1996 之前) 。这不会有效但是我工作为固定它。

Download 地址:Xconfig.sh
:%
发表于 2005-5-16 15:31:49 | 显示全部楼层
好东东,下载试试
回复 支持 反对

使用道具 举报

发表于 2005-5-17 21:38:12 | 显示全部楼层
麻烦楼主把脚本贴到这里来吧,那个ftp下不了啊。
回复 支持 反对

使用道具 举报

发表于 2005-5-17 22:35:18 | 显示全部楼层
哈哈,明显是软件翻译的内容
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-17 22:38:10 | 显示全部楼层
Post by xiaosir
哈哈,明显是软件翻译的内容

[PHP]#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# Vinque.org (C) Jonas Melian <jonasmg@mail.berlios.de> 2005

ERROR=1
NUM_MODES=2
file_xorg_cfg="/etc/X11/xorg.conf"
file_x_input="/root/xorg.conf.new"
file_run=$(basename $0)
file_run_x=$(which X 2>/dev/null)
file_run_ddcprobe=$(which ddcprobe 2>/dev/null)
fonts="/usr/share/fonts/"
file_tmp="/tmp/Xconf-$$"
file_tmp_section="$file_tmp-section"
file_tmp_card="$file_tmp-card"
file_tmp_input="$file_tmp-input"


Check() {
(( $(id -u) != 0 )) &&
        echo "Must be root to run '$file_run'." &&
        fail="$ERROR"
       
[[ ! $file_run_x ]] &&
        echo "File 'X' not found. You must install X Window System." &&
        fail="$ERROR"
       
[[ ! $file_run_ddcprobe ]] &&
        echo "File 'ddcprobe' not found. You must install 'ddcxinfo-knoppix'." &&
        fail="$ERROR"

[[ $fail ]] && exit "$ERROR"
}

GetOptions() {
if (( $# > 1 )); then
                cat <<END
Invalid option.

Usage: $file_run
Try '$file_run --help' for more information.
END
                exit "$ERROR"
else
        case "$1" in
                --help)
                        cat <<END
USAGE: $file_run
Build Xorg config file using 'X -configure'.

  -v, --verbose                print information
  -vc,--colour                print information in clolour
      --help                display this information and exit

Report bugs to <jonasmg@mail.berlios.de>
END
                        exit 0
                        ;;
                -v|--verbose) opt_verbose="ok";;
                -vc|--colour) opt_colour="ok";;
        esac
fi
}

Configure() {
$file_run_x -configure &>/dev/null

[[ ! -f $file_x_input ]] &&
        echo "File '$file_x_input' not found." &&
        exit "$ERROR"
       
# get devices identifiers
id_screen=$(sed -n '/^Section \"ServerLayout\"/,/^EndSection/{/^[[:space:]]*Screen/s/^[^"]*\("[^"]*"\).*/\1/p}' $file_x_input)

id_card=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_screen/,/^EndSection/{/^[[:space:]]*Device/s/^[^\"]*//p}" $file_x_input)

id_monitor=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_screen/,/^EndSection/{/^[[:space:]]*Monitor/s/^[^\"]*//p}" $file_x_input)

# add new sections
file=$(echo 'Section "ServerFlags"
\tOption\t    "AllowMouseOpenFail" "true"
\tOption\t    "BlankTime"   "5"
\tOption\t    "StandbyTime" "10"
\tOption\t    "SuspendTime" "20"
\tOption\t    "OffTime"     "30"
EndSection\n')

[[ $(cat "$file_x_input" |grep -wi 'load.*dri') ]] &&
        file=$(echo -e "$file"
echo 'Section "DRI"
\tMode 0666
EndSection\n')

#Section "Extensions"
#\tOption\t    "Composite" "true"
#EndSection\n')

echo -e "$file" >"$file_tmp_section"

opt_sed="\$r $file_tmp_section\n; /^Section \"Module\"/,/^EndSection/{/^[[:space:]]*[^#]Load[ ]*\"(record|xtrap|type1)\"/s/L/#L/}"
}

ConfigureCard() {
xmodule=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_card/,/^EndSection/{/^[[:space:]]*Driver/s/^[^\"]*\"\([^\"]*\).*/\1/p}" $file_x_input)
file=

case "$xmodule" in
        fbdev)
                opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_screen/,/^EndSection/{/^[[:space:]]*[^#]DefaultColorDepth/s/D/#D/}"
                ;;
        nv|trident)
                file=$(echo '\tOption\t    "SWcursor"')
END
                ;;
        ati)
#                card=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_card/,/^[[:space:]]*BoardName/{/^[[:space:]]*BoardName/s/^[^\"]*//p}" $file_x_input)
               
#                [[ $(echo $card |grep -wi 'radeon') ]] &&
#                        file=$(echo '\tOption\t    "AGPMode" "4"
#\tOption\t    "EnablePageFlip" "True"
#\tOption\t    "AGPFastWrite" "True"')
                ;;
esac

[[ $file ]] && echo -e "$file" >"$file_tmp_card" &&
        opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_card/,/^EndSection/{/^EndSection/{r $file_tmp_card\nN}}"
}

Sort() {
# from mayor to minor
column_1=$(echo "$modes_tmp" |awk '{print $1}' |sort -nru)
modes_tmp2=

for i in $column_1; do
        tmp=$(echo "$modes_tmp" |awk -v col_1="$i" '$1 == col_1{print $2}' |sort -nr)
        tmp=$(echo "$tmp" |sed "s/^/$i /")
        modes_tmp2=$(echo "$modes_tmp2"; echo "$tmp")
done
}

ConfigureMonitor() {
ddc=$($file_run_ddcprobe 2>/dev/null)

# We must use NoPM, because some machines freeze if Power management is being activated
[[ $(grep -w 'noapm' /proc/cmdline) ]] &&
        opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_monitor/,/^EndSection/{/^[[:space:]]*[^#]Option[[:space:]]*\"DPMS\"/s/O/#O/}; /^[[:space:]]*Identifier[ ]*$id_monitor/,/^EndSection/{/^[[:space:]]*#Option[[:space:]]*\"DPMS\"/a\        Option            \"NoPM\"\n}"

# If it can read ddc
if (( $(echo "$ddc" |wc -l) > 1 )); then
        #signal=$(echo "$ddc" |awk '/signal type/{print $4;exit}')
       
        # modes with hertzios (the first best hertzios and so)
        modes_tmp=$(echo "$ddc" |awk '/^Standard/{print $4 " " $6}')
        Sort
        modes_hz=$(echo "$modes_tmp2" |sed '1{/^$/d}' |cut -d ' ' -f2)
       
        # modes with depth
        modes_tmp=$(echo "$ddc" |awk '/^[[:space:]]*[0-9]/ && !/(text|@)/{print $1}')
       
        # Translate colours number to depth bits
        for i in $modes_tmp; do
                case "$i" in
                        *x2)   modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x2/ 1/') ;;
                        *x16)  modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x16/ 4/') ;;
                        *x256) modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x256/ 8/') ;;
                        *x32k) modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x32k/ 15/') ;;
                        *x64k) modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x64k/ 16/') ;;
                        *x16m) modes_depth=$(echo "$modes_depth"; echo "$i" |sed 's/x16m/ 24/') ;;
                esac
        done
       
        modes_tmp=$(echo "$modes_depth" |sed '1{/^$/d}' |awk '{print $2 " " $1}')
        Sort
        modes_depth=$(echo "$modes_tmp2" |sed '1{/^$/d}')
       
        # search a depth with 1024x768 as minimum, else 800x600
        for i in 1024 800; do
                depth=
                while read j; do
                        if (( $(echo "$j" |sed 's/^.*[ ]\([^x]*\).*/\1/') >= $i )); then
                                depth=$(echo "$j" |cut -d ' ' -f1)
                                (( $depth >= 8 )) && break
                        fi
                done <<<"$modes_depth"
                (( $depth >= 8 )) && break
        done
       
        for i in $column_1; do
                tmp=; modes=
                while read j; do
                        [[ $(echo "$j" |cut -d ' ' -f1) == $i ]] &&
                                tmp=$(echo "$tmp"; echo "$j" |cut -d ' ' -f2)
                done <<<"$modes_depth"
               
                # Put before modes whith better hz
                tmp=$(echo "$tmp" |sed '1{/^$/d}')
                for x in $modes_hz; do
                        for y in $tmp; do
                                [[ $x == $y ]] &&
                                        modes=$(echo "$modes"; echo "$x") &&
                                        tmp=$(echo "$tmp" |sed "/$x/d")
                        done
                done
               
                # add the other modes
                [[ $tmp ]] && modes=$(echo "$modes"; echo "$tmp")
               
                modes=$(echo "$modes" |sed '1{/^$/d}' |head -n$NUM_MODES |awk '{print "\"" $1 "\""}')
                modes=$(echo $modes)
               
                opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_screen/,/^EndSection/{/^[[:space:]]*Depth[ ]*$i/a\                Modes $modes\n}"
        done
else
        for i in 1 4 8 15 16 24; do
                opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_screen/,/^EndSection/{/^[[:space:]]*Depth[ ]*$i/a\                Modes \"1024x768\" \"800x600\" \"640x480\"\n}"
        done
        depth="16"
fi

opt_sed="$opt_sed; /^[[:space:]]*Identifier[ ]*$id_screen/,/^[[:space:]]*SubSection[ ]*\"Display\"/{/^[[:space:]]*SubSection[ ]*\"Display\"/i\        DefaultColorDepth $depth\n}"
}

ConfigureFonts() {
for i in 100dpi 75dpi CID TTF Type1 misc; do
        if [[ -d $fonts$i ]]; then
                (( $(ls "$fonts$i"/ |wc -w) < 4 )) &&
                        opt_sed="$opt_sed; /^[[:space:]]*[^#]FontPath[ ].*\/$i/s/F/#F/"
        else
                opt_sed="$opt_sed; /^[[:space:]]*[^#]FontPath[ ].*\/$i/s/F/#F/"
        fi
done

for d in "$fonts"* ; do
        [[ -d $d ]] || continue
        i=$(basename "$d")
        case "$i" in
                encodings|util|100dpi|75dpi|CID|TTF|Type1|misc)
                        continue ;;
                *)
                        if [[ $(find "$d" -maxdepth 1 -type f -name '*.pcf.gz') ]]; then
                                opt_sed="$opt_sed; /^[[:space:]]*FontPath[ ].*\/100dpi/a\        FontPath     \"$d/\"\n"
                        elif [[ $(find "$d" -maxdepth 1 -type f -name '*.[to]t[fc]') ]]; then
                                opt_sed="$opt_sed; /^[[:space:]]*FontPath[ ].*\/TTF/a\        FontPath     \"$d/\"\n"
                        elif [[ $(find "$d" -maxdepth 1 -type f -name '*.cid') ]]; then
                                opt_sed="$opt_sed; /^[[:space:]]*FontPath[ ].*\/CID/a\        FontPath     \"$d/\"\n"
                        elif [[ $(find "$d" -maxdepth 1 -type f -name '*.pf[ab]') ]]; then
                                opt_sed="$opt_sed; /^[[:space:]]*FontPath[ ].*\/Type1/ a\        FontPath     \"$d/\"\n"
                        fi
                        ;;
        esac
done

# if mode >= 1024x768, then change 75dpi x 100dpi
modes=$(echo -e "$opt_sed" |sed -n "/Modes/s/^.*\*$depth[^0-9x\"]\+//pg")

(( $(echo $modes |sed 's/\"\([0-9]*\).*/\1/') >= 1024 )) &&
        opt_sed="$opt_sed; /^[[:space:]]*FontPath[ ].*\/75dpi/{h;d};/^[[:space:]]*FontPath[ ].*\/100dpi/{p;g}"
}

ConfigureInput() {
input=$(< /proc/bus/input/devices)

file=$(echo 'Section "InputDevice"
\tIdentifier  "Keyboard0"
\tDriver      "kbd"
\tOption\t    "XkbModel" "pc105"
\tOption\t    "XkbLayout" "en_US"
\t#Option\t    "XkbVariant" "nodeadkeys"
EndSection

Section "InputDevice"
\tIdentifier  "Mouse0"
\tDriver      "mouse"
\tOption\t    "rotocol" "auto"
\tOption\t    "Device" "/dev/@dev@"
\tOption\t    "ZAxisMapping" "4 5"
EndSection')

if [[ $(echo $input |egrep -wi 'Name.*(synaptics|alps)') ]]; then
        file=$(echo -e "$file"
echo '\nSection "InputDevice"
\tIdentifier  "Touchpad"
\tDriver      "synaptics"
\tOption\t    "SendCoreEvents"
\tOption\t    "Device" "/dev/input/@event@"
\tOption\t    "rotocol" "event"
\tOption\t    "SHMConfig" "on"
\tOption\t    "LeftEdge" "1900"
\tOption\t    "RightEdge" "5400"
\tOption\t    "TopEdge" "1400"
\tOption\t    "BottomEdge" "4500"
\tOption\t    "FingerLow" "25"
\tOption\t    "FingerHigh" "30"
\tOption\t    "MaxTapTime" "180"
\tOption\t    "MaxTapMove" "220"
\tOption\t    "VertScrollDelta" "100"
\tOption\t    "MinSpeed" "0.02"
\tOption\t    "MaxSpeed" "0.18"
\tOption\t    "AccelFactor" "0.0010"
EndSection')

        event=$(echo "$input" |sed -n '/Name=.*Synaptics/,/Handlers=/{/Handlers=/p}' |sed 's/^.*\(event[0-9]*\).*/\1/')
       
        opt_sed="$opt_sed; /^Section \"Module\"/,/^EndSection/{/^EndSection/i\        Load  \"synaptics\"\n}; /^Section \"ServerLayout\"/,/^EndSection/{/^[[:space:]]*InputDevice[ ]*\"Mouse0\"[ ]*\"CorePointer\"/i\        InputDevice    \"Touchpad\"\n}"
       
        [[ ! -f /usr/lib/modules/input/synaptics_drv.o ]] &&
                echo "You must install 'synaptics' for the complete use of the touchpad."
fi

for i in input/mice mouse psaux; do
        [[ -e /dev/$i ]] && dev="$i" && break
done

echo -e "$file" |sed "s,@dev@,$dev,;s,@event@,$event," >"$file_tmp_input"

opt_sed="$opt_sed; /^Section \"InputDevice\"/,/^EndSection/d; /^Section \"Module\"/,/^$/{/^$/{r $file_tmp_input\n}}"
}

BuildConfig() {
[[ -f "$file_xorg_cfg" ]] &&
        mv -f "$file_xorg_cfg" "${file_xorg_cfg}~"
       
opt_sed=$(echo -e "$opt_sed")
sed -r "$opt_sed" "$file_x_input" >"$file_xorg_cfg"

rm -f "$file_tmp_section" "$file_tmp_card" "$file_tmp_input" "$file_x_input"
}

Verbose() {
monitor=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_monitor/,/^EndSection/{/^[[:space:]]*ModelName/s/^[^\"]*\"\([^\"]*\).*/\1/p}" $file_xorg_cfg)

h_refresh=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_monitor/,/^EndSection/{/^[[:space:]]*HorizSync/s/[^0-9.-]\+//gp}" $file_xorg_cfg)

v_refresh=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_monitor/,/^EndSection/{/^[[:space:]]*VertRefresh/s/[^0-9.-]\+//gp}" $file_xorg_cfg)

#modes=$(sed -n "/^[[:space:]]*Identifier $id_screen/,/^EndSection/{/^[[:space:]]*Depth[ ]*$depth/,/Modes/{/^[[:space:]]*Modes/s/^[^\"]*//p}}" $file_xorg_cfg)

card=$(sed -n "/^[[:space:]]*Identifier[ ]*$id_card/,/^EndSection/{/^[[:space:]]*BoardName/s/^[^\"]*\"\([^\"]*\).*/\1/p}" $file_xorg_cfg)

[[ $opt_colour ]] && NORMAL=$'\e[0m' && HILITE=$'\e[36;01m'

echo "Graphic card is ${HILITE}${card}${NORMAL}, using modulo ${HILITE}${xmodule}${NORMAL}"
echo "Monitor is ${HILITE}${monitor:-Generic Monitor}${NORMAL}, H{HILITE}${h_refresh} Khz${NORMAL}, V{HILITE}${v_refresh} Hz${NORMAL}"
echo "Using modes ${HILITE}${modes}${NORMAL} to ${HILITE}${depth}${NORMAL} bits of depth"
}


# Start
Check
GetOptions "$@"
Configure
ConfigureMonitor
ConfigureCard
ConfigureFonts
ConfigureInput
BuildConfig
[[ $opt_verbose || $opt_colour ]] && Verbose
[/PHP]
回复 支持 反对

使用道具 举报

发表于 2005-5-18 09:04:40 | 显示全部楼层
这个翻译也太差了吧。
这个最搞笑——Trident Card (三叉戟卡片)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-18 10:30:17 | 显示全部楼层
Post by xiaosir
哈哈,明显是软件翻译的内容


:beat 没什么好说的,本来就是转官方文章,E文不好,用了在线网页翻译看的,无非就是点了一下“复制文本”。我想这遍文章,重要的是shell ,翻译质量并不是主要问题。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表