various fixes, test code changes
[bse.git] / localinst.perl
CommitLineData
5a2cc1bd
TC
1#!/usr/bin/perl -w
2use strict;
ecabd3cb
TC
3#use File::Tree;
4use File::Copy;
5a2cc1bd 5
4bfb1a2b
TC
6my $dist = shift or die "Usage: $0 distdir [leavedb]";
7my $leavedb = shift or 0;
5a2cc1bd
TC
8my $instbase = shift || "/home/httpd/bsetest";
9
10my $mysql = "/usr/local/mysql/bin/mysql";
11
12if (-e "$instbase/cgi-bin/modules/Constants.pm"
13 && !-e "$instbase/Constants.pm") {
14 system "cp $instbase/cgi-bin/modules/Constants.pm $instbase/Constants.pm"
15}
16my $gotconf;
17eval {
18 require $instbase."/Constants.pm";
19 $Constants::BASEDIR . $Constants::URLBASE . $Constants::SECURLBASE;
20 ++$gotconf;
21};
22
23system("rm -rf $instbase/cgi-bin")
24 and die "Cannot remove cgi-bin";
25system "rm -rf $instbase/data"
26 and die "Cannot remove data";
ecabd3cb 27system "rm -f $instbase/htdocs/{*.html,a/*.html,shop/*.html,images/*.jpg}"
5a2cc1bd
TC
28 and die "Cannot remove htdocs";
29
30system "cp -rf $dist/site/cgi-bin $instbase"
31 and die "Cannot copy cgi-bin";
edc5d096 32unlink "$instbase/cgi-bin/bse.cfg";
5a2cc1bd
TC
33
34system "cp -rf $dist/site/htdocs $instbase"
35 and die "Cannot copy htdocs";
36system "cp -rf $dist/site/templates $instbase"
37 and die "Cannot copy templates";
38system "cp -rf $dist/site/data $instbase"
39 and die "Cannot copy data";
40system "cp -rf $dist/site/util $instbase";
41
42if ($gotconf) {
43 print "Updating conf\n";
44 # try to update Constants.pm
45 open CON, "< $instbase/cgi-bin/modules/Constants.pm"
46 or die "Cannot open Constants.pm";
47 my $con = do { local $/; <CON> };
48 close CON;
49
ecabd3cb
TC
50 if (defined $Constants::DB && !defined $Constants::DSN) {
51 $Constants::DSN = 'dbi:mysql:'.$Constants::DB;
52 $Constants::DBCLASS = "BSE::DB::Mysql";
53 $Constants::SESSION_CLASS = "Apache::Session::MySQL";
54 }
55 $con =~ s/(^\$DSN = ')[^']*/$1$Constants::DSN/m;
56 $con =~ s/(^\$DBCLASS = ')[^']*/$1$Constants::DBCLASS/m;
5a2cc1bd
TC
57 $con =~ s/(^\$UN = ')[^']*/$1$Constants::UN/m;
58 $con =~ s/(^\$PW = ')[^']*/$1$Constants::PW/m;
59 $con =~ s/(^\$BASEDIR = ')[^']+/$1$Constants::BASEDIR/m;
60 $con =~ s/(^\$URLBASE = ["'])[^'"]+/$1$Constants::URLBASE/m;
61 $con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1$Constants::SECURLBASE/m;
ecabd3cb 62 $con =~ s/(^\$SESSION_CLASS = ["'])[^'"]+/$1$Constants::SESSION_CLASS/m;
5a2cc1bd
TC
63 open CON, "> $instbase/cgi-bin/modules/Constants.pm"
64 or die "Cannot open Constants.pm for write: $!";
65 print CON $con;
66 close CON;
67
68 # build the database
4bfb1a2b 69 unless ($leavedb) {
ecabd3cb
TC
70 if ($Constants::DSN =~ /:mysql:(?:database=)?(\w+)/) {
71 my $db = $1;
72 system "$mysql -u$Constants::UN -p$Constants::PW $db <$dist/schema/bse.sql"
73 and die "Cannot initialize database";
74 system "cd $instbase/util ; perl initial.pl"
75 and die "Cannot load database";
76 }
77 else {
78 print "WARNING: cannot install to $Constants::DSN database\n";
79 }
4bfb1a2b 80 }
5a2cc1bd 81}
ecabd3cb 82