implement password validation for admin users
[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
6271b583 36 for my $file (keys %$manifest) {
f0543260 37 (my $work = $file) =~ s!^site!!;
f0543260 38 my $full = $instbase . $work;
6271b583
TC
39 open my $script, "<", $full
40 or next;
41 binmode $script;
42 my $first = <$script>;
43 if ($first =~ s/^#!\S*perl\S*/#!$perl/) {
44 my @all = <$script>;
45 close $script;
46 open my $out_script, ">", $full or die "Cannot create $full: $!";
47 binmode $out_script;
48 print $out_script $first, @all;
49 close $out_script;
50 }
f0543260
TC
51 }
52}
53
d6f4c5c2 54system "cp -rf $dist/site/htdocs/* $instbase/htdocs"
5a2cc1bd 55 and die "Cannot copy htdocs";
d6f4c5c2 56system "cp -rf $dist/site/templates/* $instbase/templates"
5a2cc1bd
TC
57 and die "Cannot copy templates";
58system "cp -rf $dist/site/data $instbase"
59 and die "Cannot copy data";
d6f4c5c2 60system "cp -rf $dist/site/util/ $instbase";
5a2cc1bd 61
3bc94f98
TC
62print "Updating conf\n";
63# try to update Constants.pm
64open CON, "< $instbase/cgi-bin/modules/Constants.pm"
65 or die "Cannot open Constants.pm";
66my $con = do { local $/; <CON> };
67close CON;
5a2cc1bd 68
3bc94f98
TC
69my $dbuser = BSE::Test::test_dbuser();
70my $dbpass = BSE::Test::test_dbpass();
71
d2473dc2
TC
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;
771ab646 76#$con =~ s/(^\$BASEDIR = ')[^']+/$1 . BSE::Test::base_dir/me;
3bc94f98
TC
77#$con =~ s/(^\$URLBASE = ["'])[^'"]+/$1 . BSE::Test::base_url/me;
78#$con =~ s/(^\$SECURLBASE = ["'])[^'"]+/$1 . BSE::Test::test_securl/me;
9168c88c 79$con =~ s/(^\$SESSION_CLASS = [\"\'])[^\'\"]+/$1 . BSE::Test::test_sessionclass()/me;
3bc94f98
TC
80open CON, "> $instbase/cgi-bin/modules/Constants.pm"
81 or die "Cannot open Constants.pm for write: $!";
82print CON $con;
83close CON;
5a2cc1bd 84
d2473dc2 85
9168c88c
TC
86# rebuild the config file
87# first load values from the test.cfg file
88my $conffile = BSE::Test::test_conffile();
89my %conf;
9168c88c
TC
90$conf{site}{url} = BSE::Test::base_url();
91$conf{site}{secureurl} = BSE::Test::base_securl();
771ab646
TC
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";
9168c88c
TC
98open TESTCONF, "< $conffile"
99 or die "Could not open config file $conffile: $!";
100while (<TESTCONF>) {
101 chomp;
ebc63b18 102 /^\s*(\w[^=]*\w)\.([\w-]+)\s*=\s*(.*)\s*$/ or next;
7f8bd3f6 103 $conf{lc $1}{$2} = $3;
9168c88c
TC
104}
105
771ab646 106#$uploads = $conf{paths}{downloads};
d2473dc2
TC
107# create installation config
108
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;
113
114open CFG, "> $instbase/cgi-bin/bse-install.cfg"
115 or die "Cannot create $instbase/cgi-bin/bse-install.cfg: $!";
116
117print CFG "; DO NOT EDIT - created during installation\n";
118for 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";
9168c88c 123 }
d2473dc2 124 print CFG "\n";
9168c88c 125}
9168c88c 126
3bc94f98
TC
127close CFG;
128
771ab646
TC
129#-d $uploads
130# or mkdir $uploads, 0777
131# or die "Cannot find or create upload directory: $!";
9168c88c
TC
132
133
3bc94f98
TC
134# build the database
135unless ($leavedb) {
136 my $dsn = BSE::Test::test_dsn();
137 if ($dsn =~ /:mysql:(?:database=)?(\w+)/) {
138 my $db = $1;
139 system "$mysql -u$dbuser -p$dbpass $db <$dist/schema/bse.sql"
140 and die "Cannot initialize database";
6271b583 141 system "cd $instbase/util ; $perl initial.pl"
3bc94f98
TC
142 and die "Cannot load database";
143 }
144 else {
145 print "WARNING: cannot install to $dsn database\n";
4bfb1a2b 146 }
5a2cc1bd 147}
3bc94f98 148
ecabd3cb 149