This repository was archived by the owner on Nov 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.lua
More file actions
84 lines (76 loc) · 1.98 KB
/
install.lua
File metadata and controls
84 lines (76 loc) · 1.98 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
---@diagnostic disable-next-line: unknown-cast-variable
---@cast fs fs
---@diagnostic disable-next-line: unknown-cast-variable
---@cast http http
-- FIXME since the release tag changes now, this no longer works -> determine download url using GH API
local packed_url = "https://github.com/marcel-engelke/atref/releases/download/master/packed"
local packed = "/packed"
local delim = "--------------------------------------------------"
fs.delete("/install.log")
---@param msg string
local function log(msg)
print(msg)
local log_file = fs.open("/install.log", "a")
log_file.writeLine(msg)
log_file.close()
end
---@param dest string
local function fetch(dest)
log("fetching packed code from github")
local res = http.get(packed_url)
local code, _ = res.getResponseCode()
if code ~= 200 then
log("error: http status " .. code)
---@diagnostic disable-next-line: undefined-global
exit()
end
log("saving to '" .. dest .. "'")
local file = fs.open(dest, "w")
while true do
local line = res.readLine()
if not line then
file.close()
return
end
file.writeLine(line)
end
end
---@param packed_path string
local function unpack(packed_path)
local packed_file = fs.open(packed_path, 'r')
packed_file.readLine()
packed_file.readLine()
while true do
local path = packed_file.readLine()
---@cast path string
log("creating directory '" .. path .. "'")
fs.makeDir(path)
local file_name = packed_file.readLine()
---@cast file_name string
file_name = path .. "/" .. file_name
log("installing file '" .. file_name .. "'")
local file = fs.open(file_name, 'w')
packed_file.readLine()
while true do
local line = packed_file.readLine()
if not line then
file.close()
return
end
if line == delim then
log("delim: " .. line)
file.close()
break
end
file.writeLine(line)
end
end
end
if ... then
log("this script will install to /atref")
packed = ...
else
log("this script will download and install atref to /atref")
fetch(packed)
end
unpack(packed)