/
clone.pl
executable file
·190 lines (148 loc) · 5.07 KB
/
clone.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/perl -w
=head1 NAME
clone.pl - installation script to gather clone information
=head1 VERSION
$LastChangedRevision$
=head1 DATE
$Id$
=head1 DESCRIPTION
This script is called by "make clone" to prepare for building a cloned
distribution. Gathers configuration information from the user and
install.db if available. Outputs to the various .db files used by
later stages of the install.
The following configuration variables can be set using environment
variables: C<$BRICOLAGE_ROOT>, C<$CONFIG_DIR>, C<$CLONE_NAME>,
e.g.:
make CLONE_NAME=unattended_archive clone
If the environment variable C<$INSTALL_VERBOSITY> is set to "QUIET"
this script won't ask for confirmations so that unattended
execution is possible:
make INSTALL_VERBOSITY=QUIET clone
=head1 AUTHOR
Sam Tregar <stregar@about-inc.com>
=head1 SEE ALSO
L<Bric::Admin>
=cut
use strict;
use FindBin;
use lib "$FindBin::Bin/lib";
use Bric::Inst qw(:all);
use File::Spec::Functions qw(:ALL);
use Data::Dumper;
use POSIX 'strftime';
# determine if clone should run in quiet mode
my $QUIET = $ENV{INSTALL_VERBOSITY} and $ENV{INSTALL_VERBOSITY} eq 'QUIET';
# make sure we're root, otherwise uninformative errors result
unless ($> == 0) {
print "This process must (usually) be run as root.\n";
exit 1 unless ask_yesno("Continue as non-root user?", 1, $QUIET);
}
# setup default root
our %CLONE = ( BRICOLAGE_ROOT => $ENV{BRICOLAGE_ROOT} ||
'/usr/local/bricolage' );
our ($INSTALL, $VERSION);
# determine version being installed
use lib './lib';
eval find_version();
print "\n\n==> Setting-up Bricolage $VERSION Clone Process <==\n\n";
get_bricolage_root();
read_install_db();
check_version();
confirm_paths();
get_clone_name();
output_dbs();
print "\n\n==> Finished Setting-up Bricolage Clone Process <==\n\n";
# find_version
sub find_version {
my $bric = catfile $FindBin::Bin, updir, 'lib', 'Bric.pm';
open BRIC, $bric or die "Cannot open $bric: $!\n";
my $inpod;
while (<BRIC>) {
$inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
next if $inpod || /^\s*#/;
return $_ if m/([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
}
return;
}
# get clone name
sub get_clone_name {
print "\n";
$CLONE{NAME} = $ENV{CLONE_NAME} || strftime '%Y%m%d%H%M%S', localtime;
ask_confirm("What would you like to name your clone ".
"(used to name the archive)? ", \$CLONE{NAME},
$QUIET);
}
# find the bricolage to update
sub get_bricolage_root {
ask_confirm("Bricolage Root Directory to Clone?",
\$CLONE{BRICOLAGE_ROOT},
$QUIET);
$CLONE{CONFIG_DIR} = $ENV{CONFIG_DIR} ||
catdir $CLONE{BRICOLAGE_ROOT}, 'conf';
ask_confirm("Bricolage Config Directory",
\$CLONE{CONFIG_DIR},
$QUIET);
# verify that we have a Bricolage install here
hard_fail("No Bricolage installation found in $CLONE{BRICOLAGE_ROOT}.\n")
unless -e catfile($CLONE{CONFIG_DIR}, "bricolage.conf");
# verify that this Bricolage was installed with "make install"
hard_fail("The Bricolage Installation found in $CLONE{BRICOLAGE_ROOT}\n",
"was installed manually and cannot be cloned.")
unless -e catfile($CLONE{CONFIG_DIR}, "install.db");
}
# read the install.db file from the chosen bricolage root
sub read_install_db {
my $install_file = catfile($CLONE{CONFIG_DIR}, "install.db");
if (-e $install_file) {
# read it in if it exists
do $install_file or die "Failed to read $install_file : $!";
}
}
# check that the version numbers match
sub check_version {
my @todo;
# make sure we're not cloning a different version
if ($INSTALL->{VERSION} ne $VERSION) {
print <<END;
The installed version ("$INSTALL->{VERSION}") is not same as this
version ("$VERSION")! "make clone" is only designed to work with
like versions.
END
exit 1 unless ask_yesno("Continue with clone?", 0, $QUIET);
@todo = ($VERSION);
}
}
# confirm paths listed in install.db
sub confirm_paths {
print "\nPlease confirm the Bricolage clone source directories.\n\n";
ask_confirm("Bricolage Perl Module Directory",
\$INSTALL->{CONFIG}{MODULE_DIR},
$QUIET);
ask_confirm("Bricolage Executable Directory",
\$INSTALL->{CONFIG}{BIN_DIR},
$QUIET);
ask_confirm("Mason Component Directory",
\$INSTALL->{CONFIG}{MASON_COMP_ROOT},
$QUIET);
ask_confirm("Mason Data Directory",
\$INSTALL->{CONFIG}{MASON_DATA_ROOT},
$QUIET);
}
# output .db files used by installation steps
sub output_dbs {
# fake up the .dbs from %INSTALL
my %dbs = (
DB => "database.db",
CONFIG => "config.db",
AP => "apache.db",
);
while ( my ($key, $file) = each %dbs) {
open(FILE, ">$file") or die "Unable to open $file : $!";
print FILE Data::Dumper->Dump([$INSTALL->{$key}], [$key]);
close(FILE);
}
# output upgrade.db
open(FILE, ">clone.db") or die "Unable to open clone.db : $!";
print FILE Data::Dumper->Dump([\%CLONE], ["CLONE"]);
close(FILE);
}