]>
Commit | Line | Data |
---|---|---|
5a2cc1bd TC |
1 | #!/usr/bin/perl -w |
2 | use strict; | |
ecabd3cb TC |
3 | #use File::Tree; |
4 | use File::Copy; | |
5bbf7309 TC |
5 | use lib 'lib'; |
6 | use BSE::Install qw(util_dir cgi_dir public_html_dir templates_dir data_dir mysql_name); | |
7 | #use BSE::Test (); | |
8 | use ExtUtils::Manifest qw(maniread); | |
9 | use File::Copy qw(copy); | |
10 | use File::Spec; | |
11 | use File::Path qw(make_path); | |
12 | use Getopt::Long; | |
13 | ||
14 | my $verbose; | |
15 | GetOptions("v|verbose" => \$verbose); | |
5a2cc1bd | 16 | |
4bfb1a2b TC |
17 | my $dist = shift or die "Usage: $0 distdir [leavedb]"; |
18 | my $leavedb = shift or 0; | |
5a2cc1bd | 19 | |
5bbf7309 | 20 | my $mysql = mysql_name(); |
5a2cc1bd | 21 | |
5bbf7309 | 22 | my $cfg = BSE::Install::cfg(); |
5a2cc1bd | 23 | |
5bbf7309 | 24 | my $manifest = maniread(); |
5a2cc1bd | 25 | |
4157f345 TC |
26 | # fake BSE::Modules |
27 | $manifest->{"site/cgi-bin/modules/BSE/Modules.pm"} = ""; | |
28 | ||
5bbf7309 TC |
29 | install_files("site/htdocs/", public_html_dir()); |
30 | install_files("site/templates/", templates_dir()); | |
31 | install_files("site/cgi-bin", cgi_dir()); | |
32 | install_files("site/util/", util_dir()); | |
33 | install_files("site/data/", data_dir()); | |
5a2cc1bd | 34 | |
5bbf7309 | 35 | my $perl = BSE::Install::perl(); |
f0543260 TC |
36 | if ($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 | 60 | print "Updating conf\n"; |
d2473dc2 | 61 | |
5bbf7309 TC |
62 | my $conf_src = BSE::Install::conffile(); |
63 | my $conf_dest = File::Spec->catfile(cgi_dir(), "bse-install.cfg"); | |
64 | copy($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 |
71 | my $dbuser = BSE::Install::db_user(); |
72 | my $dbpass = BSE::Install::db_password(); | |
9168c88c | 73 | |
3bc94f98 | 74 | # build the database |
5bbf7309 | 75 | my $dsn = BSE::Install::db_dsn(); |
f1fb6e3b TC |
76 | if ($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 | } | |
90 | else { | |
91 | print "WARNING: cannot install to $dsn database\n"; | |
5a2cc1bd | 92 | } |
3bc94f98 | 93 | |
5bbf7309 TC |
94 | sub 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 | } |