Skip to content

Instantly share code, notes, and snippets.

@horgh
Created March 10, 2017 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horgh/6a431dea45c2d92e5b84e6fb92520eda to your computer and use it in GitHub Desktop.
Save horgh/6a431dea45c2d92e5b84e6fb92520eda to your computer and use it in GitHub Desktop.
use strict;
use warnings;
# Find all installed packages
my $out = `dpkg-query -l`;
# Lines like:
# ii zlib1g-dev:i386 1:1.2.8.dfsg- i386 compression library - development
my @lines = split /\n/, $out;
foreach my $line (@lines) {
my @pieces = split /\s+/, $line;
my $status = $pieces[0];
next unless $status eq 'ii';
my $name = $pieces[1];
# Look up its repo
# Lines like:
# irssi | 0.8.20-2 | http://ftp.ca.debian.org/debian stretch/main i386 Packages
# May have multiple lines if have source defined.
my $madison = `apt-cache madison $name`;
my @madison_lines = split /\n/, $madison;
if (@madison_lines == 0) {
print "$name MISSING INFO\n";
next;
}
my @pieces2 = split /\|/, $madison_lines[0];
if (@pieces2 < 3) {
print "$name MISSING INFO\n";
next;
}
my $repo = $pieces2[2];
$repo =~ s/^\s+|\s+$//g;
print "$name: $repo\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment