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