#!/bin/sh

# convert-config-links - convert the likely-to-be-changed config-files
#	from symlinks to copies

if [ $# -gt 0 ] ; then
	if [ "$1" = '-h' ] ; then
		echo >&2 "usage: $0 [-h]"
		exit 0
	fi
fi

cd /etc/remstats/config
if [ ! -d ../config-base ] ; then
	echo >&2 "$0: can't find the config-base to copy from"
	exit 1
fi

for file in alerts alert-destination-map general html links tools ; do
	if [ ! -e $file ] ; then
		echo >&2 "$0: missing $file. Is /etc/remstats/config really your configuration directory?"
		exit 2
	fi
	if [ ! -f ../config-base/$file ] ; then
		echo >&2 "$0: missing ../config-base/$file.  Is /etc/remstats/config../config-base really your config-base?"
		exit 4
	fi
	mv $file $file.bak
	cp ../config-base/$file $file || (echo "$0: error copying $file" && exit 3)
	echo "... $file"
done
