1#!/usr/bin/perl -w # -*- perl -*- 2# 3# tt2inst (bin/tt2inst) 4# 5# This script installs the optional Template Toolkit components from the 6# 'docs', 'examples', 'images' and 'templates' distribution directories 7# into the corresponding installation directories. The root directory 8# for the installation should be specified as an argument to the 9# script, e.g. 'tt2inst /usr/local/tt2' 10# 11 12use strict; 13use Getopt::Std; 14use File::Find; 15use File::Path; 16use File::Copy; 17use File::Spec; 18use Cwd; 19 20my $PROGRAM = 'tt2inst'; 21my @INSTDIRS = qw( docs examples images templates ); 22 23my $args = { }; 24getopts('vh', $args); 25usage() if $args->{ h }; 26 27my $verbose = $args->{ v }; 28my $tt2inst = shift || usage(); 29my $tt2dist = getcwd; 30 31die <<EOF unless -d "$tt2dist/$INSTDIRS[0]"; 32This script should be run from the Template Toolkit distribution directory. 33EOF 34 35#------------------------------------------------------------------------ 36# install files 37#------------------------------------------------------------------------ 38 39print STDERR <<EOF if $verbose; 40Installing optional components into $tt2inst 41EOF 42 43foreach my $dir (@INSTDIRS) { 44 print STDERR " + $dir\n" 45 if $verbose; 46 47 find(\&install_file, $dir); 48} 49 50sub install_file { 51 my $f = $File::Find::name; 52 return if $f =~ /\bCVS\b/ || m[^docs/html/(?!README)]; 53 if (-d) { 54 my $dir = File::Spec->catfile($tt2inst, $f); 55 mkpath($dir) unless -d $dir; 56 return; 57 } 58 my $dest = File::Spec->catfile($tt2inst, $f); 59 copy($_, $dest) || die "$dest: $!\n"; 60} 61 62 63#------------------------------------------------------------------------ 64# usage 65#------------------------------------------------------------------------ 66 67sub usage { 68 print STDERR <<EOF; 69$PROGRAM: installation script for optional Template Toolkit components. 70 71usage: $PROGRAM [ -v | -h ] /path/to/installation/root 72 73 -v verbose mode 74 -h this help 75EOF 76 exit(); 77} 78 79