7 require ExtUtils::Manifest;
9 my $dist = shift or die "Usage: $0 distdir [leavedb]";
10 my $leavedb = shift or 0;
11 my $instbase = shift || BSE::Test::base_dir() || die "No base_dir";
13 my $mysql = BSE::Test::mysql_name;
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"
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";
24 #system "rm -f $instbase/htdocs/{*.html,a/*.html,shop/*.html,images/*.jpg}"
25 # and die "Cannot remove htdocs";
27 -d "$instbase/cgi-bin" or mkdir "$instbase/cgi-bin"
28 or die "Cannot create $instbase/cgi-bin: $!";
29 system "cp -rf $dist/site/cgi-bin/* $instbase/cgi-bin"
30 and die "Cannot copy cgi-bin";
32 my $perl = BSE::Test::test_perl();
33 if ($perl ne '/usr/bin/perl') {
34 my $manifest = ExtUtils::Manifest::maniread();
36 for my $file (keys %$manifest) {
37 (my $work = $file) =~ s!^site!!;
38 my $full = $instbase . $work;
39 open my $script, "<", $full
42 my $first = <$script>;
43 if ($first =~ s/^#!\S*perl\S*/#!$perl/) {
46 open my $out_script, ">", $full or die "Cannot create $full: $!";
48 print $out_script $first, @all;
54 system "cp -rf $dist/site/htdocs/* $instbase/htdocs"
55 and die "Cannot copy htdocs";
56 system "cp -rf $dist/site/templates/* $instbase/templates"
57 and die "Cannot copy templates";
58 system "cp -rf $dist/site/data $instbase"
59 and die "Cannot copy data";
60 system "cp -rf $dist/site/util/ $instbase";
62 print "Updating conf\n";
63 # try to update Constants.pm
64 open CON, "< $instbase/cgi-bin/modules/Constants.pm"
65 or die "Cannot open Constants.pm";
66 my $con = do { local $/; <CON> };
69 my $dbuser = BSE::Test::test_dbuser();
70 my $dbpass = BSE::Test::test_dbpass();
72 #$con =~ s/(^\$DSN = ')[^']*/$1 . BSE::Test::test_dsn()/me;
73 #$con =~ s/(^\$DBCLASS = ')[^']*/$1 . BSE::Test::test_dbclass()/me;
74 #$con =~ s/(^\$UN = ')[^']*/$1$dbuser/m;
75 #$con =~ s/(^\$PW = ')[^']*/$1$dbpass/m;
76 #$con =~ s/(^\$BASEDIR = ')[^']+/$1 . BSE::Test::base_dir/me;
77 #$con =~ s/(^\$URLBASE = ["'])[^'"]+/$1 . BSE::Test::base_url/me;
78 #$con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1 . BSE::Test::test_securl/me;
79 $con =~ s/(^\$SESSION_CLASS = [\"\'])[^\'\"]+/$1 . BSE::Test::test_sessionclass()/me;
80 open CON, "> $instbase/cgi-bin/modules/Constants.pm"
81 or die "Cannot open Constants.pm for write: $!";
86 # rebuild the config file
87 # first load values from the test.cfg file
88 my $conffile = BSE::Test::test_conffile();
90 $conf{site}{url} = BSE::Test::base_url();
91 $conf{site}{secureurl} = BSE::Test::base_securl();
92 $conf{paths}{siteroot} = $instbase;
93 #my $uploads = "$instbase/uploads";
94 #$conf{paths}{downloads} = $uploads;
95 #my $templates = "$instbase/templates";
96 #$conf{paths}{templates} = $templates;
97 #$conf{paths}{public_html} = "$instbase/htdocs";
98 open TESTCONF, "< $conffile"
99 or die "Could not open config file $conffile: $!";
102 /^\s*(\w[^=]*\w)\.([\w-]+)\s*=\s*(.*)\s*$/ or next;
103 $conf{lc $1}{$2} = $3;
106 #$uploads = $conf{paths}{downloads};
107 # create installation config
109 $conf{db}{class} = BSE::Test::test_dbclass();
110 $conf{db}{dsn} = BSE::Test::test_dsn();
111 $conf{db}{user} = $dbuser;
112 $conf{db}{password} = $dbpass;
114 open CFG, "> $instbase/cgi-bin/bse-install.cfg"
115 or die "Cannot create $instbase/cgi-bin/bse-install.cfg: $!";
117 print CFG "; DO NOT EDIT - created during installation\n";
118 for my $section_name (keys %conf) {
119 print CFG "[$section_name]\n";
120 my $section = $conf{$section_name};
121 for my $key (keys %$section) {
122 print CFG "$key=$section->{$key}\n";
130 # or mkdir $uploads, 0777
131 # or die "Cannot find or create upload directory: $!";
135 my $dsn = BSE::Test::test_dsn();
136 if ($dsn =~ /:mysql:(?:database=)?(\w+)/) {
140 system "$mysql -u$dbuser -p$dbpass $db <$dist/schema/bse.sql"
141 and die "Cannot initialize database";
142 system "cd $instbase/util ; $perl initial.pl"
143 and die "Cannot load database";
146 # always load stored procedures
147 system qq($mysql "-u$dbuser" "-p$dbpass" "$db" <$dist/schema/bse_sp.sql)
148 and die "Error loading stored procedures\n";
151 print "WARNING: cannot install to $dsn database\n";