#!/bin/sh

# Alter source-tree to install scc 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/index.html 

# SCC-release:	1.9.28
# file-version:	$Revision: 1.14 $

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

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

find . -type f					|
sed	-e '/relocate/d'	\
	-e '/openbsd-gen-scc/d'	\
	-e '/scc-logo.png/d'			|
while read file
do
	sed	-e "s@/var/opt/scc@${SCC_DATA}@g"	\
		-e "s@/etc/opt/scc@${SCC_CONF}@g"	\
		-e "s@/opt/scc@${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		|
while read file
do
	rel_conf="$(echo ${SCC_CONF} | sed -e 's/^.//')"
	rel_bin="$(echo ${SCC_BIN} | sed -e 's/^.//')"
	sed	-e "s@ etc/opt/scc@ ${rel_conf}@g"	\
		-e "s@/etc/opt/scc@${SCC_CONF}@g"	\
		-e "s@ opt/scc@ ${rel_bin}@g"		\
		-e "s@/opt/scc@${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/* ./${SCC_BIN}
rm -rf opt/scc

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

mkdir -p ./${SCC_CONF}
mv etc/opt/scc/* ./${SCC_CONF}
rm -rf etc/opt/scc

exit 0
