repo-scripts/rules/RPM.php

54 lines
1.8 KiB
PHP

<?php
class RPM implements IRule
{
private $rebuildRepodata = false;
private $imported = false;
public function getMatchingExtensions(): array
{
return ["rpm"];
}
public function processFile(string $file)
{
/*
if(!$this->imported){
$this->imported = true;
echo "Importing signature...\r\n";
echo shell_exec("rpm --import " . escapeshellarg(Config::$key));
}
*/
$this->rebuildRepodata = true;
/*echo "Getting package arch...\r\n";
$arch = shell_exec("rpm -qip " . escapeshellarg($file) . " | grep Architecture:");
if (strpos($arch, "Architecture:") === false) {
echo "Failed to get package arch\r\n";
return;
} else {
$arch = trim(explode(":", $arch)[1]);
}*/
echo "Signing package...\r\n";
echo shell_exec("rpm --addsign " . escapeshellarg($file));
$dest = Config::$dest . "/linux/rpm/" . basename($file);
//if (!file_exists(dirname($dest))) mkdir(dirname($dest));
if (file_exists($dest)) @unlink($dest);
echo "Copying to repository...";
echo (copy($file, $dest) ? "OK" : "FAIL") . "\r\n";
}
public function __destruct()
{
if ($this->rebuildRepodata) {
echo "Rebuilding rpm repodata...\r\n";
$repoPath = Config::$dest . "/linux/rpm";
echo shell_exec("rm -rf " . escapeshellarg($repoPath . "/repodata"));
echo shell_exec("createrepo " . escapeshellarg($repoPath));
echo "Signing repository...\r\n";
echo shell_exec("gpg --detach-sign --armor " . escapeshellarg($repoPath . "/repodata/repomd.xml"));
copy(Config::$key, $repoPath . "/repodata/gpg-key");
}
}
}