-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.lua
More file actions
153 lines (100 loc) · 2.73 KB
/
Copy pathinstall.lua
File metadata and controls
153 lines (100 loc) · 2.73 KB
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
local BASE_URL = 'http://ac-get.darkdna.net'
local INSTALL_SOURCE = BASE_URL .. "/install"
local MANIFEST = BASE_URL .. "/install.manifest"
local args = {...}
if args[1] then
MANIFEST = args[1]
end
function get_url(url)
if http == nil then
error('Need HTTP library enabled.', 2)
end
local remote = http.get(url)
if remote == nil then
error('Error getting HTTP.', 2)
end
return remote
end
-----------------------------------------------------------
local x, y = term.getCursorPos()
local w, h = term.getSize()
local function task_begin(id)
x, y = term.getCursorPos()
end
local function task_update(id, detail, cur, max)
local txt = cur .. "/" .. max
if max == 0 then
txt = cur .. ""
end
term.setCursorPos(x, y)
term.clearLine()
if #detail > w - #txt - 1 then
detail = detail:sub(1, w - #txt - 4) .. "..."
end
term.write(detail)
term.setCursorPos(w - #txt + 1, y)
term.write(txt)
end
local function task_complete(id, detail)
local txt = "Complete"
if detail ~= "" then
term.setCursorPos(x, y)
term.clearLine()
if #detail > w - #txt - 1 then
detail = detail:sub(1, w - #txt - 4) .. "..."
end
term.write(detail)
end
term.setCursorPos(w - #txt + 1, y)
term.write(txt)
print()
end
local log_f = io.open("/acg-install.log", "w")
local function print_log(lvl, msg)
log_f:write(lvl .. " - " .. msg .. "\n")
end
local tmp_dir = '/tmp-' .. math.random(65535)
print('Initilizing first run installer in ' .. tmp_dir)
fs.makeDir(tmp_dir)
local _, e = pcall(function()
local acg_base = get_url(INSTALL_SOURCE .. '/manifest')
local line = acg_base.readLine();
local i = 1
task_begin('get-files')
repeat
-- print(' ' .. line)
task_update('get-files', "Getting " .. line, i, 0)
local loc_file = fs.open(tmp_dir .. '/' .. line, 'w')
local acg_file = get_url(INSTALL_SOURCE .. '/' .. line)
loc_file.write(acg_file.readAll())
acg_file.close()
loc_file.close()
dofile(tmp_dir .. '/' .. line, line)
line = acg_base.readLine()
i = i + 1
until line == nil
task_complete('get-files', 'Get ac-get installer files.')
i = 1
local tot = #dirs
task_begin('make-dirs', 'Making directories')
for k, v in pairs(dirs) do
task_update('make-dirs', 'Making ' .. v, i, tot)
fs.makeDir(v)
i = i + 1
end
task_complete('make-dirs', 'Creating directories.')
local state = new(State)
state:hook("task_begin", task_begin)
state:hook("task_update", task_update)
state:hook("task_complete", task_complete)
log.add_target(print_log)
state:run_manifest(MANIFEST)
--local repo = state:add_repo(BASE_REPO, 'Base ac-get repo')
--repo:install_package('ac-get')
state:save()
end)
if e then
print("Error executing: " .. e)
end
log_f:close()
fs.delete(tmp_dir)