#! /usr/bin/perl -w

my $configuration;

# following variables to be overridden by configuration file
# boolean to not run command, just prints command that would be executed.
# also, at level 3, will not use standard configurations, but will use configuration file ../../etc/rsbackup/rsbackup.conf
# for development
$configuration{'TEST_CONDITIONS'} = 0;

# who gets backup logs
$configuration{'MAIL_TO'} = 'backups@example.com';
$configuration{'MY_NAME'} = 'client';

# full server name/IP and path to backup server, suitable for pasting into the rsync command
# NOTE: the default assumes the user is root, the server is named backup in the same domain as this machine
#       and the target path on the server is /home/backups directory
$configuration{'BACKUP_SERVER'} = 'root@backup.example.com'; # full server name to back up to (or IP)
$configuration{'PATH_ON_SERVER'} = '/'; # root path on the server

# THIS IS THE ACTUAL PATH USED. It is generally used by calculating from variables above. Note that it can be
# used for other purposes also, such as a root directory for versions.
$configuration{'BACKUP_PATH'} = "$configuration{'BACKUP_SERVER'}:$configuration{'PATH_ON_SERVER'}";

# The following list determines the directories on THIS MACHINE that are to be backed up. NOTE: During
# upgrades, this entry is assumed to be on one line, upgrade may corrupt this entry if you write it
# as a multi-line.
$configuration{'DIRS_TO_BACKUP'} = ['opt', '/root', '/home'];        # which directories on source are to be backed up

# where to store the logs on this machine. NOTE: log files are compressed and stored, and are not removed
# by rsync_backup. The default is to place them in /root/backup_logs, so they are actually backed up
# then next day also.
$configuration{'LOGDIR'} = '/home/backup_logs';                  # log directory, either relative to script or absolute

# if the following scripts are set, they are run at the appropriate time
# the scripts MUST return a null on stdio to indicate success. Any output on stdio is considered
# an error message and the backup is halted immediately with the error being emailed to the
# account defined in the cron file.
# see additional information with some pre-written scripts in the examples directory of the docs folder
$configuration{'INITIALIZATION_SCRIPT'} = '';     # optional script to execute immediately after configuration file read
$configuration{'CLEANUP_SCRIPT'} = '';      # optional script to clean up when backup done

$configuration{'EXCLUDE_FILE'} = '/etc/rsync.exclude';        # location of file containing file patterns to be excluded
$configuration{'RSYNC'} = '';                   # full path to rsync executable
$configuration{'GZIP'} = '';
$configuration{'MPACK'} = '';

$configuration{'COMPRESSED_FILE_EXTENSION'} = 'gz'; # extension for the compressed file (gz for gzip, zip for zip)

$configuration{'OPTIONS'} = ();             # List of command line flags to be passed to rsync
$configuration{'CONTROL'} = {};             # options flags and conditions for using them. See notes above
$configuration{'MAILER_SCRIPT'} = '';       # option used if a mailer script is used
$configuration{'MAIL_FROM'} = '';           # name of sender for e-mail
$configuration{'MAIL_SERVER'} = '';         # name of mail server to use
$configuration{'TEMP_FILE'}  = '/tmp/rsbackup.tmp';               # name of some temp file that can be overwritten at will
$configuration{'PREPARE_COMMAND'} = '';
$configuration{'CLEANUP_COMMAND'} = '';


my $script = join( '', <> );


foreach my $key ( keys %configuration ) {
   $script =~ s/\$$key/\$configuration{'$key'}/g;
}

print $script;

1;
