~ubuntu-branches/debian/sid/apt-dater/sid

« back to all changes in this revision

Viewing changes to .pc/03-wheezy-kernel.diff/clients/debian/apt-dater-host

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-01-08 19:39:23 UTC
  • Revision ID: package-import@ubuntu.com-20130108193923-j0ktvkife0n5kt1t
Tags: 0.9.0-3+wheezy1
Add patch 03-wheezy-kernel, which fixes an missdetection of the Wheezy 3.2
Linux Kernel as selfbuilt variant.
Closes: #697330

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# apt-dater - terminal-based remote package update manager
 
4
#
 
5
# Authors:
 
6
#   Andre Ellguth <ellguth@ibh.de>
 
7
#   Thomas Liske <liske@ibh.de>
 
8
#
 
9
# Copyright Holder:
 
10
#   2008-2012 (C) IBH IT-Service GmbH [http://www.ibh.de/apt-dater/]
 
11
#
 
12
# License:
 
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.
 
17
#
 
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.
 
22
#
 
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
 
26
#
 
27
 
 
28
use AptPkg::Config '$_config';
 
29
use AptPkg::System '$_system';
 
30
use AptPkg::Cache;
 
31
use ImVirt;
 
32
use strict;
 
33
use warnings;
 
34
 
 
35
my $CFGFILE = '/etc/apt-dater-host.conf';
 
36
my $DPKGTOOL = 'aptitude';
 
37
my $APTUPGRADE = 'dist-upgrade';
 
38
my $ASSUMEYES = 0;
 
39
my $GETROOT = 'sudo';
 
40
my $CLEANUP = 0;
 
41
my $FORBID_REFRESH = 0;
 
42
my $FORBID_UPGRADE = 0;
 
43
my $FORBID_INSTALL = 0;
 
44
my $UUIDFILE = '/etc/apt-dater-host.uuid';
 
45
my @CLUSTERS;
 
46
 
 
47
my $CMD = shift;
 
48
my $ADPROTO = '0.6';
 
49
 
 
50
$ENV{'LC_ALL'} = 'C';
 
51
 
 
52
if (-r $CFGFILE) {
 
53
    eval `cat "$CFGFILE"` ;
 
54
 
 
55
    if($@ ne '') {
 
56
        print "ADPROTO: $ADPROTO\n";
 
57
        print "ADPERR: Invalid config $CFGFILE: $@\n";
 
58
        exit;
 
59
    }
 
60
}
 
61
 
 
62
$GETROOT = '' if($> == 0);
 
63
 
 
64
die "Don't call this script directly!\n" unless (defined($CMD));
 
65
if($CMD eq 'sshkey') {
 
66
    die "Sorry, no shell access allowed!\n"
 
67
      unless(defined($ENV{'SSH_ORIGINAL_COMMAND'}));
 
68
 
 
69
    @ARGV = split(' ', $ENV{'SSH_ORIGINAL_COMMAND'});
 
70
 
 
71
    shift;
 
72
    $CMD = shift;
 
73
}
 
74
die "Invalid command '$CMD'!\n" unless ($CMD=~/^(refresh|status|upgrade|install|kernel)$/);
 
75
 
 
76
if ($CMD eq 'refresh') {
 
77
    print "ADPROTO: $ADPROTO\n";
 
78
    if ($FORBID_REFRESH) {
 
79
        print STDERR "\n\n** Sorry, apt-dater based refreshs on this host are disabled! **\n\n"
 
80
    }
 
81
    else {
 
82
        &do_refresh;
 
83
    }
 
84
    &do_status;
 
85
    &do_kernel;
 
86
}
 
87
elsif ($CMD eq 'status') {
 
88
    print "ADPROTO: $ADPROTO\n";
 
89
    &do_status;
 
90
    &do_kernel;
 
91
}
 
92
elsif ($CMD eq 'upgrade') {
 
93
    if ($FORBID_UPGRADE) {
 
94
        print STDERR "\n\n** Sorry, apt-dater based upgrades on this host are disabled! **\n\n";
 
95
    }
 
96
    else {
 
97
        &do_upgrade;
 
98
        &do_cleanup;
 
99
    }
 
100
}
 
101
elsif ($CMD eq 'install') {
 
102
    if ($FORBID_INSTALL) {
 
103
        print STDERR "\n\n** Sorry, apt-dater based installations on this host are disabled! **\n\n";
 
104
    }
 
105
    else {
 
106
        &do_install(@ARGV);
 
107
        &do_cleanup;
 
108
    }
 
109
}
 
110
elsif ($CMD eq 'kernel') {
 
111
    print "ADPROTO: $ADPROTO\n";
 
112
    &do_kernel;
 
113
}
 
114
else {
 
115
    die "Internal error!\n";
 
116
}
 
117
 
 
118
 
 
119
sub do_refresh() {
 
120
    if(system("$GETROOT $DPKGTOOL update")) {
 
121
        print "\nADPERR: Failed to execute '$GETROOT $DPKGTOOL update' ($?).\n";
 
122
        exit(1);
 
123
    }
 
124
}
 
125
 
 
126
sub get_virt() {
 
127
    return imv_get(IMV_PROB_DEFAULT);
 
128
}
 
129
 
 
130
sub get_uname() {
 
131
    my $kernel;
 
132
    my $machine;
 
133
 
 
134
    chomp($kernel = `uname -s`);
 
135
    chomp($machine = `uname -m`);
 
136
    return "$kernel|$machine";
 
137
}
 
138
 
 
139
sub do_status() {
 
140
    # initialise the global config object with the default values and
 
141
    # setup the $_system object
 
142
    $_config->init;
 
143
    $_system = $_config->system;
 
144
 
 
145
    # supress cache building messages
 
146
    $_config->{quiet} = 2;
 
147
 
 
148
    # set up the cache
 
149
    my $cache = AptPkg::Cache->new;
 
150
 
 
151
    # retrieve lsb informations
 
152
    unless (open(HLSB, "lsb_release -a 2> /dev/null |")) {
 
153
        print "\nADPERR: Failed to execute 'lsb_release -a' ($!).\n";
 
154
        exit(1);
 
155
    }
 
156
    my %lsb;
 
157
    while(<HLSB>) {
 
158
        chomp;
 
159
 
 
160
        $lsb{$1}=$2 if (/^(Distributor ID|Release|Codename):\s+(\S.*)$/);
 
161
    }
 
162
    close(HLSB);
 
163
    if($?) {
 
164
        print "\nADPERR: Error executing 'lsb_release -a' ($?).\n";
 
165
        exit(1);
 
166
    }
 
167
    print "LSBREL: $lsb{'Distributor ID'}|$lsb{'Release'}|$lsb{'Codename'}\n";
 
168
 
 
169
    # retrieve virtualization informations
 
170
    print "VIRT: ".&get_virt."\n";
 
171
 
 
172
    # retrieve uname informations
 
173
    print "UNAME: ".&get_uname."\n";
 
174
 
 
175
    # calculate forbid mask
 
176
    my $mask = 0;
 
177
    $mask |= 1 if ($FORBID_REFRESH);
 
178
    $mask |= 2 if ($FORBID_UPGRADE);
 
179
    $mask |= 4 if ($FORBID_INSTALL);
 
180
    print "FORBID: $mask\n";
 
181
 
 
182
    # add installation UUID if available
 
183
    if(-r $UUIDFILE && -s $UUIDFILE) {
 
184
        print "UUID: ", `head -n 1 "$UUIDFILE"`;
 
185
    }
 
186
 
 
187
    # add cluster name if available
 
188
    foreach my $CLUSTER (@CLUSTERS) {
 
189
        print "CLUSTER: $CLUSTER\n";
 
190
    }
 
191
 
 
192
    # get packages which might be upgraded
 
193
    my %updates;
 
194
    my %holds;
 
195
    my $pos = 0;
 
196
    my $DPKGARGS;
 
197
    my $_GETROOT = $GETROOT;
 
198
 
 
199
    if($DPKGTOOL eq "apt-get") {
 
200
        $DPKGARGS = "--quiet --simulate --fix-broken --allow-unauthenticated";
 
201
    }
 
202
    elsif($DPKGTOOL eq "aptitude") {
 
203
        $DPKGARGS = "--verbose --assume-yes --quiet --simulate -f --allow-untrusted";
 
204
        $_GETROOT = '';
 
205
    }
 
206
    else {
 
207
        # unkown DPKG frontend - fallback to apt-get
 
208
        $DPKGTOOL = "apt-get";
 
209
        $DPKGARGS = "--quiet --simulate --fix-broken --allow-unauthenticated";
 
210
    }
 
211
 
 
212
    unless(open(HAPT, "$_GETROOT $DPKGTOOL $DPKGARGS dist-upgrade |")) {
 
213
        print "\nADPERR: Failed to execute '$_GETROOT $DPKGTOOL $DPKGARGS dist-upgrade' ($!).\n";
 
214
        exit(1);
 
215
    }
 
216
    while(<HAPT>) {
 
217
        chomp;
 
218
        
 
219
        if($pos == 0) {
 
220
            $pos=1 if (/^The following packages have been kept back/);
 
221
            $pos=2 if (/^The following packages will be upgraded:/);
 
222
            next;
 
223
        }
 
224
 
 
225
        if($pos == 1) {
 
226
            unless (/^\s/) {
 
227
                $pos++;
 
228
                next;
 
229
            }
 
230
            while(/^\s*(\S+)(\s(.+))?$/) {
 
231
                $holds{$1} = 1;
 
232
                if(defined($2)) {
 
233
                    $_ = $2;
 
234
                }
 
235
                else {
 
236
                    $_ = '';
 
237
                }
 
238
            }
 
239
        }
 
240
 
 
241
        $updates{$1} = $2 if (/^Inst (\S+) \[.+\] \((\S+) /);
 
242
    }
 
243
    close(HAPT);
 
244
    if($?) {
 
245
        print "\nADPERR: Error executing '$GETROOT $DPKGTOOL $DPKGARGS dist-upgrade' ($?).\n";
 
246
        exit(1);
 
247
    }
 
248
 
 
249
    # get version of installed packages
 
250
    my %installed;
 
251
    my %status;
 
252
    unless(open(HDPKG, "dpkg-query --show --showformat='\${Package} \${Version} \${Status}\\n' |")) {
 
253
        print "\nADPERR: Failed to execute \"dpkg-query --show --showformat='\${Package} \${Version} \${Status}\\n'\" ($!).\n";
 
254
        exit(1);
 
255
    }
 
256
    while(<HDPKG>) {
 
257
        chomp;
 
258
 
 
259
        next unless (/^(\S+) (\S+) (\S+) (\S+) (\S+)$/);
 
260
        $installed{$1} = $2 ;
 
261
                
 
262
        if($holds{$1}) {
 
263
            $status{$1} = 'h';
 
264
        }
 
265
        elsif($updates{$1}) {
 
266
            $status{$1} = 'u';
 
267
        }
 
268
        else {
 
269
            $status{$1} = substr($3, 0, 1);
 
270
            
 
271
            if ($status{$1} eq 'i') {
 
272
                my $p = $cache->{$1};
 
273
 
 
274
                unless ($5 eq 'installed') {
 
275
                    $status{$1} = "b=$5";
 
276
                }
 
277
                elsif ($p) {
 
278
                    if (my $available = $p->{VersionList}) {
 
279
                        my $extra = 1;
 
280
                        for my $v (@$available) {
 
281
                            for my $f (map $_->{File}, @{$v->{FileList}}) {
 
282
                                $extra = 0 unless ($f->{FileName} eq '/var/lib/dpkg/status');
 
283
                            }
 
284
                        }
 
285
                        $status{$1} = 'x' if($extra);
 
286
                    }
 
287
                }
 
288
            }
 
289
        }
 
290
    }
 
291
    close(HDPKG);
 
292
    if($?) {
 
293
        print "\nADPERR: Error executing \"dpkg-query --show --showformat='\${Package} \${Version} \${Status}\\n'\" ($?).\n";
 
294
        exit(1);
 
295
    }
 
296
 
 
297
    foreach my $pkg (keys %installed) {
 
298
        print "STATUS: $pkg|$installed{$pkg}|$status{$pkg}";
 
299
        if (exists($updates{$pkg})) {
 
300
            print "=$updates{$pkg}" ;
 
301
        }
 
302
        
 
303
        print "\n";
 
304
    }
 
305
}
 
306
 
 
307
sub do_upgrade() {
 
308
    my $UpgradeCmd = "$GETROOT $DPKGTOOL ";
 
309
 
 
310
    $UpgradeCmd .= '--assume-yes ' if($ASSUMEYES);
 
311
 
 
312
    if($DPKGTOOL eq 'aptitude'){
 
313
        $UpgradeCmd .= '-o Aptitude::Delete-Unused=false ';
 
314
    }
 
315
    $UpgradeCmd .= $APTUPGRADE;
 
316
 
 
317
    system($UpgradeCmd);
 
318
}
 
319
 
 
320
sub do_install() {
 
321
    if($GETROOT) {
 
322
        system($GETROOT, $DPKGTOOL, 'install', @_);
 
323
    }
 
324
    else {
 
325
        system($DPKGTOOL, 'install', @_);
 
326
    }
 
327
}
 
328
 
 
329
sub do_kernel() {
 
330
    my $infostr = 'KERNELINFO:';
 
331
    my $verfile = '/proc/version';
 
332
    my $version = `uname -r`;
 
333
    chomp($version);
 
334
 
 
335
    unless(-r $verfile) {
 
336
        print "$infostr 9 $version\n";
 
337
        return;
 
338
    }
 
339
 
 
340
    unless(`cat /proc/version` =~ /^\S+ \S+ \S+ \(Debian ([^\)]+)\)/) {
 
341
        print "$infostr 2 $version\n";
 
342
        return;
 
343
    }
 
344
    my $vers = $1;
 
345
 
 
346
    my $reboot = 0;
 
347
    unless(open(HDPKG, "dpkg-query -W -f='\${Version} \${Status;20} \${Maintainer} \${Provides}\n' 'linux-image*'|grep 'install ok installed Debian Kernel Team'|grep linux-image|")) {
 
348
        print "$infostr 9 $version\n";
 
349
        return;
 
350
    }
 
351
    while(<HDPKG>) {
 
352
        next unless (/^(\S+)\s/);
 
353
        
 
354
        $reboot=1 unless (system("dpkg", "--compare-versions", $vers, "lt", $1) >> 8);
 
355
    }
 
356
    close(HDPKG);
 
357
 
 
358
    print "$infostr $reboot $version\n";
 
359
}
 
360
 
 
361
sub do_cleanup() {
 
362
    return unless $CLEANUP;
 
363
 
 
364
    system("$GETROOT $DPKGTOOL clean");
 
365
}