]> git.imager.perl.org - bse.git/blame - localinst.perl
remove sensitive information from data_only for siteuser objects
[bse.git] / localinst.perl
CommitLineData
5a2cc1bd
TC
1#!/usr/bin/perl -w
2use strict;
ecabd3cb
TC
3#use File::Tree;
4use File::Copy;
5bbf7309
TC
5use lib 'lib';
6use BSE::Install qw(util_dir cgi_dir public_html_dir templates_dir data_dir mysql_name);
7#use BSE::Test ();
8use ExtUtils::Manifest qw(maniread);
9use File::Copy qw(copy);
10use File::Spec;
11use File::Path qw(make_path);
12use Getopt::Long;
13
14my $verbose;
15GetOptions("v|verbose" => \$verbose);
5a2cc1bd 16
4bfb1a2b
TC
17my $dist = shift or die "Usage: $0 distdir [leavedb]";
18my $leavedb = shift or 0;
5a2cc1bd 19
5bbf7309 20my $mysql = mysql_name();
5a2cc1bd 21
5bbf7309 22my $cfg = BSE::Install::cfg();
5a2cc1bd 23
5bbf7309 24my $manifest = maniread();
5a2cc1bd 25
4157f345
TC
26# fake BSE::Modules
27$manifest->{"site/cgi-bin/modules/BSE/Modules.pm"} = "";
28
5bbf7309
TC
29install_files("site/htdocs/", public_html_dir());
30install_files("site/templates/", templates_dir());
31install_files("site/cgi-bin", cgi_dir());
32install_files("site/util/", util_dir());
33install_files("site/data/", data_dir());
5a2cc1bd 34
5bbf7309 35my $perl = BSE::Install::perl();
f0543260
TC
36if ($perl ne '/usr/bin/perl') {
37 my $manifest = ExtUtils::Manifest::maniread();
38
6271b583 39 for my $file (keys %$manifest) {
5bbf7309
TC
40 (my $work = $file) =~ s!^site/!!;
41 $work =~ s(^(cgi-bin|util)/)()
42 or next;
43 my $base = $work eq "util" ? util_dir() : cgi_dir();
44 my $full = File::Spec->catfile($base, $work);
6271b583
TC
45 open my $script, "<", $full
46 or next;
47 binmode $script;
48 my $first = <$script>;
49 if ($first =~ s/^#!\S*perl\S*/#!$perl/) {
50 my @all = <$script>;
51 close $script;
52 open my $out_script, ">", $full or die "Cannot create $full: $!";
53 binmode $out_script;
54 print $out_script $first, @all;
55 close $out_script;
56 }
f0543260
TC
57 }
58}
59
3bc94f98 60print "Updating conf\n";
d2473dc2 61
5bbf7309
TC
62my $conf_src = BSE::Install::conffile();
63my $conf_dest = File::Spec->catfile(cgi_dir(), "bse-install.cfg");
64copy($conf_src, $conf_dest)
65 or die "Cannot copy $conf_src to $conf_dest: $!\n";
3bc94f98 66
771ab646
TC
67#-d $uploads
68# or mkdir $uploads, 0777
69# or die "Cannot find or create upload directory: $!";
9168c88c 70
5bbf7309
TC
71my $dbuser = BSE::Install::db_user();
72my $dbpass = BSE::Install::db_password();
9168c88c 73
3bc94f98 74# build the database
5bbf7309 75my $dsn = BSE::Install::db_dsn();
f1fb6e3b
TC
76if ($dsn =~ /:mysql:(?:database=)?(\w+)/) {
77 my $db = $1;
78
79 unless ($leavedb) {
3bc94f98
TC
80 system "$mysql -u$dbuser -p$dbpass $db <$dist/schema/bse.sql"
81 and die "Cannot initialize database";
5bbf7309 82 system "cd ".util_dir." ; $perl initial.pl"
3bc94f98
TC
83 and die "Cannot load database";
84 }
f1fb6e3b
TC
85
86 # always load stored procedures
87 system qq($mysql "-u$dbuser" "-p$dbpass" "$db" <$dist/schema/bse_sp.sql)
88 and die "Error loading stored procedures\n";
89}
90else {
91 print "WARNING: cannot install to $dsn database\n";
5a2cc1bd 92}
3bc94f98 93
5bbf7309
TC
94sub install_files {
95 my ($prefix, $destbase) = @_;
96
97 print "Install $prefix to $destbase\n";
98 for my $file (sort grep /^\Q$prefix/, keys %$manifest) {
99 (my $rel = $file) =~ s/^\Q$prefix//;
100 my $src = File::Spec->catfile($dist, $file);
101 my $dest = File::Spec->catfile($destbase, $rel);
102 my ($destvol, $destdir) = File::Spec->splitpath($dest);
103 my $destpath = File::Spec->catdir($destvol, $destdir);
104 unless (-e $destpath) {
105 make_path($destpath); # croak on error
106 }
107 elsif (!-d $destpath) {
108 die "$destpath isn't a directory!\n";
109 }
110 print " Copy $rel to $dest\n" if $verbose;
111 copy($src, $dest)
112 or die "Cannot copy $src to $dest: $!\n";
113 }
114}