#!/usr/bin/perl -w
#
# Installs templates to given directory.
#
use strict;
use File::Path;
use File::Basename;
use File::Copy;

my $homedir=$ARGV[0];
die "No homedir given!\n" unless $homedir && -x $homedir;
if($homedir =~ /\/devsite\b/)
 { print "Would not install templates to devsite installation (this is not an error).\n";
   exit(0);
 }
if(-l "$homedir/templates")
 { print "Would not install templates to sym-linked directory ($homedir/templates).\n";
   exit(0);
 }
open(F,'MANIFEST') || die "Cannot open MANIFEST: $!\n";
while(my $file=<F>)
{ chomp($file);
  next unless $file =~ /^templates\//;
  my $outfile=$homedir . '/' . $file;
  print "Copying $file to $outfile\n";
  mkpath([dirname($outfile)],0,0755);
  copy($file,$outfile) || die "Cannot copy $file to $outfile: $!\n";
}
