59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
function delUponExit()
|
|
{
|
|
if(is_file('/tmp/php.apt_history.log'))
|
|
unlink('/tmp/php.apt_history.log');
|
|
}
|
|
|
|
register_shutdown_function('delUponExit');
|
|
|
|
$i = 1;
|
|
exec("ls /var/log/apt/history.log.*.gz", $list);
|
|
|
|
foreach($list as $entry)
|
|
{
|
|
$lines = gzfile($entry);
|
|
file_put_contents("/tmp/php.apt_history.log", $lines, FILE_APPEND);
|
|
}
|
|
|
|
$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);
|
|
|
|
$i = 0; $j = 0;
|
|
|
|
foreach($list as $entry)
|
|
{
|
|
$history=explode(" ", $entry);
|
|
if($history[0] == "autoremove" || $history[0] == "upgrade")continue;
|
|
$history[0] == "install" ? ($packages[$history[1]]=true):($packages[$history[1]]=false);
|
|
}
|
|
|
|
foreach($packages as $package => $stat)
|
|
{
|
|
$stat ? ($ipackage[$i ++] = $package):($rpackage[$j ++] = $package);
|
|
}
|
|
|
|
$i = sizeOf($ipackage);
|
|
$j = sizeOf($rpackage);
|
|
|
|
$l = $i > $j ? $i:$j;
|
|
|
|
echo "Custom package activities(apt-get):\n";
|
|
echo "+---------------------------------------------------------+\n";
|
|
echo "| Package(s) installed | Package(s) removed |\n";
|
|
echo "|----------------------------+----------------------------|\n";
|
|
|
|
$ll = .5*(strlen("+---------------------------------------------------------+") - 3);
|
|
|
|
for($k = 0; $k < $l; $k ++) {
|
|
$il = str_pad($k < $i ? $ipackage[$k]:"", $ll, " ", STR_PAD_BOTH);
|
|
$rl = str_pad($k < $j ? $rpackage[$k]:"", $ll, " ", STR_PAD_BOTH);
|
|
|
|
|
|
echo "|$il|$rl|\n";
|
|
}
|
|
|
|
echo "+---------------------------------------------------------+\n";
|