consistently load the managed images directory from the config file
[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 ();
f0543260 7require ExtUtils::Manifest;
5a2cc1bd 8
4bfb1a2b
TC
9my $dist = shift or die "Usage: $0 distdir [leavedb]";
10my $leavedb = shift or 0;
3bc94f98 11my $instbase = shift || BSE::Test::base_dir() || die "No base_dir";
5a2cc1bd 12
3bc94f98 13my $mysql = BSE::Test::mysql_name;
5a2cc1bd 14
3bc94f98
TC
15# if (-e "$instbase/cgi-bin/modules/Constants.pm"
16# && !-e "$instbase/Constants.pm") {
17# system "cp $instbase/cgi-bin/modules/Constants.pm $instbase/Constants.pm"
18# }
5a2cc1bd 19
ce07f199
TC
20#system("rm -rf $instbase/cgi-bin")
21# and die "Cannot remove cgi-bin";
22#system "rm -rf $instbase/data"
23# and die "Cannot remove data";
ab2cd916
TC
24#system "rm -f $instbase/htdocs/{*.html,a/*.html,shop/*.html,images/*.jpg}"
25# and die "Cannot remove htdocs";
5a2cc1bd 26
ce07f199
TC
27-d "$instbase/cgi-bin" or mkdir "$instbase/cgi-bin"
28 or die "Cannot create $instbase/cgi-bin: $!";
29system "cp -rf $dist/site/cgi-bin/* $instbase/cgi-bin"
5a2cc1bd
TC
30 and die "Cannot copy cgi-bin";
31
f0543260
TC
32my $perl = BSE::Test::test_perl();
33if ($perl ne '/usr/bin/perl') {
34 my $manifest = ExtUtils::Manifest::maniread();
35
36 for my $file (grep /\.pl$/, keys %$manifest) {
37 (my $work = $file) =~ s!^site!!;
38 next unless $work =~ /cgi-bin/;
39 my $full = $instbase . $work;
40 open SCRIPT, "< $full" or die "Cannot open $full: $!";
41 binmode SCRIPT;
42 my @all = <SCRIPT>;
43 close SCRIPT;
44 $all[0] =~ s/^#!\S*perl\S*/#!$perl/;
45 open SCRIPT, "> $full" or die "Cannot create $full: $!";
46 binmode SCRIPT;
47 print SCRIPT @all;
48 close SCRIPT;
49 }
50}
51
d6f4c5c2 52system "cp -rf $dist/site/htdocs/* $instbase/htdocs"
5a2cc1bd 53 and die "Cannot copy htdocs";
d6f4c5c2 54system "cp -rf $dist/site/templates/* $instbase/templates"
5a2cc1bd
TC
55 and die "Cannot copy templates";
56system "cp -rf $dist/site/data $instbase"
57 and die "Cannot copy data";
d6f4c5c2 58system "cp -rf $dist/site/util/ $instbase";
5a2cc1bd 59
3bc94f98
TC
60print "Updating conf\n";
61# try to update Constants.pm
62open CON, "< $instbase/cgi-bin/modules/Constants.pm"
63 or die "Cannot open Constants.pm";
64my $con = do { local $/; <CON> };
65close CON;
5a2cc1bd 66
3bc94f98
TC
67my $dbuser = BSE::Test::test_dbuser();
68my $dbpass = BSE::Test::test_dbpass();
69
d2473dc2
TC
70#$con =~ s/(^\$DSN = ')[^']*/$1 . BSE::Test::test_dsn()/me;
71#$con =~ s/(^\$DBCLASS = ')[^']*/$1 . BSE::Test::test_dbclass()/me;
72#$con =~ s/(^\$UN = ')[^']*/$1$dbuser/m;
73#$con =~ s/(^\$PW = ')[^']*/$1$dbpass/m;
771ab646 74#$con =~ s/(^\$BASEDIR = ')[^']+/$1 . BSE::Test::base_dir/me;
3bc94f98
TC
75#$con =~ s/(^\$URLBASE = ["'])[^'"]+/$1 . BSE::Test::base_url/me;
76#$con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1 . BSE::Test::test_securl/me;
9168c88c 77$con =~ s/(^\$SESSION_CLASS = [\"\'])[^\'\"]+/$1 . BSE::Test::test_sessionclass()/me;
3bc94f98
TC
78open CON, "> $instbase/cgi-bin/modules/Constants.pm"
79 or die "Cannot open Constants.pm for write: $!";
80print CON $con;
81close CON;
5a2cc1bd 82
d2473dc2 83
9168c88c
TC
84# rebuild the config file
85# first load values from the test.cfg file
86my $conffile = BSE::Test::test_conffile();
87my %conf;
9168c88c
TC
88$conf{site}{url} = BSE::Test::base_url();
89$conf{site}{secureurl} = BSE::Test::base_securl();
771ab646
TC
90$conf{paths}{siteroot} = $instbase;
91#my $uploads = "$instbase/uploads";
92#$conf{paths}{downloads} = $uploads;
93#my $templates = "$instbase/templates";
94#$conf{paths}{templates} = $templates;
95#$conf{paths}{public_html} = "$instbase/htdocs";
9168c88c
TC
96open TESTCONF, "< $conffile"
97 or die "Could not open config file $conffile: $!";
98while (<TESTCONF>) {
99 chomp;
ebc63b18 100 /^\s*(\w[^=]*\w)\.([\w-]+)\s*=\s*(.*)\s*$/ or next;
9168c88c
TC
101 $conf{lc $1}{lc $2} = $3;
102}
103
771ab646 104#$uploads = $conf{paths}{downloads};
d2473dc2
TC
105# create installation config
106
107$conf{db}{class} = BSE::Test::test_dbclass();
108$conf{db}{dsn} = BSE::Test::test_dsn();
109$conf{db}{user} = $dbuser;
110$conf{db}{password} = $dbpass;
111
112open CFG, "> $instbase/cgi-bin/bse-install.cfg"
113 or die "Cannot create $instbase/cgi-bin/bse-install.cfg: $!";
114
115print CFG "; DO NOT EDIT - created during installation\n";
116for my $section_name (keys %conf) {
117 print CFG "[$section_name]\n";
118 my $section = $conf{$section_name};
119 for my $key (keys %$section) {
120 print CFG "$key=$section->{$key}\n";
9168c88c 121 }
d2473dc2 122 print CFG "\n";
9168c88c 123}
9168c88c 124
3bc94f98
TC
125close CFG;
126
771ab646
TC
127#-d $uploads
128# or mkdir $uploads, 0777
129# or die "Cannot find or create upload directory: $!";
9168c88c
TC
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