/
conf_install.pl
76 lines (62 loc) · 2.08 KB
/
conf_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
#!/usr/bin/perl
use strict;
use File::Copy;
use Bio::Root::IO;
use File::Path 'mkpath';
use Cwd;
use FindBin '$Bin';
use constant DEBUG => 0;
my $origdir = cwd;
my $homedir = "$Bin/..";
chdir $homedir or die "couldn't cd to $homedir: $!\n";
foreach (@ARGV) {
$_ =~ s/^\"(.*)\"$/$1/;
}
# get configuration stuff from command line
my %options = map {split /=/} @ARGV;
my $dir = "$options{CONF}/gbrowse.conf";
#start the installation...
print "Installing sample configuration files...\n";
if (! (-e $dir)) {
mkpath($dir,0,0777) or die "unable to make $dir directory\n";
}
installdir( source => "conf" , target => "$dir" , recurse => 1 );
sub installdir {
my(%arg) = @_;
my $source = $arg{source};
my $target = $arg{target};
my $recurse = $arg{recurse};
if (! (-e $target)) {
mkdir($target,0777) or die "unable to mkdir $target: $!";
}
opendir(my $SOURCE, $source) or die "unable to opendir('$source'): $!";
while(my $file = readdir($SOURCE)){
next if $file =~ /\.PMS$/;
my $sourcefile = Bio::Root::IO->catfile($source,$file);
my $targetfile = Bio::Root::IO->catfile($target,$file);
if(-f $sourcefile){
chmod(0666,$targetfile);
# copy($sourcefile,$targetfile) or die "unable to write to $targetfile: $!";
copy_with_substitutions($sourcefile,$targetfile) or die "unable to write to $targetfile: $!";
print STDERR " file $sourcefile -> $targetfile\n" if DEBUG;
chmod(0444,$targetfile);
} elsif(-d $sourcefile && $recurse){
next if $file eq '.' or $file eq '..' or $file eq 'CVS';
print STDERR "directory $sourcefile -> $targetfile\n" if DEBUG;
installdir(source => $sourcefile, target => $targetfile, recurse => 1);
}
}
closedir($SOURCE);
}
sub copy_with_substitutions {
my ($localfile,$install_file) = @_;
open (IN,$localfile) or die "Couldn't open $localfile: $!";
open (OUT,">$install_file") or die "Couldn't open $install_file for writing: $!";
while (<IN>) {
s/\$(\w+)/$options{$1}||"\$$1"/eg;
print OUT;
}
close OUT;
close IN;
}
chdir $origdir or die "couldn't cd to $origdir: $!\n";