add git source: HIT

pull/493/head
qkqpttgf 2021-12-20 10:44:51 +08:00 committed by GitHub
parent e9681f5595
commit b91245904c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 16 deletions

View File

@ -312,19 +312,23 @@ function setConfigResponse($response)
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')
{
$slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
global $slash;
// __DIR__ is xxx/platform
$projectPath = splitlast(__DIR__, $slash)[0];
// 从github下载对应tar.gz并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
if ($GitSource=='Github') {
// 从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 0;
$tarfile = $projectPath . $slash .'github.tar.gz';
$githubfile = file_get_contents($url);
if (!$githubfile) return 0;
file_put_contents($tarfile, $githubfile);
if (splitfirst(PHP_VERSION, '.')[0] > '5') {
$phar = new PharData($tarfile); // need php5.3, 7, 8
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
@ -336,14 +340,7 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
unlink($tarfile);
$outPath = '';
$tmp = scandir($projectPath);
$name = $auth . '-' . $project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath = $projectPath . $slash . $f;
break;
}
}
$outPath = findIndexPath($projectPath);
//error_log1($outPath);
if ($outPath=='') return 0;
@ -354,11 +351,12 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
$tmp1['message'] = "Can not move " . $projectPath . $slash . '.data' . $slash . 'config.php' . " to " . $outPath . $slash . '.data' . $slash . 'config.php';
return json_encode($tmp1);
}
return moveFolder($outPath, $projectPath, $slash);
return moveFolder($outPath, $projectPath);
}
function moveFolder($from, $to, $slash)
function moveFolder($from, $to)
{
global $slash;
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
if (!file_exists($to)) mkdir($to, 0777);
@ -368,7 +366,7 @@ function moveFolder($from, $to, $slash)
$fromfile = $from . $slash . $filename;
$tofile = $to . $slash . $filename;
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
$response = moveFolder($fromfile, $tofile, $slash);
$response = moveFolder($fromfile, $tofile);
if (api_error(setConfigResponse($response))) return $response;
}else{
//if (file_exists($tofile)) unlink($tofile);