|

楼主 |
发表于 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] |
|