add git source: HIT

pull/493/head
qkqpttgf 2021-12-20 10:47:16 +08:00 committed by GitHub
parent 68c07943e6
commit 4cfe38c388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 13 deletions

View File

@ -595,27 +595,25 @@ function setConfigResponse($response)
return json_decode( $response, true )['Response'];
}
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
$source = '/tmp/code.zip';
$outPath = '/tmp/';
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 json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]);
$tarfile = '/tmp/github.tar.gz';
file_put_contents($tarfile, file_get_contents($url));
$phar = new PharData($tarfile);
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
// 获取包中目录名
$tmp = scandir('phar://'.$tarfile);
$name = $auth.'-'.$project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath .= $f;
break;
}
}
// 获取解压出的目录名
$outPath = findIndexPath($outPath);
// 放入配置文件
file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php'));
@ -649,7 +647,7 @@ function addFileToZip($zip, $rootpath, $path = '')
}
}
}
@closedir($path);
@closedir($handler);
}
function WaitFunction() {