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