-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathupgrade-licence.pl
executable file
·159 lines (140 loc) · 3.91 KB
/
upgrade-licence.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
#!/usr/local/bin/perl
=head1 upgrade-license.pl
Upgrade Virtualmin GPL system to Pro version
This program can be used to upgrade Virtualmin GPL system to Professional
version.
The serial C<--serial> and key C<--key> params must be set to an actual
valid license.
=cut
package virtual_server;
if (!$module_name) {
$main::no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*)\/[^\/]+$/) {
chdir($pwd = $1);
}
else {
chop($pwd = `pwd`);
}
$0 = "$pwd/upgrade-license.pl";
require './virtual-server-lib.pl';
$< == 0 || die "upgrade-license.pl must be run as root";
}
# Parse command-line args
&set_all_text_print();
@OLDARGV = @ARGV;
# Parse args
while(@ARGV > 0) {
local $a = shift(@ARGV);
if ($a eq "--serial") {
$serial = shift(@ARGV);
}
elsif ($a eq "--key") {
$key = shift(@ARGV);
}
elsif ($a eq "--multiline") {
$multiline = 1;
}
elsif ($a eq "--help") {
&usage();
}
}
$serial || &usage("No serial number specified");
$key || &usage("No licence key specified");
$key =~ /^(AMAZON|DEMO|GPL)$/ && &usage("This license key cannot be used for upgrades");
my ($out, $err);
# Setup Virtualmin license and repositories
&$first_print("Upgrading Virtualmin license and repositories ..");
my $vmcmd = &get_api_helper_command();
$vmcmd || &usage('Cannot find Virtualmin helper command');
&execute_command("$vmcmd setup-repos ".
"--serial @{[quotemeta($serial)]} --key @{[quotemeta($key)]} ".
"--force-update", undef, \$out, \$err);
if ($?) {
&$second_print($err || $out);
exit(2);
}
else {
&$second_print("..done");
}
# Update Virtualmin package to Pro
&$first_print("Upgrading Virtualmin package ..");
my $itype;
chop($itype = &read_file_contents("$module_root_directory/install-type"));
# Update metadata and install latest ca-certificates package
if ($itype eq "rpm") {
&execute_command("yum clean all");
&execute_command("yum -y update ca-certificates");
# Run the upgrade
&execute_command("yum -y install wbm-virtual-server wbm-virtualmin-support", undef, \$out, \$err);
if ($?) {
&$second_print("..error : @{[($err || $out)]}");
exit(3);
}
else {
&$second_print($text{'setup_done'});
&$second_print($text{'upgrade_success'});
}
}
# Update metadata and install latest ca-certificates package
elsif ($itype eq "deb") {
&execute_command("apt-get update");
&execute_command("apt-get -y install ca-certificates");
# Run the upgrade
my @packages;
&foreign_require("software");
foreach $p (&software::update_system_available()) {
if ($p->{'name'} eq 'webmin-virtual-server') {
# For the Virtualmin package, select pro
# version explicitly so that the GPL is
# replaced.
local ($ver) = grep { !/\.gpl/ }
&apt_package_versions($p->{'name'});
push(@packages, $ver ? $p->{'name'}."=".$ver
: $p->{'name'});
}
}
if (!@packages) {
push(@packages, 'webmin-virtual-server');
}
# Add Virtualmin support module
push(@packages, 'webmin-virtualmin-support');
&execute_command("apt-get -y --allow-unauthenticated --allow-downgrades --allow-remove-essential --allow-change-held-packages -f install ".join(" ", @packages)."", undef, \$out, \$err);
if ($?) {
&$second_print("..error : @{[($err || $out)]}");
exit(3);
}
else {
&$second_print($text{'setup_done'});
&$second_print($text{'upgrade_success'});
}
}
else {
&$second_print(".. error : Upgrades are not supported on this system : $itype");
exit(4);
}
&clear_links_cache();
&virtualmin_api_log(\@OLDARGV);
sub apt_package_versions
{
local ($name) = @_;
local @rv;
open(OUT, "apt-cache show ".quotemeta($name)." |");
while(<OUT>) {
if (/^Version:\s+(\S+)/) {
push(@rv, $1);
}
}
close(OUT);
return sort { $b cmp $a } @rv;
}
sub usage
{
print "$_[0]\n\n" if ($_[0]);
print "Upgrade Virtualmin GPL system to Pro.\n";
print "\n";
print "virtualmin upgrade-license --serial number\n";
print " --key id\n";
exit(1);
}