#!/bin/sh

# Alter source-tree to install scc-srv in alternate directories.
# Copyright (C) 2001-2004 Open Challenge B.V.
# Copyright (C) 2004-2005 OpenEyeT Professional Services.
# Copyright (C) 2005-2009 QNH.
#
# This program 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, or (at your option)
# any later version.
#
# This program 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 this program; see the file COPYING.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Contact information: http://scc.qnh-infrastructure.nl

# SCC-release:	1.7.5
# file-version:	$Revision: 1.13 $

# Edit the following lines to install the software in other directories than the default.
# Tean call this script, followed by the appropriate generate-script.
# Note that this script will not work correctly when SCC_DATA contains the string: "/opt/scc-srv".
# The contents of both variables should end with the string: "scc-srv".
# Be sure to use absolute paths for the following variables.
SCC_DATA=""		# for example: /usr/pkg/share/scc-srv
SCC_BIN=""		# for example: /usr/pkg/scc-srv
export SCC_DATA SCC_BIN

if [ -z "${SCC_DATA}" -o -z "${SCC_BIN}" ]
then
	echo "customize ${0} to alter directory settings" >&2
	exit 2
fi

find . -type f					|
sed	-e '/relocate/d'		\
	-e '/openbsd-gen-scc-srv/d'	\
	-e '/scc-logo.png/d'			|
while read file
do
	sed	-e "s@/var/opt/scc-srv@${SCC_DATA}@g"	\
		-e "s@/opt/scc-srv@${SCC_BIN}@g"	\
			<${file}			\
			>${file}.tmp

	# Preserve the original permissions.
	chmod u+w ${file}
	cp ${file}.tmp ${file}
	chmod u-w ${file}
	rm -f ${file}.tmp
done

find . -type f -name openbsd-gen-scc-srv		|
while read file
do
	rel_data="$(echo ${SCC_DATA} | sed -e 's/^.//')"
	rel_bin="$(echo ${SCC_BIN} | sed -e 's/^.//')"
	sed	-e "s@ var/opt/scc-srv@ ${rel_data}@g"	\
		-e "s@/var/opt/scc-srv@${SCC_DATA}@g"	\
		-e "s@ opt/scc-srv@ ${rel_bin}@g"	\
		-e "s@/opt/scc-srv@${SCC_BIN}@g"	\
			<${file}			\
			>${file}.tmp

	# Preserve the original permissions.
	chmod u+w ${file}
	cp ${file}.tmp ${file}
	chmod u-w ${file}
	rm -f ${file}.tmp
done

cd software

mkdir -p ./${SCC_BIN}
mv opt/scc-srv/* ./${SCC_BIN}
rm -rf opt/scc-srv

mkdir -p ./${SCC_DATA}
mv var/opt/scc-srv/* ./${SCC_DATA}
rm -rf var/opt/scc-srv

exit 0
