Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 718 → Rev 719

/buildidx/buildidx.php
10,6 → 10,7
 
requires php-zip
 
15 feb 2022: index is generated as json, contains all filenames and alt versions
14 feb 2022: packages are expected to have the *.svp extension
12 feb 2022: skip source packages from being processed (*.src.zip)
20 jan 2022: rewritten the code from ANSI C to PHP for easier maintenance
29,7 → 30,7
22 sep 2012: forked 1st version from FDUPDATE builder
*/
 
$PVER = "20220214";
$PVER = "20220215";
 
 
// computes the BSD sum of a file and returns it
91,7 → 92,7
 
// ***************** MAIN ROUTINE *********************************************
 
echo "SvarDOS repository index generator ver {$PVER}\n";
//echo "SvarDOS repository index generator ver {$PVER}\n";
 
if (($_SERVER['argc'] != 2) || ($_SERVER['argv'][1][0] == '-')) {
echo "usage: php buildidx.php repodir\n";
100,50 → 101,69
 
$repodir = $_SERVER['argv'][1];
 
echo "building index for directory {$repodir}...\n";
 
$pkgfiles = scandir($repodir);
$pkglist = '';
$pkgcount = 0;
 
// iterate over each svp package
foreach ($pkgfiles as $zipfile) {
if (!preg_match('/.svp$/i', $zipfile)) continue; // skip non-svp files
if (strchr($zipfile, '-')) {
echo "skipping: {$zipfile}\n";
continue; // skip alt vers (like dosmid-0.9.2.svp)
}
// do a list of all svp packages with their available versions and descriptions
 
$path_parts = pathinfo($zipfile);
$pkg = strtolower($path_parts['filename']);
$pkgdb = array();
foreach ($pkgfiles as $fname) {
if (!preg_match('/.svp$/i', $fname)) continue; // skip non-svp files
 
$zipfile_fullpath = realpath($repodir . '/' . $zipfile);
$path_parts = pathinfo($fname);
$pkgnam = explode('-', $path_parts['filename'])[0];
$pkgfullpath = realpath($repodir . '/' . $fname);
 
$lsm = read_file_from_zip($zipfile_fullpath, "appinfo/{$pkg}.lsm");
$lsm = read_file_from_zip($pkgfullpath, "appinfo/{$pkgnam}.lsm");
if ($lsm == false) {
echo "ERROR: pkg {$z} does not contain an LSM file at the expected location\n";
exit(1);
echo "ERROR: pkg {$fname} does not contain an LSM file at the expected location\n";
continue;
}
 
$lsmarray = parse_lsm($lsm);
if (empty($lsmarray['version'])) {
echo "ERROR: lsm file in {$zipfile} does not contain a version\n";
var_dump($lsmarray);
exit(1);
echo "ERROR: lsm file in {$fname} does not contain a version\n";
continue;
}
if (empty($lsmarray['description'])) {
echo "ERROR: lsm file in {$zipfile} does not contain a description\n";
exit(1);
echo "ERROR: lsm file in {$fname} does not contain a description\n";
continue;
}
 
$pkglist .= "{$pkg}\t{$lsmarray['version']}\t{$lsmarray['description']}\t" . file2bsum($zipfile_fullpath) . "\n";
$meta['fname'] = $fname;
$meta['desc'] = $lsmarray['description'];
 
$pkgdb[$pkgnam][$lsmarray['version']] = $meta;
}
 
$db = array();
 
// iterate over each svp package
foreach ($pkgdb as $pkg => $versions) {
 
// sort filenames by version, highest first
uksort($versions, "version_compare");
$versions = array_reverse($versions, true);
 
foreach ($versions as $ver => $meta) {
$fname = $meta['fname'];
$desc = $meta['desc'];
 
$bsum = file2bsum(realpath($repodir . '/' . $fname));
 
$meta2['ver'] = strval($ver);
$meta2['bsum'] = $bsum;
 
if (empty($db[$pkg]['desc'])) $db[$pkg]['desc'] = $desc;
$db[$pkg]['versions'][$fname] = $meta2;
}
 
$pkgcount++;
 
}
 
echo "DONE - processed " . $pkgcount . " svp packages\n";
if ($pkgcount < 100) echo "WARNING: an unexpectedly low number of packages has been found in the repo ({$pkgcount})\n";
 
file_put_contents($repodir . '/index.tsv', $pkglist);
file_put_contents($repodir . '/_index.json', json_encode($db));
 
exit(0);
 
/website/index-repo.php
5,22 → 5,21
 
<?php
 
$handle = fopen('../packages/index.tsv', "rb");
if ($handle === FALSE) {
echo "<p>ERROR: INDEX FILE NOT FOUND</p>\n";
exit(0);
}
$db = json_decode(file_get_contents('../packages/_index.json'), true);
 
echo "<table>\n";
 
echo "<thead><tr><th>PACKAGE</th><th>VERSION</th><th>DESCRIPTION</th></tr></thead>\n";
 
while (($arr = fgetcsv($handle, 1024, "\t")) !== FALSE) {
// format: pkgname | version | desc | bsdsum
echo "<tr><td><a href=\"repo/?a=pull&amp;p={$arr[0]}\">{$arr[0]}</a></td><td>{$arr[1]}</td><td>{$arr[2]}</td></tr>\n";
foreach ($db as $pkg => $meta) {
 
$desc = $meta['desc'];
$pref = array_shift($meta['versions']); // get first version (that's the preferred one)
$ver = $pref['ver'];
$bsum = $pref['bsum'];
 
echo "<tr><td><a href=\"repo/?a=pull&amp;p={$pkg}\">{$pkg}</a></td><td>{$ver}</td><td>{$desc}</td></tr>\n";
}
echo "</table>\n";
 
fclose($handle);
 
?>
/website/repo/index.php
73,6 → 73,7
$a = strtolower($_GET['a']);
 
$p = '';
$v = '';
if ($a != 'checkup') {
if (empty($_GET['p'])) {
http_response_code(404);
79,56 → 80,78
echo "ERROR: no package specified\r\n";
exit(0);
}
$p = strtolower($_GET['p']);
$pv = explode('-', strtolower($_GET['p']));
$p = $pv[0];
if (!empty($pv[1])) $v = $pv[1];
}
 
$v = '';
if (!empty($_GET['v'])) $v = $_GET['v'];
 
// pull action is easy (does not require looking into pkg list), do it now
// is action valid?
 
if ($a === 'pull') {
if (file_exists($p . '.svp')) {
header('Content-Disposition: attachment; filename="' . $p . '.svp"');
header('Content-Type: application/octet-stream');
readfile($p . '.svp');
} else {
http_response_code(404);
echo "ERROR: package not found on server\r\n";
}
if (($a !== 'search') && ($a !== 'checkup') && ($a !== 'pull')) {
http_response_code(404);
echo "ERROR: invalid action\r\n";
exit(0);
}
 
// is action valid?
 
if (($a !== 'search') && ($a !== 'checkup')) {
// load pkg db
 
$db = json_decode(file_get_contents('_index.json'), true);
if (empty($db)) {
http_response_code(404);
echo "ERROR: invalid action\r\n";
echo "ERROR: server error, database not found\n";
exit(0);
}
 
// iterate over packages now
 
$handle = fopen("index.tsv", "rb");
if ($handle === FALSE) {
http_response_code(404);
echo "ERROR: Server-side internal error\r\n";
// pull action
 
if ($a === 'pull') {
$fname = false;
if (empty($v)) { // take first version (that's the preferred one)
$fname = array_key_first($db[$p]['versions']);
} else {
// look for a specific version string
foreach ($db[$p]['versions'] as $f => $e) {
if (strcasecmp($e['ver'], $v) == 0) {
$fname = $f;
break;
}
}
}
if (file_exists($fname)) {
header('Content-Disposition: attachment; filename="' . $fname);
header('Content-Type: application/octet-stream');
readfile($fname);
} else {
http_response_code(404);
echo "ERROR: package not found on server\r\n";
}
exit(0);
}
 
 
// search action
 
if ($a === 'search') {
$matches = 0;
while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
if ((stristr($pkg[0], $p)) || (stristr($pkg[2], $p))) {
echo str_pad(strtoupper($pkg[0]), 12) . str_pad("ver: {$pkg[1]} ", 16) . str_pad("size: " . nicesize(filesize($pkg[0] . '.svp')), 16) . "BSUM: " . sprintf("%04X", $pkg[3]) . "\r\n";
echo wordwrap($pkg[2], 79, "\r\n", true);
foreach ($db as $pkg => $meta) {
if ((stristr($pkg, $p)) || (stristr($meta['desc'], $p))) {
// fetch first (preferred) version
$prefver_fname = array_key_first($meta['versions']);
$prefver = array_shift($meta['versions']);
echo str_pad(strtoupper($pkg), 12) . str_pad("ver: {$prefver['ver']} ", 16) . str_pad("size: " . nicesize(filesize($prefver_fname)), 16) . "BSUM: " . sprintf("%04X", $prefver['bsum']) . "\r\n";
echo wordwrap($meta['desc'], 79, "\r\n", true);
echo "\r\n";
// do I have any alt versions?
$altvers = glob("{$pkg[0]}-*.svp");
if (!empty($altvers)) {
$alts = str_replace('.svp', '', $altvers);
echo wordwrap("[alt versions: " . implode(', ', $alts), 79, "\r\n", true) . "]\r\n";
$altlist = array();
foreach ($meta['versions'] as $altver) {
$altlist[] = $pkg . '-' . $altver['ver'];
}
if (!empty($altlist)) {
echo wordwrap("[alt versions: " . implode(', ', $altlist), 79, "\r\n", true) . "]\r\n";
}
echo "\r\n";
$matches++;
}
136,32 → 159,36
if ($matches == 0) echo "No matching package found.\r\n";
}
 
 
// checkup action
 
if ($a === 'checkup') {
$found = 0;
$remote_pkgs = csv_to_array("php://input", "\t"); // [0] = pkgname ; [1] = version
while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
// is $pkg part of remote packages?
foreach ($remote_pkgs as $rpkg) {
if (strcasecmp($pkg[0], $rpkg[0]) != 0) continue;
if ($pkg[1] === $rpkg[1]) continue; // skip same version
if ($found == 0) {
echo str_pad('', 58, '-') . "\r\n";
tabulprint(array('PACKAGE', 'INSTALLED (LOCAL)', 'AVAILABLE (REMOTE)'), array(8, 20, 20));
tabulprint(array('----------', '----------------------', '----------------------'), array(10, 22, 22), false);
}
$found++;
tabulprint(array('' . $pkg[0], $rpkg[1], $pkg[1]), array(8, 20, 20));
break;
 
foreach ($remote_pkgs as $rpkg) {
$rpkg[0] = strtolower($rpkg[0]);
if (empty($db[$rpkg[0]])) continue;
 
$dbpkg = $db[$rpkg[0]];
// compare user's version with preferred version in repo
$prefver = array_shift($dbpkg['versions']);
if (strcasecmp($prefver['ver'], $rpkg[1]) == 0) continue;
// found version mismatch
if ($found == 0) {
echo str_pad('', 58, '-') . "\r\n";
tabulprint(array('PACKAGE', 'INSTALLED (LOCAL)', 'AVAILABLE (REMOTE)'), array(8, 20, 20));
tabulprint(array('----------', '----------------------', '----------------------'), array(10, 22, 22), false);
}
$found++;
tabulprint(array('' . $rpkg[0], $rpkg[1], $prefver['ver']), array(8, 20, 20));
}
if ($found == 0) {
echo "no available updates\r\n";
} else {
echo str_pad('', 58, '-') . "\r\n";
echo "found {$found} differing packages\r\n";
echo "found {$found} differing package(s)\r\n";
}
}
fclose($handle);
 
 
?>