diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2019-10-09 17:11:22 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-10-09 17:11:22 -0700 |
commit | bea05d3fd9105bb7bc2c499b0053fe797d71f7a2 (patch) | |
tree | 64d113e0cb9557f2785c08af0ec0fd18ba1c9173 /bin/locmaint | |
parent | 653d5692ed9d1c4990fc573808321c908f0bb75f (diff) | |
download | dotfiles-bea05d3fd9105bb7bc2c499b0053fe797d71f7a2.tar.gz |
locmaint: avoid trying to purge the same package more than once
Diffstat (limited to 'bin/locmaint')
-rwxr-xr-x | bin/locmaint | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/bin/locmaint b/bin/locmaint index 2f85b3b9..d62913a3 100755 --- a/bin/locmaint +++ b/bin/locmaint @@ -430,18 +430,23 @@ sub do_sysmaint { chomp(my $kernel_release = `uname -r`); my $kernel_pkg_name = "linux-image-$kernel_release"; + my %purgeable; my @rc_packages; - my @build_deps_packages; for (`dpkg -l`) { /^([a-zA-Z ][a-zA-Z ][a-zA-Z ])\s(\S+)\s/ or next; my ($stat, $pkg) = ($1, $2); if ($stat eq "rc ") { + $purgeable{$pkg}{rc} = 1; + # @rc_packages will be used before %purgeable is modified, + # so we can its entries now. @build_deps_packages and + # @obsolete_packages will need be initialised only after + # we've possibly removed some entries from %purgeable push @rc_packages, $pkg; - } elsif ($pkg =~ /-build-deps\z/) { - push @build_deps_packages, $pkg; } + $purgeable{$pkg}{build_deps} = 1 if $pkg =~ /-build-deps\z/; } - my @obsolete_packages = grep !/\A$kernel_pkg_name\z/, + $purgeable{$_}{obsolete} = 1 + for grep !/\A$kernel_pkg_name\z/, map { /^..A? (\S+)\s/; $1 } `aptitude search '?obsolete'`; show_user @@ -452,19 +457,22 @@ sub do_sysmaint { unless (@rc_packages == 0) { say_bold("Conf-files packages:"); print " rc $_\n" for @rc_packages; - system as_root("apt-get -y purge @rc_packages") - if prompt_yn("Purge these?"); - # TODO also subtract any purged packages from - # @build_deps_packages and @obsolete_packages + if (prompt_yn("Purge these?")) { + system as_root("apt-get -y purge @rc_packages"); + delete $purgeable{$_} for @rc_packages; + } } + my @build_deps_packages = grep { $purgeable{$_}{bd} } keys %purgeable; unless (@build_deps_packages == 0) { say_bold("mk-build-deps(1) packages:"); print " $_\n" for @build_deps_packages; - system as_root("apt-get -y purge @build_deps_packages") - if prompt_yn("Purge these?"); - # TODO also subtract any purged packages from - # @obsolete_packages + if (prompt_yn("Purge these?")) { + system as_root("apt-get -y purge @build_deps_packages"); + delete $purgeable{$_} for @build_deps_packages; + } } + my @obsolete_packages + = grep { $purgeable{$_}{obsolete} } keys %purgeable; unless (@obsolete_packages == 0 || $suite eq TESTING) { say_bold("Packages not available from any mirrors:"); print " $_\n" for @obsolete_packages; |