Print essential and build-essential packages
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 24 Apr 2015 00:42:53 +0000 (21:42 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 24 Apr 2015 00:42:53 +0000 (21:42 -0300)
Parse Packages file and print all packages needed for essential and
build-essential.

debsort.pl [new file with mode: 0644]

diff --git a/debsort.pl b/debsort.pl
new file mode 100644 (file)
index 0000000..1066656
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/env perl
+#
+#   Copyright 2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+#
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use warnings;
+
+open(PACKAGES, "<Packages");
+open(SOURCES, "<Sources");
+
+my @packages = ();
+my %depends = ();
+my %priority = ();
+my %essential = ();
+
+sub add_depends {
+       my ($package, $depends) = @_;
+       my $deps = [];
+       my @vdeps = split(",", $depends);
+       for my $i (@vdeps) {
+               $i =~ qr,([0-9a-z-+.]+),;
+               push @$deps, $1;
+       }
+       $depends{$package} = $deps;
+}
+
+my $package;
+while (<PACKAGES>) {
+       if (/^Package: ([0-9a-z-+.]+)/) {
+               $package = $1;
+               push @packages, $package;
+       }
+       if (/^Depends: (.*)/) {
+               add_depends($package, $1);
+       }
+       if (/^Priority: (.*)/) {
+               $priority{$package} = $1;
+       }
+       if (/^Essential: yes/) {
+               $essential{$package} = "yes";
+       }
+}
+
+close(PACKAGES);
+close(SOURCES);
+
+my @pp = ();
+
+my @visit = ();
+
+for my $i (keys %essential) {
+       push @visit, $i;
+}
+push @visit, "build-essential";
+
+while (@visit) {
+       my $n = pop @visit;
+       next if grep /^$n$/, @pp;
+       push @pp, $n;
+       my $l = $depends{$n};
+       for my $d (@$l) {
+               if (!grep /^$d$/, @pp && !grep /^$d$/, @visit) {
+                       push @visit, $d;
+               }
+       }
+}
+
+for my $i (@pp) {
+       print "$i\n";
+}