forked from dbb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapt-carbon.pl
executable file
·53 lines (42 loc) · 1.25 KB
/
apt-carbon.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
#!/usr/bin/perl -w
use strict;
use autodie;
use AptPkg::Cache; # debian: libapt-pkg-perllibapt-pkg-perl
use List::MoreUtils qw(natatime); # debian: liblist-moreutils-perl
# github.com/dbbolton
my $cache = AptPkg::Cache->new;
open(my $out, ">", "apt-carbon.sh");
print $out <<'EOF';
#!/bin/sh
aptitude update && aptitude safe-upgrade
aptitude install -P
EOF
my @pkg_list;
for (split "\n", `dpkg -l`) {
if (/^i/) {
my $name = (split ' ', $_)[1];
push @pkg_list, $name;
}
}
my $j = natatime 3, @pkg_list;
while (my @vals = $j->()) {
print $out "@vals \\\n";
}
print $out " \n# end of apt-carbon.sh";
# Pasting ###################################################################
# old, dirty form that doesn't use AptPkg::Cache
# if ( ! (`apt-cache policy curl` =~ /\(none\)/))
if ( $cache->{'curl'}->{'CurrentState'} eq 'Installed' ) {
print "Using curl...\n";
system "cat apt-carbon.sh | curl -F 'sprunge=<-' http://sprunge.us";
}
elsif ( $cache->{'pastebinit'}->{'CurrentState'} eq 'Installed' ) {
print "Using pastebinit...\n";
system "pastebinit apt-carbon.sh";
}
else {
print "Automatic upload failed: Neither curl nor pastebinit is installed.\n".
"Your script is located at ./apt-carbon.sh\n";
}
chmod 0744, $out;
close $out;