]> git.imager.perl.org - bse.git/blame - localinst.perl
0.12_10 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;
9168c88c 54$con =~ s/(^\$SESSION_CLASS = [\"\'])[^\'\"]+/$1 . BSE::Test::test_sessionclass()/me;
3bc94f98
TC
55open CON, "> $instbase/cgi-bin/modules/Constants.pm"
56 or die "Cannot open Constants.pm for write: $!";
57print CON $con;
58close CON;
5a2cc1bd 59
9168c88c
TC
60# rebuild the config file
61# first load values from the test.cfg file
62my $conffile = BSE::Test::test_conffile();
63my %conf;
64$conf{site}{name} = "Test Server";
65$conf{site}{url} = BSE::Test::base_url();
66$conf{site}{secureurl} = BSE::Test::base_securl();
67my $uploads = "$instbase/uploads";
68$conf{paths}{downloads} = $uploads;
69open TESTCONF, "< $conffile"
70 or die "Could not open config file $conffile: $!";
71while (<TESTCONF>) {
72 chomp;
73 /^\s*(\w+)\.(\w+)\s*=\s*(.*\S)\s*$/ or next;
74 $conf{lc $1}{lc $2} = $3;
75}
76
77$uploads = $conf{paths}{downloads};
3bc94f98
TC
78# fix bse.cfg
79open CFG, "< $instbase/cgi-bin/bse.cfg"
80 or die "Cannot open $instbase/cgi-bin/bse.cfg: $!";
9168c88c
TC
81my $section = "";
82my @cfg;
83while (<CFG>) {
84 chomp;
85 if (/^\[(.*)\]\s*$/) {
86 my $newsect = lc $1;
87 if ($conf{$section} && keys %{$conf{$section}}) {
88 for my $key (sort keys %{$conf{$section}}) {
89 push @cfg, "$key=$conf{$section}{$key}";
90 }
91 delete $conf{$section};
92 }
93 $section = $newsect;
94 }
95 elsif (/^\s*(\w+)\s*=\s*.*$/ && exists $conf{$section}{lc $1}) {
96 my $key = lc $1;
97 print "found $section.$key\n";
98 $_ = "$key=$conf{$section}{$key}";
99 delete $conf{$section}{$key};
100 }
101 push @cfg, $_;
102}
103if ($conf{$section} && keys %{$conf{$section}}) {
104 for my $key (sort keys %{$conf{$section}}) {
105 push @cfg, "$key=$conf{$section}{$key}";
106 }
107 delete $conf{$section};
108}
109for my $sect (keys %conf) {
110 if ($conf{$sect} && keys %{$conf{$sect}}) {
111 push @cfg, "[$sect]";
112 for my $key (sort keys %{$conf{$sect}}) {
113 push @cfg, "$key=$conf{$section}{$key}";
114 }
115 push @cfg, "";
116 }
117}
3bc94f98 118close CFG;
9168c88c 119
3bc94f98
TC
120open CFG, "> $instbase/cgi-bin/bse.cfg"
121 or die "Cannot create $instbase/cgi-bin/bse.cfg: $!";
9168c88c
TC
122for my $line (@cfg) {
123 print CFG $line, "\n";
124}
3bc94f98
TC
125close CFG;
126
9168c88c
TC
127-d $uploads
128 or mkdir $uploads, 0777
129 or die "Cannot find or create upload directory: $!";
130
131
3bc94f98
TC
132# build the database
133unless ($leavedb) {
134 my $dsn = BSE::Test::test_dsn();
135 if ($dsn =~ /:mysql:(?:database=)?(\w+)/) {
136 my $db = $1;
137 system "$mysql -u$dbuser -p$dbpass $db <$dist/schema/bse.sql"
138 and die "Cannot initialize database";
139 system "cd $instbase/util ; perl initial.pl"
140 and die "Cannot load database";
141 }
142 else {
143 print "WARNING: cannot install to $dsn database\n";
4bfb1a2b 144 }
5a2cc1bd 145}
3bc94f98 146
ecabd3cb 147