#!/bin/bash -e
#
# backuppc-config
#
# Automatic first-time configuration for Iztaci's
# default BackupPC installation.
#


BPC_CONFIG="/etc/BackupPC/config.pl"

if [[ $1 == "-i" ]]; then
   perl -I /usr/libexec/backuppc/lib /usr/libexec/backuppc/bin/configure.pl --config-only --config-path=/etc/BackupPC/config.pl
else
   echo ------------------------------------------------------------
   echo "        Starting BackupPC automatic configuration"
   echo ------------------------------------------------------------
   echo
   echo
   echo "We are using the configuration file at: $BPC_CONFIG"
   echo
   echo "We will set the following configuration variables:"
   echo
   echo "   ServerHost='$(hostname)'"
   echo
   echo "Making a backup of the original configuration file:"
   cp -v "$BPC_CONFIG" "${BPC_CONFIG}.bak-$(date +%s)"

   perl -I /usr/libexec/backuppc/lib /usr/libexec/backuppc/bin/configure.pl \
        --batch                                   \
        --config-only                             \
        --config-path=/etc/BackupPC/config.pl     \
        --config-override ServerHost=\'$(hostname)\'
fi

echo
echo ------------------------------------------------------------
echo "                Configuration complete"
echo ------------------------------------------------------------
echo
echo "If you ever want to reconfigure your BackupPC installation"
echo "you can do so by editing the file at $BPC_CONFIG"
echo "or by running:"
echo
echo "   $(basename $0) -i"
echo

exit 0
