public function getInstalledPackageDetails($hostDetails, $packageName)
{
// what are we doing?
$log = usingLog()->startAction("get details for package '{$packageName}' installed in host '{$hostDetails->hostId}'");
// get the details
$command = 'dpkg-query -W --showformat=\'\\${Package} \\${Version}\\t\\${Status}\\n\' ' . $packageName;
$result = $this->runCommand($hostDetails, $command);
// any luck?
if ($result->didCommandFail()) {
$log->endAction("could not get details ... package not installed?");
return new BaseObject();
}
// study the output
$lines = explode("\n", $result->output);
$lines = FilterForMatchingRegex::against($lines, "|^{$packageName} |");
$lines = FilterForMatchingString::against($lines, "install ok installed");
if (empty($lines)) {
$log->endAction("package not installed?");
return new BaseObject();
}
// we have some information to return
$return = new BaseObject();
$return->name = FilterColumns::fromString($lines[0], "0", " ");
$return->version = FilterColumns::fromString($lines[0], "1", "\t");
$return->repo = "unknown";
// all done
$log->endAction();
return $return;
}