1 |
#!/usr/bin/perl |
2 |
###################################### |
3 |
# $Id: apt-get_remote.pl,v 1.3 2003/02/03 10:42:10 jonen Exp $ |
4 |
###################################### |
5 |
# $Log: apt-get_remote.pl,v $ |
6 |
# Revision 1.3 2003/02/03 10:42:10 jonen |
7 |
# + another bugfix (sorry, but my orginal script was destroyed by a mistake of myself, arrggg.. ;) |
8 |
# |
9 |
# Revision 1.1 2003/02/03 10:04:56 jonen |
10 |
# + first init |
11 |
# |
12 |
# |
13 |
###################################### |
14 |
|
15 |
|
16 |
=pod |
17 |
|
18 |
=head2 apt-get_remote.pl - remote apt-get via mail, web etc. |
19 |
|
20 |
Sebastian Utz S<seut@netfrag.org> |
21 |
|
22 |
B<last changes> |
23 |
|
24 |
$Id: apt-get_remote.pl,v 1.3 2003/02/03 10:42:10 jonen Exp $ |
25 |
|
26 |
=head3 Description |
27 |
|
28 |
Currently, it generates only filtered output of 'apt-get update; apt-get --dry-run upgrade' to e.g. mail via cronjob to some user. |
29 |
|
30 |
=head3 ToDo |
31 |
|
32 |
o generates html output and replace 'o' with e.g. a 'checkbox' |
33 |
o add action to do a upgrade to all packages |
34 |
o make this available via http |
35 |
o get response via mail, http, etc. and check selected packages |
36 |
o install selected packages |
37 |
o some more functions: |
38 |
o generate list of all installed packages |
39 |
o generate list of all not-installed packages |
40 |
o generate list of all 'old' packages |
41 |
o generate list of all '-dev' and unused packages |
42 |
|
43 |
|
44 |
=cut |
45 |
|
46 |
|
47 |
use strict; |
48 |
use warnings; |
49 |
|
50 |
use Data::Dumper; |
51 |
use Sys::Hostname; |
52 |
|
53 |
my $hostname = hostname(); |
54 |
|
55 |
my $apt_get = "/usr/bin/apt-get"; |
56 |
my $apt_update = $apt_get . " update"; |
57 |
my $apt_upgrade = $apt_get . " -y upgrade"; |
58 |
my $apt_dry_upgrade = $apt_get . " --dry-run upgrade"; |
59 |
|
60 |
my $result = `$apt_dry_upgrade`; |
61 |
|
62 |
my @raw_data = split("\n", $result); |
63 |
|
64 |
my @new_lines; |
65 |
|
66 |
push @new_lines, "Checking for upgrade available packages for '". $hostname . "':\n"; |
67 |
|
68 |
my $count_lines = $#raw_data; |
69 |
my $cnt = 1; |
70 |
foreach(@raw_data) { |
71 |
if($_ =~ /^\s\s/ ) { |
72 |
s/^\s\s/ /; |
73 |
my @packages = split(" ", $_); |
74 |
foreach(@packages) { |
75 |
push @new_lines, " o " . $_; |
76 |
} |
77 |
} |
78 |
elsif($_ =~ /packages upgraded,/ ) { |
79 |
push @new_lines, $_; |
80 |
if($raw_data[$cnt] =~ /or removed\.$/) { |
81 |
push @new_lines, $raw_data[$cnt]; |
82 |
splice(@raw_data, $cnt, 1); |
83 |
} |
84 |
push @new_lines, "\n"; |
85 |
push @new_lines, "New Packages available for upgrade:"; |
86 |
} |
87 |
elsif( $_ =~ /^Inst/ ) { |
88 |
s/^Inst/ o /; |
89 |
push @new_lines,$_; |
90 |
} |
91 |
elsif( $_ !~ /^Conf/ ) { |
92 |
push @new_lines, $_; |
93 |
} |
94 |
if($cnt == $count_lines) { |
95 |
push @new_lines, "\n\n"; |
96 |
} |
97 |
$cnt++; |
98 |
} |
99 |
|
100 |
|
101 |
print join("\n", @new_lines); |