#!/bin/bash
#**************************************************************************
#* ScriptBackUp - Executes the backup and if demanded executes the shutdown.
#* Version:     0.2.0 10/08/2006
#* File:        sbackup
#* Description: Read the configuration and executes backup and/or the shutdown.
#* Platform(s):	GNU/Linux, All
#* Author(s):	Della Bianca Giuseppe <bepi@adria.it><bepii@libero.it>
#*
#* Copyright (C) 2005-6 Della Bianca Giuseppe <bepi@adria.it><bepii@libero.it>
#* This file is part of ScriptBackUp.
#*
#* ScriptBackUp 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.
#*
#* ScriptBackUp 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 ScriptBackUp; if not, write to the Free Software
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#**************************************************************************/

#export LC_ALL="C"
ProgFile=$0
ProgPath=`dirname $ProgFile`
ProgName=`basename $ProgFile`
if [ $ProgPath == "." ]; then
    ProgPath=`pwd`;
fi
OLDIFS=$IFS
#
# load the data and the functions necessary to ScriptBackUp and for 
# execute the backup
. $ProgPath"/"$ProgName"conf"
. $ProgPath"/"$ProgName"func"
. $ProgPath"/"$ProgName"runfunc"
. $ProgPath"/"$ProgName"bkpfunc"
#
. gettext.sh
export TEXTDOMAIN
export TEXTDOMAINDIR
#
echo `eval_gettext "Start of \\\$ProgName \\\$ProgVers"`
ProgResult=0
# initialize the program
InitProg
# execute the sets of backup/shutdown
if [ $ProgResult == "0" ]; then
    for BackUpName in "$@"; do
	echo "Set: "$BackUpName
	GoBackUp="true"
	GoShut="true"
# check and initialize the set of backup/shutdown
	InitBackUp
# run the backup
	RunBackUp
# run the shutdown
	RunShutDown
# end the set of backup/shutdown
	EndBackUp
    done
fi
#
# visualizes the outcome of the program
if [ $ProgResult == "-1" ]; then
    ProgResult=0
fi
if [ $ProgResult == "0" ]; then
    echo `eval_gettext "\\\$ProgName FINISHED CORRECTLY"`
else
    echo `eval_gettext "\\\$ProgName FINISHED WITH ERROR"`
fi

exit $ProgResult

