#! /bin/bash
#**************************************************************************
#* update-X-config - Set parameters of X config.
#* Version:     0.0.3 01/09/2005
#* File:        update-X-config.
#* Description: Set parameters of X config.
#* Platform(s):	GNU/Linux, All
#* Author(s):	Della Bianca Giuseppe <bepi@adria.it><bepii@libero.it>
#*
#* Copyright (C) 2005 Della Bianca Giuseppe <bepi@adria.it><bepii@libero.it>
#* This file is part of update-X-config.
#*
#* update-X-config 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.
#*
#* update-X-config is distributed in the hope that it will be useful,
#* but WITHOUT ANY WARRANTY; without even the implied warranty of
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#* GNU General Public License for more details.
#*
#* You should have received a copy of the GNU General Public License
#* along with update-X-config; if not, write to the Free Software
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#**************************************************************************

BaseDir=`dirname $0`

# load the function for update-X-config
. "$BaseDir/update-X-configfunc"

# set parameters for gesconf, local copy of xorg.conf, ...
GFS=$'\007'
OLDIFS=$IFS
FilesConf=""
FileXConf="$BaseDir/xorg.conf"
GcProg="$BaseDir/gesconf"
GcX="$GcProg -ps $GFS -fx $FileXConf.new -v 1"
GcKey="$GcProg -ps $GFS -v 3"
UpdGo="ok"

CheckExeOpt $*

if [ "$UpdGo" == ok ]; then
# copy the real X config
    cp /etc/X11/xorg.conf $FileXConf.act
    cp $FileXConf.act $FileXConf.new

# set update of X config
    echo -n > "$BaseDir/update-X-config.del.tmp"
    echo -n > "$BaseDir/update-X-config.upd.tmp"
    echo -n > "$BaseDir/update-X-config.und.tmp"

# read list of configuration file
    for ActFile in $FilesConf; do
	echo -e "\nUpdating from ' $ActFile ' file:"
	if [ -f "$ActFile" ]; then
# read new parameters from configuration file
	    ListUpdConf "$ActFile"
	else
	    UpdGo="ko"
	    echo "File ' $ActFile ' not existent"
	    break;
	fi
    done

    if [ "$UpdGo" == ok ]; then
# update X config
	echo -e "\nDelete parameters on X config"
	cat "$BaseDir/update-X-config.del.tmp" | ($GcProg -ps $GFS -fx $FileXConf.new -v 4 -w - -d)
	echo -e "\nUpdate parameters on X config"
	cat "$BaseDir/update-X-config.upd.tmp" | ($GcProg -ps $GFS -fx $FileXConf.new -v 4 - -s)
    fi

    rm "$BaseDir/update-X-config.del.tmp"
    rm "$BaseDir/update-X-config.upd.tmp"
    rm "$BaseDir/update-X-config.und.tmp"
fi


