| 1 |
#!/usr/bin/perl |
| 2 |
use warnings; |
| 3 |
use strict; |
| 4 |
|
| 5 |
use Sys::Hostname; |
| 6 |
use File::Spec; |
| 7 |
|
| 8 |
my $host = hostname(); |
| 9 |
my $default_webapp_dir = |
| 10 |
$host =~ /habitatoc/ |
| 11 |
? '/var/www/diberri/cgi-bin/html2wiki' |
| 12 |
: $host =~ /Schonlein/ |
| 13 |
? '/Users/diberri/Sites/cgi-bin/html2wiki' |
| 14 |
: ''; |
| 15 |
|
| 16 |
my $webapp_dir = prompt( 'Path to web application:', $default_webapp_dir ); |
| 17 |
die "no path specified" unless $webapp_dir; |
| 18 |
|
| 19 |
doit( "mkdir -p $webapp_dir" ) if ! -d $webapp_dir; |
| 20 |
doit( "cp -R cgi/* $webapp_dir" ); |
| 21 |
|
| 22 |
my $index_cgi = File::Spec->catfile( $webapp_dir, 'index.cgi' ); |
| 23 |
my $template_path = File::Spec->catdir( $webapp_dir, 'templates/' ); |
| 24 |
doit( "sed -ie 's#__PATH_TO_TEMPLATES__#$template_path#' $index_cgi" ); |
| 25 |
|
| 26 |
if( $host =~ /habitatoc/ ) { |
| 27 |
my $main_html = File::Spec->catfile( $template_path, 'main.html' ); |
| 28 |
doit( "sed -ie 's#FIXME_TMPL_INCLUDE#TMPL_INCLUDE#' $main_html" ); |
| 29 |
} |
| 30 |
|
| 31 |
sub doit { |
| 32 |
my $cmd = shift; |
| 33 |
print $cmd, "\n"; |
| 34 |
system $cmd; |
| 35 |
} |
| 36 |
|
| 37 |
sub prompt { |
| 38 |
my( $prompt, $default ) = @_; |
| 39 |
$default ||= ''; |
| 40 |
|
| 41 |
printf( '%s [%s]: ', $prompt, $default ); |
| 42 |
chomp( my $input = <STDIN> ); |
| 43 |
$input =~ s/^\s+//; |
| 44 |
$input =~ s/\s+$//; |
| 45 |
|
| 46 |
return $input || $default || ''; |
| 47 |
} |