forked from schuetzm/imscp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimscp-autoinstall
executable file
·309 lines (243 loc) · 9.68 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
#!/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
#####################################################################################
# Script description:
#
# This script is responsible to build the i-MSCP tree into a temporary folder from
# the upstream archive. This script can optionnaly installing all i-MSCP dependencies
# and launch the i-MSCP setup/update script. It attemp to detect the target
# distribution, process backup tasks and save the current GUI persistent data in update
# mode before doing any changes on the files system. In case the target distribution
# cannot be detected, the script exit with a specific error message.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin", "$FindBin::Bin/engine/PerlLib", "$FindBin::Bin/engine/PerlVendor";
umask(027);
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 autoinstaller::Common;
# Initialize the buildonly option
$main::buildonly = 0;
# Initialize the skippackages option
$main::skippackages = 0;
iMSCP::Getopt->parse(
qq{Usage: perl imscp-autoinstall [options]
-b, --buildonly Process only build step.
-s, --skippackages Do not install/update distro packages.},
'buildonly|b' => \$main::buildonly,
'skippackages|s' => \$main::skippackages
);
# Getting the reconfigure option value
$main::reconfigure = iMSCP::Getopt->reconfigure;
# Handle the preseed option
%main::preseed = ();
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;
# In noninteractive mode (nonprompt option), we bypass the default
# exit handler (as provided by the iMSCP::Debug package) to raise
# a specific error in case an answer is wrong. An answer can be a
# wrong entry from an i-MSCP conffile, or from a preseed file in
# case the preseed option is involved.
iMSCP::HooksManager->getInstance->register(
'beforeExit',
sub {
my $exitCode = shift;
if($$exitCode == 5) { # We exit with status 5 from iMSCP::Dialog::Dialog in noninteractive mode
$$exitCode = 1;
if(iMSCP::Getopt->preseed) {
fatal "Noninteractive mode: Missing or bad entry found in your preseed file."
} else {
fatal "Noninteractive mode: Missing or bad entry found in an i-MSCP configuration file."
}
} else {
my $clearScreen = shift;
$$clearScreen = 0; # Do not clear screen
}
0;
}
) if $main::noprompt;
print STDOUT "Installation in progress... Please wait.\n" if $main::noprompt;
newDebug('imscp-build.log');
# Ensure the script is run as root
iMSCP::Requirements->new()->user();
iMSCP::HooksManager->getInstance()->trigger('beforeInstallPreRequiredPackages') if ! $main::skippackages;
# Install pre-required package
installPreRequiredPackages() and exit 1 if ! $main::skippackages;
iMSCP::HooksManager->getInstance()->trigger('afterInstallPreRequiredPackages') if ! $main::skippackages;
# Entering in silent mode
silent(1);
if(! $main::buildonly && ! $main::noprompt) {
$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(
"
\\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).
",
['install', 'build'],
'install'
);
exit if $rs == 1 || $rs == 255; # (CANCEL, ESC)
$main::buildonly = $main::buildonly eq 'build' ? 1 : 0;
}
## Build steps
my $distribution = iMSCP::LsbRelease->new()->getId(1);
# Process build steps
my @steps = (
[\&loadConfig, 'Loading i-MSCP configuration'],
[\&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'],
[\&processConfFile, "Loading $distribution specific variables"],
[\&processSpecificConfFile, "Processing $distribution specific configuration files"],
[\&buildImscpDaemon, 'Building i-MSCP daemon'],
[\&installEngine, 'Installing engine files in temporary directory'],
[\&installGui, 'Installing GUI files in temporary directory'],
[\&installDistMaintainerScripts, "Installing $distribution maintainer scripts in temporary directory"],
[\&postBuild, 'Processing postBuild tasks']
);
# Remove the uninstall/install packages steps in case the --skippackages option is set to true
splice(@steps, 2, 2) if $main::skippackages;
iMSCP::HooksManager->getInstance()->trigger('beforeBuild', \@steps);
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('afterBuild');
iMSCP::Dialog->factory()->endGauge() if iMSCP::Dialog->factory()->needGauge();
my @warnings = getMessageByType('WARNING');
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);
}
if(! $main::buildonly) {
## Setup steps
require "$FindBin::Bin/engine/setup/imscp-setup-methods.pl";
@steps = (
[\&doImscpBackup, 'Backup existing i-MSCP installation if any'],
[\&saveGuiPersistentData, 'Saving GUI persistent data'],
[\&installTmp, 'Installing new 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'],
);
iMSCP::HooksManager->getInstance()->trigger('beforeAutoInstallSetup', \@steps);
$step = 1;
$nbSteps = scalar @steps;
for (@steps){
$rs = step($_->[0], $_->[1], $nbSteps, $step);
exit $rs if $rs;
$step++;
}
iMSCP::HooksManager->getInstance()->trigger('afterAutoInstallSetup');
iMSCP::Dialog->factory()->endGauge() if iMSCP::Dialog->factory()->needGauge();
iMSCP::Dialog->factory()->msgbox(
"
\\Z1Congratulations!!!\\Zn
i-MSCP '$main::imscpConfig{'Version'}' has been successfully installed/updated.
"
);
iMSCP::Dialog->factory()->infobox("\nRemoving temporary files...");
$rs = removeTmp();
exit $rs;
} else {
iMSCP::Dialog->factory()->msgbox(
"
\\Z4\\ZuBuild Step Successful\\Zn
To finish the i-MSCP install process, run the following commands from your console:
\\ZbI. If you want migrate from ispCP\\Zn
# cp -R /tmp/imscp/* /
# cd $main::imscpConfig{ROOT_DIR}/engine/setup
# perl imscp-migrate-from-ispcp
# perl imscp-setup
\\ZbII. If you want install or update iMSCP\\Zn
# rm -Rf $main::imscpConfig{GUI_ROOT_DIR}/data/sessions
# rm -Rf $main::imscpConfig{GUI_ROOT_DIR}/data/cache
# cp -Rfv $main::imscpConfig{GUI_ROOT_DIR}/data /tmp/imscp/var/www/imscp/gui
# cp -Rfv $main::imscpConfig{GUI_ROOT_DIR}/public/tools/webmail/data \\\\
/tmp/imscp/var/www/imscp/gui/public/tools/webmail
# cp -Rfv $main::imscpConfig{GUI_ROOT_DIR}/plugins /tmp/imscp/var/www/imscp/gui
# rm -Rf $main::imscpConfig{ROOT_DIR}/{daemon,engine,gui}
# cp -R /tmp/imscp/* /
# rm -R /tmp/imscp
# cd $main::imscpConfig{ROOT_DIR}/engine/setup
# perl imscp-setup
If you get no error, all went good; if you get one, look at http://forum.i-mscp.net to solve the problem.
Thanks for using i-MSCP.
"
);
}
0;
END
{
my $exitCode = $?;
my $logdir = $main::imscpConfig{'LOG_DIR'} || '/tmp';
iMSCP::Dir->new(dirname => $logdir)->make() unless -d $logdir;
$? = $exitCode;
}