#!/bin/sh
# Portable System Interface Copyright (c) 1997-1998 Tycho Softworks.
# $Id: instetc 1.1 Tue, 23 Jun 1998 11:38:33 -0400 dyfet $

opwd=`pwd`
cd `dirname $0`
cd ../..
if test -f config.cache ; then
	. config.cache
	BUILDROOT=CONFIG_ROOT
else
	BUILDROOT=''
fi

cd $opwd
etc='/etc'

if test ! -d "$etc" ; then
	etc=''
	if test -d /config ; then
		etc='/config'
	fi
fi

if test -z "$etc" ; then
	exit 0
fi

if test -d /var/spool ; then
	VAR_SPOOL=/var/spool
else
	VAR_SPOOL=/usr/spool
fi

if test -d /var/lock ; then
	VAR_LOCK='/var/lock'
else
	VAR_LOCK='/tmp'
fi

if test -d /var/log ; then
	VAR_LOG='/var/log'
else
	VAR_LOG=$VAR_SPOOL/log
fi

if test -d /var ; then
	VAR_LIB=/var
else
	VAR_LIB=/usr/lib
fi

if test -d /home ; then
	VAR_HOME=/home
else
	VAR_HOME=/usr
fi

sedlock="-e s/%VAR_LOCK%/$VAR_LOCK/"
sedspool="-e s/%VAR_SPOOL%/$VAR_SPOOL/"
sedlog="-e s/%VAR_LOG%/$VAR_LOG/"
sedlib="-e s/%VAR_LIB%/$VAR_LIB/"
sedhome="-e s/%VAR_HOME%/$VAR_HOME/"
sedcmd=$sedlock" "$sedspool" "$sedlog" "$sedlib" "$sedhome

install -d $BUILDROOT$etc
for file in $* ; do
	sed $sedcmd <$file >$BUILDROOT$etc
done
