Initial revision
[bse.git] / localinst.perl
CommitLineData
5a2cc1bd
TC
1#!/usr/bin/perl -w
2use strict;
3
4my $dist = shift or die "Usage: $0 distdir";
5
6my $instbase = shift || "/home/httpd/bsetest";
7
8my $mysql = "/usr/local/mysql/bin/mysql";
9
10if (-e "$instbase/cgi-bin/modules/Constants.pm"
11 && !-e "$instbase/Constants.pm") {
12 system "cp $instbase/cgi-bin/modules/Constants.pm $instbase/Constants.pm"
13}
14my $gotconf;
15eval {
16 require $instbase."/Constants.pm";
17 $Constants::BASEDIR . $Constants::URLBASE . $Constants::SECURLBASE;
18 ++$gotconf;
19};
20
21system("rm -rf $instbase/cgi-bin")
22 and die "Cannot remove cgi-bin";
23system "rm -rf $instbase/data"
24 and die "Cannot remove data";
25system "rm -rf $instbase/htdocs"
26 and die "Cannot remove htdocs";
27
28system "cp -rf $dist/site/cgi-bin $instbase"
29 and die "Cannot copy cgi-bin";
30
31system "cp -rf $dist/site/htdocs $instbase"
32 and die "Cannot copy htdocs";
33system "cp -rf $dist/site/templates $instbase"
34 and die "Cannot copy templates";
35system "cp -rf $dist/site/data $instbase"
36 and die "Cannot copy data";
37system "cp -rf $dist/site/util $instbase";
38
39if ($gotconf) {
40 print "Updating conf\n";
41 # try to update Constants.pm
42 open CON, "< $instbase/cgi-bin/modules/Constants.pm"
43 or die "Cannot open Constants.pm";
44 my $con = do { local $/; <CON> };
45 close CON;
46
47 $con =~ s/(^\$DB = ')[^']*/$1$Constants::DB/m;
48 $con =~ s/(^\$UN = ')[^']*/$1$Constants::UN/m;
49 $con =~ s/(^\$PW = ')[^']*/$1$Constants::PW/m;
50 $con =~ s/(^\$BASEDIR = ')[^']+/$1$Constants::BASEDIR/m;
51 $con =~ s/(^\$URLBASE = ["'])[^'"]+/$1$Constants::URLBASE/m;
52 $con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1$Constants::SECURLBASE/m;
53 open CON, "> $instbase/cgi-bin/modules/Constants.pm"
54 or die "Cannot open Constants.pm for write: $!";
55 print CON $con;
56 close CON;
57
58 # build the database
59 system "$mysql -u$Constants::UN -p$Constants::PW $Constants::DB <$dist/schema/bse.sql"
60 and die "Cannot initialize database";
61 system "cd $instbase/util ; perl initial.pl"
62 and die "Cannot load database";
63}