-
Notifications
You must be signed in to change notification settings - Fork 37
/
gbrowse_ppm_install.pl
executable file
·130 lines (112 loc) · 3.66 KB
/
gbrowse_ppm_install.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -w
# After PPM downloads and installs the contents of blib, this script
# prompts the user for the location of htdocs, conf, and cgi-bin
# and installs them.
use strict;
use Config;
use LWP::Simple;
use PPM::Archive;
use File::Basename 'dirname';
use ExtUtils::MakeMaker 'prompt'; # love it!
use constant SUPPORT_FILES => 'gbrowse_ppm_support_files-2.00pre1.tar.gz';
use constant PPM_REPOSITORY => 'http://www.gmod.org/ggb/ppm';
my $startperl = $Config{startperl} ne '#!perl'
? $Config{startperl}
: "#!$Config{perlpath}";
# fetch the support files
print "Fetching GBrowse support files...\n";
my $file = SUPPORT_FILES;
my $url = join '/',PPM_REPOSITORY,SUPPORT_FILES;
my $rc = mirror($url,$file);
if (is_error($rc)) {
die "Sorry, couldn't fetch $file from ",PPM_REPOSITORY,". HTTP code: $rc.\n";
}
# unpack them
print "Unpacking support files...\n";
my $a = PPM::Archive->new($file);
my @files = $a->list_files;
foreach (@files) {
$a->extract($_);
}
undef $a;
die "Unexpected error. There should be an install_util directory here, but there isn't!\n" unless -d "install_util";
eval <<'END'
use lib './install_util';
use GBrowseGuessDirectories;
END
;
# now we get to prompt the user endlessly for the pathnames
print STDERR "\n** Installing GBrowse CGI and config files **\n";
print STDERR "** Please indicate the location of the following Web Server directories:\n";
my $prefix = $^O =~ /mswin/i ? 'C:/Program Files/Apache Group/Apache2'
: '/usr/local/apache';
my $conf = prompt_for_directory('conf', GBrowseGuessDirectories->conf || "$prefix/conf");
$prefix = dirname($conf); # update
my $htdocs = prompt_for_directory('htdocs', GBrowseGuessDirectories->htdocs || "$prefix/htdocs");
my $cgibin = prompt_for_directory('cgi-bin',GBrowseGuessDirectories->cgibin || "$prefix/cgi-bin");
fixup($_,"$conf/gbrowse.conf") foreach grep {-T} @files;
my @args = (
"'APACHE=$prefix'",
"'CGIBIN=$cgibin'",
"'CONF=$conf'",
"'HTDOCS=$htdocs'"
);
for my $inst ("cgi_install.pl","htdocs_install.pl","conf_install.pl") {
system("perl","install_util/$inst",@args); #==0
# or die "The install script, $inst, failed. I don't know why\n";;
}
print STDERR "\n** GBrowse installation complete.\n";
print STDERR "** Now go to http://your.server/gbrowse for further setup instructions.\n";
exit 0;
sub prompt_for_directory {
my ($prompt,$default) = @_;
my $dir;
while (!$dir) {
$dir = prompt("\t\"$prompt\" directory ([q]uit)",$default);
if ($dir eq 'q') {
print STDERR "ABORTED: your installation is NOT complete\n\n";
exit 0;
}
$dir = interpolate($dir);
if (!-d $dir) {
print STDERR "$dir doesn't exist. Please try again.\n";
redo;
} elsif (!-w $dir) {
print STDERR "warning: $dir isn't writable. Installation may fail.\n";
}
}
return $dir;
}
sub interpolate {
my $path = shift;
my ($to_expand,$homedir);
return $path unless $path =~ m!^~([^/]*)!;
eval {
if ($to_expand = $1) {
$homedir = (getpwnam($to_expand))[7];
} else {
$homedir = (getpwuid($<))[7];
}
return $path unless $homedir;
$path =~ s!^~[^/]*!$homedir!;
};
return $path;
}
# horrible -- fix line endings for proper architecture
sub fixup {
my $file = shift;
my $conf = shift;
return unless -f $file;
local $/ = "\012";
open F,$file or die "Can't open $file: $!";
open OUT,">$file.new" or die "Can't open $file.new: $!";
while (<F>) {
chomp;
s/^\#!.+/$startperl -w/;
s/^\$CONF_DIR\s*=\s*\'.+/\$CONF_DIR = '$conf';/;
print OUT $_,"\n";
}
close F;
close OUT;
rename "$file.new",$file;
}