-
Notifications
You must be signed in to change notification settings - Fork 2
/
act-get.lua
132 lines (126 loc) · 2.93 KB
/
act-get.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
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
--http://pastebin.com/5CuUMxqr
local branch = "master"
if fs.exists(".act.branch") then
local f = fs.open(".act.branch", "r")
branch = f.readAll()
f.close()
end
local files = {
{
name = "act-get",
url = "https://raw.github.com/Forte40/act/"..branch.."/act-get.lua"
},
{
name = "act",
folder = "apis",
url = "https://raw.github.com/Forte40/act/"..branch.."/act.lua"
},
{
name = "do",
url = "https://raw.github.com/Forte40/act/"..branch.."/do.lua"
},
{
name = "forman",
url = "https://raw.github.com/Forte40/act/"..branch.."/forman.lua"
},
{
name = "worker",
url = "https://raw.github.com/Forte40/act/"..branch.."/worker.lua"
},
{
name = "panel",
folder = "apis",
url = "https://raw.github.com/Forte40/panel/master/panel.lua"
}
}
local scripts = {"startup", "ethos_rail", "tree_farm", "tree", "tree2", "melon_farm", "mob_drop"}
local cmd = ...
if cmd == "list" then
textutils.pagedPrint(table.concat(scripts, "\n"))
return
elseif cmd == "startup" then
if fs.exists("disk") then
files = {
{
name = "startup",
folder = "disk",
url = "https://raw.github.com/Forte40/act/"..branch.."/startup.lua"
}
}
print("startup being copied to floppy")
print("copy an act script to the floppy manually")
print()
else
print("place next to drive with floppy")
return
end
elseif cmd then
local found = false
for _, name in ipairs(scripts) do
if cmd == name then
found = true
break
end
end
if found then
files = {
{
name = cmd..".act",
url = "https://raw.github.com/Forte40/act/"..branch.."/examples/"..cmd..".act"
}
}
else
print("script '"..cmd.."' does not exists")
return
end
end
if not http then
print("No access to web")
return
end
for _, file in ipairs(files) do
local path
if file.folder then
if not fs.exists(file.folder) then
fs.makeDir(file.folder)
end
path = fs.combine(file.folder, file.name)
else
path = file.name
end
local currText = ""
if fs.exists(path) then
local f = fs.open(path, "r")
currText = f.readAll()
f.close()
io.write("update ")
else
io.write("install ")
end
io.write("'"..file.name.."'"..string.rep(" ", math.max(0, 8 - #file.name)))
if file.folder then
io.write(" in '"..file.folder.."'"..string.rep(".", math.max(0, 8 - #file.folder)).."...")
else
io.write(" .............")
end
local request = http.get(file.url)
if request then
local response = request.getResponseCode()
if response == 200 then
local newText = request.readAll()
if newText == currText then
print("skip")
else
local f = fs.open(path, "w")
f.write(newText)
f.close()
print("done")
end
else
print(" bad HTTP response code " .. response)
end
else
print(" no request handle")
end
os.sleep(0.1)
end