Rev 647 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env php
<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This script will be called at the ViaThinkSoft server side
$argc = $_SERVER['argc']; // to please Eclipse for PHP
$argv = $_SERVER['argv']; // to please Eclipse for PHP
if (PHP_SAPI != 'cli') {
die("This file can only be invoked in CLI mode.\n");
}
if ($argc != 2) {
echo "Usage: ".$argv[0]." <targetpath>\n";
exit(2);
}
$output_dir = $argv[1];
if (!is_dir($output_dir)) {
echo "Path $output_dir does not exist!\n";
exit(1);
}
/**
* @param string $dir
* @param string|null $basepath
* @param array $results
* @return array
* @throws Exception
*/
function getDirContents(string $dir, string $basepath = null, array &$results = array()): array {
if (is_null($basepath)) $basepath = $dir;
$basepath = realpath($basepath) . DIRECTORY_SEPARATOR;
$dir = realpath($dir) . DIRECTORY_SEPARATOR;
$files = scandir($dir);
foreach ($files as $file) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $file);
if (!is_dir($path)) {
$xpath = substr($path, strlen($basepath));
$xpath = str_replace('\\', '/', $xpath);
$results[] = hash_file('sha256', $path)."\t".$xpath;
} else if ($file != "." && $file != ".." && $file != ".svn" && $file != ".git") {
getDirContents($path, $basepath, $results);
$xpath = substr($path, strlen($basepath));
$xpath = str_replace('\\', '/', $xpath);
$results[] = hash('sha256', '')."\t".$xpath;
}
}
return $results;
}
$out = array();
$ec = -1;
exec('svn info https://svn.viathinksoft.com/svn/oidplus/ | grep "Revision:" | cut -d " " -f 2', $out, $ec);
$max_svn = implode("", $out);
for ($i=1; $i<=$max_svn; $i++) {
echo "SVN revision $i / $max_svn\r";
$outfile = "$output_dir/svn-rev$i.txt";
if (!file_exists($outfile)) {
$outdir = "/tmp/oidplus_svntmp_$i/";
if (is_dir($outdir)) {
exec("rm -rf $outdir", $out, $ec);
}
exec("svn co https://svn.viathinksoft.com/svn/oidplus/@$i $outdir", $out, $ec);
if ($ec != 0) continue;
$ary = getDirContents($outdir, $outdir);
exec("rm -rf $outdir", $out, $ec);
if ($ec != 0) continue;
$ary = implode("\n", $ary)."\n";
file_put_contents($outfile, $ary);
}
}
echo "\n";