utils/php/pkgstat.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2014-01-23 12:48:52 +00:00
<?php
2014-04-11 04:12:20 +00:00
function delUponExit()
{
2014-01-23 12:48:52 +00:00
if(is_file('/tmp/php.apt_history.log'))
2014-04-11 04:12:20 +00:00
unlink('/tmp/php.apt_history.log');
2014-01-23 12:48:52 +00:00
}
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
register_shutdown_function('delUponExit');
$i = 1;
exec("ls /var/log/apt/history.log.*.gz", $list);
2014-04-11 04:12:20 +00:00
foreach($list as $entry)
{
2014-01-23 12:48:52 +00:00
$lines = gzfile($entry);
2014-04-11 04:12:20 +00:00
file_put_contents("/tmp/php.apt_history.log", $lines, FILE_APPEND);
2014-01-23 12:48:52 +00:00
}
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
$list = null;
exec("cat /var/log/apt/history.log >> /tmp/php.apt_history.log");
exec('cat /tmp/php.apt_history.log |egrep --regexp=\'^Commandline:\sapt-get\s[(install)(remove)(purge)]\'|awk \'{print $3" "$4}\'', $list);
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
$i = 0; $j = 0;
2014-04-11 04:12:20 +00:00
foreach($list as $entry)
{
2014-01-23 12:48:52 +00:00
$history=explode(" ", $entry);
if($history[0] == "autoremove" || $history[0] == "upgrade")continue;
$history[0] == "install" ? ($packages[$history[1]]=true):($packages[$history[1]]=false);
}
2014-04-11 04:12:20 +00:00
foreach($packages as $package => $stat)
{
2014-01-23 12:48:52 +00:00
$stat ? ($ipackage[$i ++] = $package):($rpackage[$j ++] = $package);
}
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
$i = sizeOf($ipackage);
$j = sizeOf($rpackage);
$l = $i > $j ? $i:$j;
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
echo "Custom package activities(apt-get):\n";
echo "+---------------------------------------------------------+\n";
echo "| Package(s) installed | Package(s) removed |\n";
echo "|----------------------------+----------------------------|\n";
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
$ll = .5*(strlen("+---------------------------------------------------------+") - 3);
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
for($k = 0; $k < $l; $k ++) {
2014-04-11 04:12:20 +00:00
$il = str_pad($k < $i ? $ipackage[$k]:"", $ll, " ", STR_PAD_BOTH);
$rl = str_pad($k < $j ? $rpackage[$k]:"", $ll, " ", STR_PAD_BOTH);
2014-01-23 12:48:52 +00:00
2014-04-11 04:12:20 +00:00
echo "|$il|$rl|\n";
2014-01-23 12:48:52 +00:00
}
2014-04-11 04:12:20 +00:00
2014-01-23 12:48:52 +00:00
echo "+---------------------------------------------------------+\n";