Skip to content

Instantly share code, notes, and snippets.

@mklooss
Last active March 14, 2017 14:54
Show Gist options
  • Save mklooss/c9fca78de4ce4c6758cd94ec45f35d11 to your computer and use it in GitHub Desktop.
Save mklooss/c9fca78de4ce4c6758cd94ec45f35d11 to your computer and use it in GitHub Desktop.
find old debian packages after upgrade
<?php
/* yeah i know, php buuuuuh */
exec('apt-cache dumpavail | grep "Package:" | awk \'{print $2}\' > packages.txt');
exec('dpkg -l | awk \'{print $2}\' > installed.txt');
$packages = file_get_contents('packages.txt');
$packages = str_replace("\r", '', $packages);
$packages = array_filter((array) explode("\n", $packages));
$installed = file_get_contents('installed.txt');
$installed = str_replace("\r", '', $installed);
$installed = array_filter((array) explode("\n", $installed));
foreach ($installed as $_pkg)
{
$__pkg = array_filter((array)explode(':', $_pkg));
$_pkg = array_shift($__pkg);
unset($__pkg);
if (!in_array($_pkg, $packages))
{
echo $_pkg;
echo "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment