#!/bin/bash

TEMP=`getopt -o fh --long force,help -n 'test.sh' -- "$@"`
eval set -- "$TEMP"

FILENAME=$0
function printHelp(){
	echo "$FILENAME copies default conf files to active confs"
	echo "Default is to only copy if file is not present"
	echo ""
	echo "Usage: $FILENAME [<option>...]"
	echo "Options:"
	echo "  -f, --force        Overwrite existing conf files."
	echo "  -h, --help         show this help message"
	echo ""
}

FORCE="FALSE"

while true ; do
    case "$1" in
	-f|--force)
	    FORCE="TRUE" ; shift ;;
    -h|--help)
	    printHelp
        exit 0
        shift ;;
    --) shift ; break ;;
    *) echo "Internal error!" ; exit 1 ;;
    esac
done

if [ "$FORCE" == "TRUE" ]
then
	echo "Loading all default config files, overwriting existing."
	CPCMD="cp"
else
	echo "Loading only missing default config files."
	#Site controllers lack the -n option, so we have to do this
    # to avoid overwriting existing files
	CPCMD="false | cp -i"
fi


#System config files
eval "$CPCMD /home/admin/conf/default/fwserv.conf /home/admin/conf/"
eval "$CPCMD /home/admin/conf/default/mail.conf /home/admin/conf/"
eval "$CPCMD /home/admin/conf/default/snmpd.conf /home/admin/conf/"
eval "$CPCMD /home/admin/conf/default/pbtvars.conf /home/admin/conf/"

#DNP3 config files
eval "$CPCMD /home/admin/dnp3/default/dnp3Data.d /home/admin/dnp3/"
eval "$CPCMD /home/admin/dnp3/default/dnp3map.csv /home/admin/dnp3/"

#Firewall (iptables) config files
eval "$CPCMD /home/admin/conf/default/firewall.rules /home/admin/conf/"

echo ""
