Rev 1426 | Go to most recent revision | Blame | Last modification | View Log | RSS feed
#!/usr/bin/env php
<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2022 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
require_once __DIR__.'/funcs.inc.php';
// Generate keypair with:
// openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:8192
// openssl rsa -pubout -in private.pem -out public.pem
$argc = $_SERVER['argc']; // to please Eclipse for PHP
$argv = $_SERVER['argv']; // to please Eclipse for PHP
if (PHP_SAPI != 'cli') {
fwrite(STDERR, "This file can only be invoked in CLI mode.\n");
die();
}
if (DIRECTORY_SEPARATOR != '/') {
echo "This script can only run on Unix like systems\n";
exit(2);
}
if ($argc != 4) {
echo "Usage: ".$argv[0]." <targetpath> <privkey> <force(1|0)>\n";
exit(2);
}
$output_dir = $argv[1];
$priv_key = $argv[2];
$force = $argv[3];
if (!is_dir($output_dir)) {
echo "Path $output_dir does not exist!\n";
exit(1);
}
if (!is_file($priv_key)) {
echo "Private key file $priv_key does not exist!\n";
exit(1);
}
if (($force != '1') && ($force != '0')) {
echo "Argument 'force' must be 0 or 1\n";
exit(1);
}
// First, write the change scripts
$out = array();
$ec = -1;
exec('svn info https://svn.viathinksoft.com/svn/oidplus/trunk/ | grep "Revision:" | cut -d " " -f 2', $out, $ec);
if ($ec != 0) die("SVN Info failed!!!\n");
$max_svn = implode("", $out);
if ($max_svn > 1426) $max_svn = 1426; // 1425 is the last commit for update system v2
for ($i=2; $i<=$max_svn; $i++) {
echo "SVN revision $i / $max_svn\r";
$outfile = $output_dir."/update_".($i-1)."_to_$i.txt";
if (!$force && is_file($outfile)) continue;
$outdir_old = "/tmp/oidplus_svntmp2_".($i-1)."/";
if ($outdir_old && is_dir($outdir_old)) exec("rm -rf $outdir_old", $out, $ec);
exec("svn co https://svn.viathinksoft.com/svn/oidplus/trunk/@".($i-1)." $outdir_old", $out, $ec);
if ($ec != 0) die("Checkout of SVN Rev ".($i-1)." failed!!!\n");
hotfix_dir('2.0.0.'.($i-1), $outdir_old);
$outdir_new = "/tmp/oidplus_svntmp2_$i/";
if ($outdir_new && is_dir($outdir_new)) exec("rm -rf $outdir_new", $out, $ec);
exec("svn co https://svn.viathinksoft.com/svn/oidplus/trunk/@$i $outdir_new", $out, $ec);
if ($ec != 0) die("Checkout of SVN Rev ".($i)." failed!!!\n");
hotfix_dir('2.0.0.'.$i, $outdir_new);
oidplus_create_changescript($outdir_old, $outdir_new, $outfile, '2.0.0.'.($i-1), $i==1426?'2.0.1':'2.0.0.'.$i, $priv_key);
// Delete temp dirs
$ec = -1;
$out = array();
if ($outdir_old && is_dir($outdir_old)) exec("rm -rf $outdir_old", $out, $ec);
if ($outdir_new && is_dir($outdir_new)) exec("rm -rf $outdir_new", $out, $ec);
}
echo "\n";
// Now write the release messages (required by software update and vnag)
$ec = -1;
$out = array();
exec('svn log https://svn.viathinksoft.com/svn/oidplus/trunk --xml', $out, $ec);
if ($ec != 0) {
fwrite(STDERR, "SVN Log failed\n");
} else {
$str = implode("\n",$out);
$xml = simplexml_load_string($str);
$out = array();
foreach ($xml as $a) {
$out[(int)$a->attributes()->revision] = array(
'date' => date('Y-m-d H:i:s',strtotime((string)$a->date)),
'author' => (string)$a->author,
'msg' => trim((string)$a->msg),
);
}
ksort($out);
// TODO: We should also digitally sign these files?
file_put_contents($output_dir.'/releases.ser', serialize($out));
file_put_contents($output_dir.'/releases.ser.gz', gzencode(serialize($out)));
}