3
# apt-dater - terminal-based remote package update manager
6
# Andre Ellguth <ellguth@ibh.de>
7
# Thomas Liske <liske@ibh.de>
10
# 2008-2012 (C) IBH IT-Service GmbH [http://www.ibh.de/apt-dater/]
13
# This program is free software; you can redistribute it and/or modify
14
# it under the terms of the GNU General Public License as published by
15
# the Free Software Foundation; either version 2 of the License, or
16
# (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this package; if not, write to the Free Software
25
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
my $CFGFILE = '/etc/apt-dater-host.conf';
33
my $FORBID_UPGRADE = 0;
34
my $FORBID_INSTALL = 0;
35
my $UUIDFILE = '/etc/apt-dater-host.uuid';
44
eval `cat "$CFGFILE"` ;
47
print "ADPROTO: $ADPROTO\n";
48
print "ADPERR: Invalid config $CFGFILE: $@\n";
53
$GETROOT = '' if($> == 0);
55
die "Don't call this script directly!\n" unless (defined($CMD));
56
if($CMD eq 'sshkey') {
57
die "Sorry, no shell access allowed!\n"
58
unless(defined($ENV{'SSH_ORIGINAL_COMMAND'}));
60
@ARGV = split(' ', $ENV{'SSH_ORIGINAL_COMMAND'});
65
die "Invalid command '$CMD'!\n" unless ($CMD=~/^(refresh|status|upgrade|install|kernel)$/);
67
if ($CMD eq 'refresh') {
68
print "ADPROTO: $ADPROTO\n";
72
elsif ($CMD eq 'status') {
73
print "ADPROTO: $ADPROTO\n";
77
elsif ($CMD eq 'upgrade') {
78
if ($FORBID_UPGRADE) {
79
print STDERR "\n\n** Sorry, apt-dater based upgrades on this host are disabled! **\n\n"
85
elsif ($CMD eq 'install') {
86
if ($FORBID_INSTALL) {
87
print STDERR "\n\n** Sorry, apt-dater based installations on this host are disabled! **\n\n"
93
elsif ($CMD eq 'kernel') {
94
print "ADPROTO: $ADPROTO\n";
98
die "Internal error!\n";
102
return "Unknown" unless (-x '/usr/bin/imvirt');
105
chomp($imvirt = `/usr/bin/imvirt`);
114
chomp($kernel = `uname -s`);
115
chomp($machine = `uname -m`);
116
return "$kernel|$machine";
120
# retrieve lsb informations
121
unless(open(HLSB, "lsb_release -a 2> /dev/null |")) {
122
print "\nADPERR: Failed to execute 'lsb_release -a' ($!).\n";
130
$lsb{$1}=$2 if (/^(Distributor ID|Release|Codename):\s+(\S.*)$/);
134
print "\nADPERR: Error executing 'lsb_release -a' ($?).\n";
138
print "LSBREL: $lsb{'Distributor ID'}|$lsb{'Release'}|$lsb{'Codename'}\n";
140
# retrieve virtualization informations
141
print "VIRT: ".&get_virt."\n";
143
# retrieve uname informations
144
print "UNAME: ".&get_uname."\n";
146
# calculate forbid mask
148
# $mask |= 1 if ($FORBID_REFRESH); NOT SUPPORTED
149
$mask |= 2 if ($FORBID_UPGRADE);
150
$mask |= 4 if ($FORBID_INSTALL);
151
print "FORBID: $mask\n";
153
# add installation UUID if available
154
if(-r $UUIDFILE && -s $UUIDFILE) {
155
print "UUID: ", `head -n 1 "$UUIDFILE"`;
158
# add cluster name if available
159
foreach my $CLUSTER (@CLUSTERS) {
160
print "CLUSTER: $CLUSTER\n";
163
# get packages which might be upgraded
165
unless(open(HAPT, "$GETROOT rug --terse list-updates |")) {
166
print "\nADPERR: Failed to execute '$GETROOT rug --terse list-updates' ($!).\n";
172
$updates{$1} = $2 if (/^.*\|.*\|.*\|([^|]+)\|([^|]+)\|/);
176
print "\nADPERR: Error executing '$GETROOT rug --terse list-updates' ($?).\n";
180
# get version of installed packages
183
unless(open(HDPKG, "rpm -qa --qf '%{NAME}|%{VERSION}-%{RELEASE}|\n' |")) {
184
print "\nADPERR: Failed to execute \"rpm -qa --qf '%{NAME}|%{VERSION}-%{RELEASE}|\\n'\" ($!).\n";
191
next unless (/^(\S+)\|\S+\|/);
197
print 'u=', $updates{$1};
207
print "\nADPERR: Error executing \"rpm -qa --qf '%{NAME}|%{VERSION}-%{RELEASE}|\\n'\" ($?).\n";
214
system("$GETROOT rug update");
219
system($GETROOT, 'rug', 'install', @_);
222
system('rug', 'install', @_);
227
my $infostr = 'KERNELINFO:';
228
my $version = `uname -r`;
232
$add = $1 if($version =~ /(-[a-z]+)$/);
238
unless(open(HKERNEL, "rpm -q --whatprovides kernel --qf '%{NAME}|%{VERSION}-%{RELEASE}\n' |")) {
239
print "$infostr 9 $version\n";
245
if(/^kernel$add\|(.+)/) {
247
$distri{$ver.$add} = 1;
253
$kinstalled = $ver if(&versioncmp($kinstalled, $ver) < 0);
259
print "$infostr 9 $version\n";
263
unless($distri{$version}) {
264
print "$infostr 2 $version\n";
268
unless($kinstalled.$add cmp $version) {
269
print "$infostr 0 $version\n";
272
print "$infostr 1 $version\n";
276
# Taken from Sort::Versions 1.4
277
# Copyright (c) 1996, Kenneth J. Albanowski.
280
my @A = ($_[0] =~ /([-.]|\d+|[^-.\d]+)/g);
281
my @B = ($_[1] =~ /([-.]|\d+|[^-.\d]+)/g);
287
if ($A eq '-' and $B eq '-') {
289
} elsif ( $A eq '-' ) {
291
} elsif ( $B eq '-') {
293
} elsif ($A eq '.' and $B eq '.') {
295
} elsif ( $A eq '.' ) {
297
} elsif ( $B eq '.' ) {
299
} elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) {
300
if ($A =~ /^0/ || $B =~ /^0/) {
301
return $A cmp $B if $A cmp $B;
303
return $A <=> $B if $A <=> $B;
308
return $A cmp $B if $A cmp $B;