-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.lua
64 lines (61 loc) · 1.93 KB
/
startup.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
-- SPLITS A STRING INTO TWO PARTS, BEFORE AND AFTER THE DELIMITER
function splitString(string, delimiter)
local parts={}
parts[1]=string:sub(0, (string:find(delimiter))-1)
parts[2]=string:sub((string:find(delimiter))+1)
return parts
end
-- CHECKS IF THE PROGRAM REQUIRES UPDATING
function requiresUpdate(newestVersion)
-- IF THERE IS NO CHANGELOG: UPDATE
local file=io.open("changelog", "r")
if file == nil then
return true
end
-- IF IT IS OF AN OLDER VERSION: UPDATE
local versionLine=file:read()
local versionInfo=splitString(versionLine, "=")[2]
file:close()
if versionInfo~=newestVersion then
return true
end
return false
end
-- MAIN UPDATE CODE
local updateConfig = http.get("https://raw.github.com/Ulthean/MLG_Mining/master/updateList")
if not updateConfig then
print("Error connecting to server")
return false
end
local newestVersionInfo=splitString(updateConfig.readLine(), "=")[2]
if requiresUpdate(newestVersionInfo) then
-- BUILD THE LIST OF PROGRAMS TO UPDATE
local numPrograms=tonumber(splitString(updateConfig.readLine(), "=")[2])
local programs={}
for i=1, numPrograms do
local programInfo = updateConfig.readLine()
programs[splitString(programInfo, "=")[1]]=splitString(programInfo, "=")[2]
end
-- REMOVE ALL PROGRAMS, EXCEPT FOR THE CONFIG FILE
for k, v in pairs(programs) do
if k~="config" then
shell.run("rm", k)
end
end
-- ADD THE UPDATED PROGRAMS
for k, v in pairs(programs) do
shell.run("pastebin", "get", v, k)
end
-- PROVIDE UPDATE INFO
local impact=splitString(updateConfig.readLine(), "=")[2]
local advise=splitString(updateConfig.readLine(), "=")[2]
print("---------------------------")
print("MLG MINING: PROGRAM UPDATED")
print("IMPACT: "..impact)
print("ADVISE: "..advise)
print("---------------------------")
else
print("---------------------------")
print("MLG MINING: NO UPDATE FOUND")
print("---------------------------")
end