File: webapp-install

package info (click to toggle)
libhtml-wikiconverter-perl 0.68-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: perl: 1,186; makefile: 2
file content (47 lines) | stat: -rwxr-xr-x 1,164 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use warnings;
use strict;

use Sys::Hostname;
use File::Spec;

my $host = hostname();
my $default_webapp_dir =
  $host =~ /habitatoc/
    ? '/var/www/diberri/cgi-bin/html2wiki'
    : $host =~ /Schonlein/
        ? '/Users/diberri/Sites/cgi-bin/html2wiki'
        : '';

my $webapp_dir = prompt( 'Path to web application:', $default_webapp_dir );
die "no path specified" unless $webapp_dir;

doit( "mkdir -p $webapp_dir" ) if ! -d $webapp_dir;
doit( "cp -R cgi/* $webapp_dir" );

my $index_cgi = File::Spec->catfile( $webapp_dir, 'index.cgi' );
my $template_path = File::Spec->catdir( $webapp_dir, 'templates/' );
doit( "sed -ie 's#__PATH_TO_TEMPLATES__#$template_path#' $index_cgi" );

if( $host =~ /habitatoc/ ) {
  my $main_html = File::Spec->catfile( $template_path, 'main.html' );
  doit( "sed -ie 's#FIXME_TMPL_INCLUDE#TMPL_INCLUDE#' $main_html" );
}

sub doit {
  my $cmd = shift;
  print $cmd, "\n";
  system $cmd;
}

sub prompt {
  my( $prompt, $default ) = @_;
  $default ||= '';

  printf( '%s [%s]: ', $prompt, $default );
  chomp( my $input = <STDIN> );
  $input =~ s/^\s+//;
  $input =~ s/\s+$//;

  return $input || $default || '';
}