forked from schuetzm/imscp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imscp-autoinstall
executable file
·341 lines (257 loc) · 10.2 KB
/
imscp-autoinstall
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/perl
# i-MSCP - internet Multi Server Control Panel
# Copyright 2010-2013 by internet Multi Server Control Panel
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# @category i-MSCP
# @copyright 2010-2013 by i-MSCP | http://i-mscp.net
# @author Daniel Andreca <[email protected]>
# @author Laurent Declercq <[email protected]>
# @link http://i-mscp.net i-MSCP Home Site
# @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin", "$FindBin::Bin/engine/PerlLib", "$FindBin::Bin/engine/PerlVendor";
umask(022);
# Turn off localisation features to force any command output to be in english
$ENV{'LC_MESSAGES'} = 'C';
use iMSCP::Debug;
use iMSCP::Requirements;
use iMSCP::Dialog;
use iMSCP::LsbRelease;
use iMSCP::HooksManager;
use iMSCP::Stepper;
use iMSCP::Dir;
use iMSCP::File;
use iMSCP::Getopt;
use iMSCP::Boot;
use autoinstaller::Common;
newDebug('imscp-build.log');
# Entering in silent mode
silent(1);
# Load config
loadConfig() and fatal('Unable to load main configuration file');
# Ensure that this script is run by root user
iMSCP::Requirements->new()->user();
# Initialize the buildonly option
$main::buildonly = 0;
# Initialize the skippackages option
$main::skippackages = 0;
# Add autoinstaller specific command line options
iMSCP::Getopt->parse(
qq{Usage: perl imscp-autoinstall [options]
-b, --build-only Process only build step.
-s, --skip-packages Do not install/update distro packages.},
'build-only|b' => \$main::buildonly,
'skip-packages|s' => \$main::skippackages
);
verbose(iMSCP::Getopt->debug || $main::imscpConfig{'DEBUG'} || 0);
# Getting the reconfigure option value
$main::reconfigure = iMSCP::Getopt->reconfigure;
# Global variable that holds questions
%main::questions = () if ! %main::questions;
# Handle the preseed option
my $preseedFile = iMSCP::Getopt->preseed;
if($preseedFile) {
require $preseedFile;
# Values from preseed file always override those already set.
# The preseed option is not compatible with the reconfigure option.
$main::reconfigure = 'none';
undef $preseedFile;
}
# Handle the hook-file option
my $hookFile = iMSCP::Getopt->hookFile;
if($hookFile) {
require $hookFile;
undef $hookFile;
}
# Handle the noprompt option
$main::noprompt = iMSCP::Getopt->noprompt;
debugRegisterCallBack(
sub {
if($?) { # We exit with status 5 from iMSCP::Dialog::Dialog in noninteractive mode
if($? == 5) {
if(iMSCP::Getopt->preseed) {
print STDERR output ('Noninteractive mode: Missing or bad entry found in your preseed file.', 'fatal');
} else {
print STDERR output("Noninteractive mode: Missing or bad entry found in configuration file.", 'fatal');
}
}
} else {
if(!$main::buildonly) {
print STDOUT output("i-MSCP $main::imscpConfig{'Version'} has been successfully installed/updated.", 'ok');
} else {
print STDOUT output("i-MSCP $main::imscpConfig{'Version'} has been successfully built.", 'ok');
}
exit 0;
}
}
) if $main::noprompt;
if ($main::noprompt) {
if(!$main::buildonly) {
print STDOUT output("Installation in progress... Please wait.");
} else {
print STDOUT output("Build in progress... Please wait.")
}
}
if($main::skippackages && ! iMSCP::Getopt->preseed) {
unless(
$main::imscpConfig{'HTTPD_SERVER'} && $main::imscpConfig{'PO_SERVER'} &&
$main::imscpConfig{'MTA_SERVER'} && $main::imscpConfig{'FTPD_SERVER'} &&
$main::imscpConfig{'NAMED_SERVER'} && $main::imscpConfig{'SQL_SERVER'}
) {
$main::noprompt = 0;
$main::skippackages = 0;
}
}
iMSCP::HooksManager->getInstance()->trigger('beforeInstallPreRequiredPackages') and exit 1 if ! $main::skippackages;
installPreRequiredPackages() and exit 1 if ! $main::skippackages;
iMSCP::HooksManager->getInstance()->trigger('afterInstallPreRequiredPackages') if ! $main::skippackages;
if(! $main::buildonly && ! $main::noprompt && $main::reconfigure eq 'none') {
$ENV{'DIALOGOPTS'} = "--ok-label Ok --yes-label Yes --no-label No --cancel-label Back";
# Display the i-MSCP README file
my $file = iMSCP::File->new('filename' => $FindBin::Bin . '/README');
my $content = $file->get() or fatal("Unable to find the $FindBin::Bin/README file.");
iMSCP::Dialog->factory()->msgbox("\n$content");
# Check distribution compatibility
checkDistribution() and exit 0;
iMSCP::Dialog->factory()->set('cancel-label', 'Abort');
my $rs;
($rs, $main::buildonly) = iMSCP::Dialog->factory()->radiolist(<<EOF, ['install', 'build'], 'install');
\\Z4\\Zb\\ZuInstaller Options\\Zn
Please, choose an option:
\\Z4Install:\\Zn Choose this option if you want install or update i-MSCP.
\\Z4Build:\\Zn Choose this option if you want install i-MSCP manually or if you
want migrate from ispCP (>= 1.0.7).
EOF
exit if $rs == 1 || $rs == 255; # (CANCEL, ESC)
$main::buildonly = $main::buildonly eq 'build' ? 1 : 0;
}
## Build steps
my $distribution = iMSCP::LsbRelease->getInstance()->getId(1);
# Process build steps
my @steps = (
[\&preBuild, 'Processing preBuild tasks'],
[\&uninstallPackages, "Uninstalling $distribution packages not longer needed by i-MSCP"],
[\&installPackages, "Installing all $distribution packages for i-MSCP"],
[\&testRequirements, 'Testing i-MSCP requirements'],
[\&processDistroLayoutFile, "Processing $distribution layout file"],
[\&processDistroInstallFiles, "Processing $distribution install files"],
[\&buildImscpDaemon, 'Building i-MSCP daemon'],
[\&installEngine, 'Installing engine files in temporary directory'],
[\&installGui, 'Installing GUI files in temporary directory'],
[\&savePersistentData, 'Saving persistent data from previous installation if any'],
[\&postBuild, 'Processing postBuild tasks']
);
# Remove the uninstall/install packages steps in case the --skippackages option is set to true
splice(@steps, 1, 2,) if $main::skippackages;
iMSCP::HooksManager->getInstance()->trigger('beforeBuildSteps', \@steps) and exit 1;
my $rs = 0;
my $step = 1;
my $nbSteps = scalar @steps;
for (@steps) {
$rs = step($_->[0], $_->[1], $nbSteps, $step);
exit $rs if $rs;
$step++;
}
iMSCP::HooksManager->getInstance()->trigger('afterBuildSteps') and exit 1;
iMSCP::Dialog->factory()->endGauge() if iMSCP::Dialog->factory()->hasGauge();
my @warnings = getMessageByType('warn');
my @errors = getMessageByType('error');
if (@errors > 0 || @warnings > 0) {
my $msg = "\n\\Z" . (@errors > 0 ? 1 : 3 ) . "Build step finished but with " .
(@errors > 0 ? 'errors' : 'warnings') . ":\\Zn\n";
$msg .= "\nWARNINGS:\n" . join("\n", @warnings) . "\n" if @warnings > 0;
$msg .= "\nERRORS:\n" . join("\n", @errors) . "\n" if @errors > 0;
iMSCP::Dialog->factory()->set('defaultno', '');
iMSCP::Dialog->factory()->yesno("$msg\nDo you want continue?") and exit 1;
iMSCP::Dialog->factory()->set('defaultno', undef);
}
unless($main::buildonly) {
endDebug();
newDebug('imscp-setup.log');
# Try to acquire backend lock but do not wait for it
if(! iMSCP::Boot->getInstance()->lock(undef, 1)) {
iMSCP::Dialog->factory()->msgbox(<<EOF);
A backend process is currently running (eg. daily backup). The setup will switch back to the build mode.
To complete the update, you must wait until the end of the process and follow the instructions as shown in the following dialog.
EOF
goto BUILDONLY;
}
## Setup steps
require "$FindBin::Bin/engine/setup/imscp-setup-methods.pl";
@steps = (
[\&doImscpBackup, 'Backup existing i-MSCP installation if any'],
[\&installTmp, 'Installing i-MSCP files on file system'],
[\&setupBoot, 'Setup bootstrapping'],
[\&setupRegisterHooks, 'Registering servers/addons setup hooks'],
[\&setupDialog, 'Processing i-MSCP setup dialog if any'],
[\&setupTasks, 'Processing i-MSCP setup tasks'],
[\&removeTmp, 'Removing temporary files'],
);
iMSCP::HooksManager->getInstance()->trigger('beforeInstall', \@steps) and exit 1;
$step = 1;
$nbSteps = scalar @steps;
for (@steps) {
$rs = step($_->[0], $_->[1], $nbSteps, $step);
exit $rs if $rs;
$step++;
}
iMSCP::Dialog->factory()->endGauge() if iMSCP::Dialog->factory()->hasGauge();
iMSCP::HooksManager->getInstance()->trigger('afterInstall') and exit 1;
iMSCP::Dialog->factory()->msgbox(<<EOF);
\\Z1Congratulations\\Zn
i-MSCP $main::imscpConfig{'Version'} has been successfully installed/updated.
Please go to $main::imscpConfig{'BASE_SERVER_VHOST_PREFIX'}$main::imscpConfig{'BASE_SERVER_VHOST'} and log in with your administrator account.
Thanks for using i-MSCP.
EOF
} else {
BUILDONLY:
my $msg = <<EOF;
\\Z4\\ZuBuild Step Successful\\Zn
Please run the following commands from your console:
EOF
if ($main::buildonly && (-f '/etc/ispcp/ispcp.conf' || -f '/usr/local/etc/ispcp/ispcp.conf')) {
$msg .= <<EOF
# cp -fR /tmp/imscp/* /
# cd $main::imscpConfig{'ROOT_DIR'}/engine/setup
# perl imscp-migrate-from-ispcp
# perl imscp-setup
EOF
} else {
$msg .= <<EOF;
# rm -fR $main::imscpConfig{'ROOT_DIR'}/{daemon,engine,gui}
# cp -fR $main::{'INST_PREF'}/imscp/* /
# rm -fR $main::{'INST_PREF'}/imscp
# perl $main::imscpConfig{'ROOT_DIR'}/engine/setup/imscp-setup --debug
EOF
}
$msg .= <<EOF;
If you get no error, all went good; if you get one, look at http://forum.i-mscp.net to solve the problem.
Thank you for using i-MSCP.
EOF
iMSCP::Dialog->factory()->msgbox($msg);
endDebug();
}
END
{
my $exitCode = $?;
my $logdir = $main::imscpConfig{'LOG_DIR'} || '/tmp';
iMSCP::Dir->new('dirname' => $logdir)->make() unless -d $logdir;
$? = $exitCode;
}
exit 0;