0.12_09 commit
[bse.git] / localinst.perl
CommitLineData
5a2cc1bd
TC
1#!/usr/bin/perl -w
2use strict;
ecabd3cb
TC
3#use File::Tree;
4use File::Copy;
3bc94f98
TC
5use lib 't';
6use BSE::Test ();
5a2cc1bd 7
4bfb1a2b
TC
8my $dist = shift or die "Usage: $0 distdir [leavedb]";
9my $leavedb = shift or 0;
3bc94f98 10my $instbase = shift || BSE::Test::base_dir() || die "No base_dir";
5a2cc1bd 11
3bc94f98 12my $mysql = BSE::Test::mysql_name;
5a2cc1bd 13
3bc94f98
TC
14# if (-e "$instbase/cgi-bin/modules/Constants.pm"
15# && !-e "$instbase/Constants.pm") {
16# system "cp $instbase/cgi-bin/modules/Constants.pm $instbase/Constants.pm"
17# }
5a2cc1bd
TC
18
19system("rm -rf $instbase/cgi-bin")
20 and die "Cannot remove cgi-bin";
21system "rm -rf $instbase/data"
22 and die "Cannot remove data";
ecabd3cb 23system "rm -f $instbase/htdocs/{*.html,a/*.html,shop/*.html,images/*.jpg}"
5a2cc1bd
TC
24 and die "Cannot remove htdocs";
25
26system "cp -rf $dist/site/cgi-bin $instbase"
27 and die "Cannot copy cgi-bin";
28
29system "cp -rf $dist/site/htdocs $instbase"
30 and die "Cannot copy htdocs";
31system "cp -rf $dist/site/templates $instbase"
32 and die "Cannot copy templates";
33system "cp -rf $dist/site/data $instbase"
34 and die "Cannot copy data";
35system "cp -rf $dist/site/util $instbase";
36
3bc94f98
TC
37print "Updating conf\n";
38# try to update Constants.pm
39open CON, "< $instbase/cgi-bin/modules/Constants.pm"
40 or die "Cannot open Constants.pm";
41my $con = do { local $/; <CON> };
42close CON;
5a2cc1bd 43
3bc94f98
TC
44my $dbuser = BSE::Test::test_dbuser();
45my $dbpass = BSE::Test::test_dbpass();
46
47$con =~ s/(^\$DSN = ')[^']*/$1 . BSE::Test::test_dsn()/me;
48$con =~ s/(^\$DBCLASS = ')[^']*/$1 . BSE::Test::test_dbclass()/me;
49$con =~ s/(^\$UN = ')[^']*/$1$dbuser/m;
50$con =~ s/(^\$PW = ')[^']*/$1$dbpass/m;
51$con =~ s/(^\$BASEDIR = ')[^']+/$1 . BSE::Test::base_dir/me;
52#$con =~ s/(^\$URLBASE = ["'])[^'"]+/$1 . BSE::Test::base_url/me;
53#$con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1 . BSE::Test::test_securl/me;
54$con =~ s/(^\$SESSION_CLASS = ["'])[^'"]+/$1 . BSE::Test::test_sessionclass()/me;
55open CON, "> $instbase/cgi-bin/modules/Constants.pm"
56 or die "Cannot open Constants.pm for write: $!";
57print CON $con;
58close CON;
5a2cc1bd 59
3bc94f98
TC
60# fix bse.cfg
61open CFG, "< $instbase/cgi-bin/bse.cfg"
62 or die "Cannot open $instbase/cgi-bin/bse.cfg: $!";
63my $cfg = do { local $/; <CFG> };
64close CFG;
65$cfg =~ s/^name\s*=.*/name=Test Server/m;
66$cfg =~ s/^url\s*=.*/"url=" . BSE::Test::base_url()/me;
6e3d2da5 67$cfg =~ s/^secureurl\s*=.*/"secureurl=" . BSE::Test::base_securl()/me;
3bc94f98
TC
68my $uploads = "$instbase/uploads";
69$cfg =~ s!^downloads\s*=.*!downloads=$uploads!m;
70-d $uploads
71 or mkdir $uploads, 0777
72 or die "Cannot find or create upload directory: $!";
73open CFG, "> $instbase/cgi-bin/bse.cfg"
74 or die "Cannot create $instbase/cgi-bin/bse.cfg: $!";
75print CFG $cfg;
76close CFG;
77
78# build the database
79unless ($leavedb) {
80 my $dsn = BSE::Test::test_dsn();
81 if ($dsn =~ /:mysql:(?:database=)?(\w+)/) {
82 my $db = $1;
83 system "$mysql -u$dbuser -p$dbpass $db <$dist/schema/bse.sql"
84 and die "Cannot initialize database";
85 system "cd $instbase/util ; perl initial.pl"
86 and die "Cannot load database";
87 }
88 else {
89 print "WARNING: cannot install to $dsn database\n";
4bfb1a2b 90 }
5a2cc1bd 91}
3bc94f98 92
ecabd3cb 93