#!/usr/bin/perl
#
#	Install Files and substitute Variables
#	This is Version 1.0
#       Copyright (c) 1996  Elmar Ludwig - Universitaet Osnabrueck

if (($destdir = pop @ARGV) eq '' || ($mode = shift) eq '')
{
    print STDERR "Usage: $0 mode [src] ... destdir\n";
    exit 1;
}

while (($src = shift) && open(SRC, $src))
{
    $dest = $src =~ m%.*/([^/]+)/*$% ? "$destdir/$1" : "$destdir/$src";

    if (open(DEST, ">$dest"))
    {
	while (<SRC>)
	{
	    while (s/@@(\w+)@@/$ENV{$1}/) {}
	    print DEST $_;
	}

	close DEST;
	chmod oct($mode), $dest;
    }
    else
    {
	print STDERR "$0: Cannot create $dest\n";
    }
}
