-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.woo
155 lines (120 loc) · 5.29 KB
/
install.woo
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
-- 安装自己
-- https://gitee.com/oshine/om/raw/master/installer.woo
-- https://gitee.com/oshine/om/raw/v1.0.11/installer.woo
local T = true
--local host = 'https://woo.wooyri.com/om?ver='
local host = 'http://127.0.0.1:8008/s/om?ver='
local params = _args()
if not params.lan then
while true do
--params.lan = _readline('please choose install language(default [en] english)/请选择安装语言(默认[en]英文):[en/zh]')
if not params.lan then
params.lan = 'en'
end
if not _in_array(params.lan, { 'en', 'zh' }) then
print('only en or zh valid,trt again/只能输入en或者zh,请重试')
else
print(({ ['en'] = 'you choose english', ['zh'] = '你选择了中文' })[params.lan])
break
end
end
end
print(({ ['en'] = 'ready to request server for om version', ['zh'] = '准备请求服务器可用的om版本' })[params.lan])
local ver = _str_sub(_ver(), 0, 4)
host = host .. ver
local available, err = woo.http:new():get(host)
if err ~= nil then
print(err)
return
end
available = available.body
if _is_valid(available) then
available = _json_decode(available)
else
print('can not access network')
os.exit(-1)
end
if available.code ~= 0 then
print('unknown error')
return
end
--_out(available)
print(({ ['en'] = 'there have the version[%s] valid',
['zh'] = '这里有版本[%s]可用' })[params.lan]:format(available.data.ver))
if not params.install_dir then
--params.install_dir = _readline(({ ['en'] = 'type install dir,default ${home}/om:',
-- ['zh'] = '请输入安装目录,默认 ${home}/om:' })[params.lan])
if not params.install_dir then
params.install_dir = _home() .. '/om'
end
end
-- 动态获取当前woo语言版本对应的最大可用om版本
local om_ver = '1.15'
function downl()
local addr = available.data.addr
if not addr then
print(({ ['en'] = 'server response err', ['zh'] = '服务器返回不正确' })[params.lan])
return
end
local curr_env = _env('OM_PATH')
print(({ ['en'] = 'current OM_PATH:%s,you choose install dir:%s',
['zh'] = '当前 OM_PATH:%s,你选择的安装地址:%s' })[params.lan]:format(curr_env, params.install_dir))
if curr_env ~= params.install_dir then
if _os() == 'windows' then
-- 添加环境变量,判断windows和unix系统
_exec({ 'cmd', '/c', 'setx OM_PATH ' .. params.install_dir })
else
_exec({ 'sh', '-c', 'echo export OM_PATH=' .. params.install_dir .. ' >> ~/.bashrc && source ~/.bashrc' })
end
print(({ ['en'] = 'env variable not correct ,correct it now', ['zh'] = '环境变量不正确,已经修正' })[params.lan])
else
print(({ ['en'] = 'env variable ok ,skip it', ['zh'] = '环境变量配置正确,跳过' })[params.lan])
end
local addrs = _str_split(addr, '|')
for i, addr_host in pairs(addrs) do
if _str_index(addr, 'gitee.com/') ~= -1 then
-- https://gitee.com/oshine/om/repository/archive/v1.0.11.zip
-- https://gitee.com/oshine/om/repository/archive/v1.0.11.zip?ref=v1.0.11&sha=fbaebe69d0e33c243f5c40a63cf8af26cb044b45&format=zip&captcha_type=yunpian&token=938e763645e446f78190ae5047f357b1&authenticate=784120e1cf514f91ac01d8251a81c696
addr_host = addr_host .. '/repository/archive/v' .. available.data.ver .. '.zip'
elseif _str_index(addr, 'github.com/') ~= -1 then
-- todo,install from github
end
print(({ ['en'] = 'start download from:%s',
['zh'] = '开始下载:%s' })[params.lan]:format(addr_host))
_wget('om.zip', addr_host,
{ cookies = { }, headers = { ['User-Agent'] = 'curl/7.74.0 (' .. _os(true) .. '/woo-' .. _ver() .. ')' } },
function(current, total)
print(current, total)
end)
break
end
print(({ ['en'] = 'finish download,start unzip...',
['zh'] = '下载完成开始解压...' })[params.lan])
local exit = _file_exist(params.install_dir .. '/om')
print('exit:', exit, params.install_dir .. '/om')
if exit then
local r = (({ ['en'] = 'om already install,are you sure replace it?(y/n):',
['zh'] = 'om 已经安装,是否替换?' })[params.lan])
if _readline(r) ~= 'y' then
return
end
print(({ ['en'] = 'delete old om folder...',
['zh'] = '删除就的om文件夹...' })[params.lan])
_rm(params.install_dir .. '/om')
end
local unzip_res = _zip('unzip', 'om.zip', params.install_dir .. '/')
if unzip_res ~= true then
print(({ ['en'] = 'unzip fail:%s',
['zh'] = '解压失败:%s' })[params.lan]:format(unzip_res))
return
end
end
--downl()
print(({ en = 'unzip success,install om dependencies package',
zh = '解压成功,安装om依赖包' })[params.lan])
--local git='https://gitee.com/oshine/om'
package.path = '@' .. params.install_dir .. '/?.woo'
print(package.path)
require('oshine/om@1.?:installer'):new(params.install_dir .. '/oshine/om/' .. om_ver):
install({ lan = params.lan }, true, om_ver)
print(({ ['en'] = 'success', ['zh'] = '成功' })[params.lan])