add git source: HIT

pull/493/head
qkqpttgf 2021-12-20 10:48:25 +08:00 committed by GitHub
parent 4cfe38c388
commit 459b23b284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 19 deletions

View File

@ -388,34 +388,33 @@ function setConfigResponse($response)
return json_decode($response, true); return json_decode($response, true);
} }
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{ {
$tmppath = '/tmp'; $tmppath = '/tmp';
// 从github下载对应tar.gz并解压 if ($GitSource=='Github') {
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; // 从github下载对应tar.gz并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
} elseif ($GitSource=='HITGitlab') {
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
} else return json_encode(['error'=>['code'=>'Git Source input Error!']]);
$tarfile = $tmppath . '/github.tar.gz'; $tarfile = $tmppath . '/github.tar.gz';
$githubfile = file_get_contents($url); file_put_contents($tarfile, file_get_contents($url));
if (!$githubfile) return '{"error":{"message":"fail to download from github"}}'; $phar = new PharData($tarfile);
file_put_contents($tarfile, $githubfile); $html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
$phar = new PharData($tarfile); // need php5.3, 7, 8
$phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖
unlink($tarfile); unlink($tarfile);
$outPath = ''; // 获取解压出的目录名
$tmp = scandir($tmppath); $outPath = findIndexPath($tmppath);
$name = $auth . '-' . $project;
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
$name = $project . 'CODE';
mkdir($tmppath . "/" . $name, 0777, 1); mkdir($tmppath . "/" . $name, 0777, 1);
foreach ($tmp as $f) { rename($outPath, $tmppath . "/" . $name . '/api');
if ( substr($f, 0, strlen($name)) == $name) { $outPath = $tmppath . "/" . $name;
rename($tmppath . '/' . $f, $tmppath . "/" . $name . '/api');
$outPath = $tmppath . "/" . $name;
break;
}
}
//echo $outPath . "<br>"; //echo $outPath . "<br>";
//error_log1($outPath); //error_log1($outPath);
if ($outPath=='') return '{"error":{"message":"no outpath"}}';
// put in config // put in config
$coderoot = __DIR__; $coderoot = __DIR__;