-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller
executable file
·82 lines (63 loc) · 2.01 KB
/
installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env php
<?php
/**
* @param $url
* @return mixed
*/
function get($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_USERAGENT, 'AlphaGo');
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
/**
* @param $file
* @param $destination
*/
function unzip_file($file, $destination)
{
$zip = new ZipArchive();
if ($zip->open($file) !== TRUE) {
die("Could not open archive");
}
$zip->extractTo($destination);
$zip->close();
}
/**
* @param $sudo
*/
function global_install($sudo = false)
{
$command = 'ln -s -f ' . __DIR__ . '/test-yunti-speed/yunti /usr/local/bin/yunti && chmod a+x /usr/local/bin/yunti';
if ($sudo) {
$command = 'sudo ' . $command;
}
system($command, $command_return);
if ($command_return === 0) {
$text = '安装成功,命令 yunti 已链接到 /usr/local/bin/,你可以在命令行运行 yunti 进行 vpn 连接。';
echo PHP_EOL . chr(27) . '[1;32m' . $text . chr(27) . '[0m' . PHP_EOL;
} else {
$text = '当前账户无权安装,将切换到 ROOT 账户,可能需要输入密码。';
echo chr(27) . '[1;33m' . $text . chr(27) . '[0m' . PHP_EOL . PHP_EOL;
global_install(true);
}
}
echo '正在安装云梯脚本…' . PHP_EOL . PHP_EOL;
# 获取 last releases download url
$api_url = 'https://api.github.com/repos/springjk/test-yunti-speed/releases/latest';
$version = json_decode(get($api_url), true);
$file_url = $version['assets'][0]['browser_download_url'];
# 下载文件
file_put_contents(__DIR__ . '/test-yunti-speed.zip', get($file_url));
# 解压文件
unzip_file(__DIR__ . '/test-yunti-speed.zip', __DIR__);
unlink(__DIR__ . '/test-yunti-speed.zip');
# 添加全局执行
global_install();