-
Notifications
You must be signed in to change notification settings - Fork 1
/
aptupgrade
executable file
·100 lines (82 loc) · 1.81 KB
/
aptupgrade
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl -w
use strict;
our $opt_dry= $ENV{DRY};
$0=~ /([^\/]+)$/s;
my $me= $1;
sub usage {
die "$me list of packages to upgrade
Checks each package whether it is really installed, and if yes,
apt-get install's it.
";
exit 1;
}
usage unless @ARGV;
# get list of installed packages
our %installed= map { chomp; $_=>1 } `dpkglist -i`;
$|=1;
our @packages= grep {
if (/^-/) {
usage
} else {
my $installed= $installed{$_};
if (!$installed) {
print "$me: package '$_' is not installed.\n";
}
$installed
}
} @ARGV;
use Chj::Debian::DpkgAptList 'aptlist';
use Chj::Chomp;
use Chj::xperlfunc;
sub prln {
print "$me: @_\n";
}
sub set_sighandler {
my ($signal)=@_;
$SIG{$signal}= sub {
die "got SIG$signal";
}
};
if (@packages) {
# before upgrading packages, save the auto-install flags
my %autoinstalled;
aptlist( +{Package=>1,
'Auto-Installed'=>1,
},
sub {
my ($d)=@_;
my $name= Chomp $$d{Package}[0][0];
my $autoinstalled= Chomp $$d{'Auto-Installed'}[0][0];
$autoinstalled{$name}= $autoinstalled;
});
my @autopackages= grep {
$autoinstalled{$_}
} @packages;
my $save_autoflags= sub {
if (@autopackages) {
prln "These packages had their auto-installed flag set:";
prln " $_" for @autopackages;
prln "set their flags again..";
xxsystem( ($opt_dry ? "echo" : ()), "aptitude", "install", "--",
map {
$_.'&M'
} @autopackages);
prln "done";
}
};
set_sighandler $_ for
qw(HUP INT QUIT USR1 USR2);
eval {
xxsystem( ($opt_dry ? "echo" : ()), "apt-get", "install", "--", @packages);
&$save_autoflags;
1
} || do {
my $e= $@;
eval {
prln "There was an error.";
&$save_autoflags;
};
prln "Here's the previous error:";
die $e;
};
}