Skip to content
Newer
Older
100755 79 lines (62 sloc) 1.91 KB
c8d76d4 @abw *** empty log message ***
authored
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
12 use strict;
13 use Getopt::Std;
14 use File::Find;
15 use File::Path;
16 use File::Copy;
f4df3b6 @abw approach v2.03
authored
17 use File::Spec;
c8d76d4 @abw *** empty log message ***
authored
18 use Cwd;
19
20 my $PROGRAM = 'tt2inst';
21 my @INSTDIRS = qw( docs examples images templates );
22
23 my $args = { };
24 getopts('vh', $args);
25 usage() if $args->{ h };
26
27 my $verbose = $args->{ v };
28 my $tt2inst = shift || usage();
29 my $tt2dist = getcwd;
30
31 die <<EOF unless -d "$tt2dist/$INSTDIRS[0]";
32 This script should be run from the Template Toolkit distribution directory.
33 EOF
34
35 #------------------------------------------------------------------------
36 # install files
37 #------------------------------------------------------------------------
38
39 print STDERR <<EOF if $verbose;
40 Installing optional components into $tt2inst
41 EOF
42
43 foreach my $dir (@INSTDIRS) {
44 print STDERR " + $dir\n"
45 if $verbose;
46
f4df3b6 @abw approach v2.03
authored
47 find(\&install_file, $dir);
c8d76d4 @abw *** empty log message ***
authored
48 }
49
50 sub install_file {
f4df3b6 @abw approach v2.03
authored
51 my $f = $File::Find::name;
52 return if $f =~ /\bCVS\b/ || m[^docs/html/(?!README)];
c8d76d4 @abw *** empty log message ***
authored
53 if (-d) {
f4df3b6 @abw approach v2.03
authored
54 my $dir = File::Spec->catfile($tt2inst, $f);
c8d76d4 @abw *** empty log message ***
authored
55 mkpath($dir) unless -d $dir;
56 return;
57 }
f4df3b6 @abw approach v2.03
authored
58 my $dest = File::Spec->catfile($tt2inst, $f);
59 copy($_, $dest) || die "$dest: $!\n";
c8d76d4 @abw *** empty log message ***
authored
60 }
61
62
63 #------------------------------------------------------------------------
64 # usage
65 #------------------------------------------------------------------------
66
67 sub usage {
68 print STDERR <<EOF;
69 $PROGRAM: installation script for optional Template Toolkit components.
70
71 usage: $PROGRAM [ -v | -h ] /path/to/installation/root
72
73 -v verbose mode
74 -h this help
75 EOF
76 exit();
77 }
78
Something went wrong with that request. Please try again.