forked from Ale32bit-CC/SmartNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.lua
53 lines (46 loc) · 1.39 KB
/
installer.lua
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
-- https://api.github.com/repos/knijn/SmartNet/git/trees/main?recursive=1
print("SmartNet by AlexDevs")
local date
if fs.exists("config.lua") then
print("Existing config.lua found. Overwrite? [y/N]")
local ans = read()
if ans:lower():sub(1,1) ~= "y" then
date = os.date("%Y%m%d%H%M%S")
fs.move("config.lua", date .. ".config.lua")
end
end
print("Fetching files list...")
local h, err = http.get("https://api.github.com/repos/knijn/SmartNet/git/trees/main?recursive=1")
if not h then
printError(err)
return false
end
local files = textutils.unserialiseJSON(h.readAll())
h.close()
print("Downloading files...")
for k, v in ipairs(files.tree) do
if v.type == "blob" then
print("Downloading " .. v.path)
local h, err = http.get("https://raw.githubusercontent.com/knijn/SmartNet/main/" .. v.path)
if h then
local content = h.readAll()
h.close()
local f = fs.open(v.path, "w")
f.write(content)
f.close()
else
printError(err)
end
elseif v.type == "tree" then
print("Creating directory " .. v.path)
fs.makeDir(v.path)
end
end
if date then
print("Restoring config...")
fs.delete("config.lua")
fs.copy(date .. ".config.lua", "config.lua")
print("Reboot to apply update")
else
print("Edit config.lua and reboot to apply")
end