1
0
xorg-x11-server/xlog2xconf.sh

84 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/sh
#
# Create minimal xorg.conf extracted from Xorg.<DISPLAY>.log
#
# -c <configfile> (use to specify configfile to create)
# -e (edit file with $EDITOR after creation)
# -f (overwrite existing <configfile>)
# -l <logfile> (use to specify X logfile to read)
#
if [ $UID -ne 0 ]; then
echo "You must be root"
exit 1
fi
configfile=/etc/X11/xorg.conf
editor=false
overwrite=false
logfile=/var/log/Xorg.0.log
while getopts ":c:efl:" opt; do
case $opt in
c ) configfile=${OPTARG}
;;
e ) editor=true
;;
f ) overwrite=true
;;
l ) logfile=${OPTARG}
;;
* ) echo 'usage: minimal-xconfig [-c <configfile>] [-e] [-f] [-l <logfile>]'
exit 1
;;
esac
done
if [ ! -f $logfile ]; then
echo "$logfile does not exist."
echo "Use \"-l <logfile>\" to specify a different logfile."
exit 1
fi
if ! grep -q -- "(==) --- Start of built-in configuration ---" $logfile; then
echo "$logfile does not contain the required xorg.conf section."
echo "Probably it uses a regular xorg.conf."
echo "Use \"-l <logfile>\" to specify a different logfile."
exit 1
fi
if [ -f $configfile -a "$overwrite" == "false" ]; then
echo "$configfile already exists."
echo "Use \"-f\" to overwrite or \"-c <configfile>\" to specify a different configfile."
exit 1
fi
begin=false
cat $logfile | \
while read line; do
if [ "$begin" == "true" ]; then
if echo $line | grep -q -- "(==) --- End of built-in configuration ---"; then
break
else
if ! echo $line | grep -q ^Section; then
if ! echo $line | grep -q ^EndSection; then
echo -n " "
fi
fi
echo $line
test "$line" == "EndSection" && echo
fi
elif echo $line | grep -q -- "(==) --- Start of built-in configuration ---"; then
begin=true
fi
done > $configfile
if [ "$editor" == "true" ]; then
$EDITOR $configfile
else
echo "created $configfile"
fi
exit 0