Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currentVersion = "0"
- local connection = false
- local files = {}
- table.insert(files, {name = "/version", link = "0MzLR5RW"})
- local args = {...}
- if args[1] == nil then
- print("Update : No command entered...")
- elseif args[1] == "client" then
- table.insert(files, {name = "/client.lua", link = "uf8hScVN"})
- table.insert(files, {name = "/startup.lua", link = "etVRTS8Z"})
- elseif args[1] == "server" then
- table.insert(files, {name = "/server.lua", link = "myehJ0nH"})
- table.insert(files, {name = "/startup.lua", link = "vmM0ztz2"})
- monitor = peripheral.wrap("back")
- monitor.clear()
- monitor.setTextColor(colors.white)
- monitor.setTextScale(0.5)
- monitor.setCursorPos(1,1)
- monitor.write("Updating")
- end
- table.insert(files, {name = "/update.lua", link = "75iZjThu"})
- local function downloadFiles(url, path)
- for i = 1, 3 do
- term.setTextColor(colors.green)
- print("Attempting to download : "..path)
- term.setTextColor(colors.white)
- local response = http.get(url)
- if response then
- local data = response.readAll()
- if path then
- local f = io.open(path, "w")
- f:write(data)
- f:close()
- end
- os.sleep(1)
- return true
- end
- end
- return false
- end
- local function checkForUpdates(updateUrl)
- for i = 1, 3 do
- if connection == false then
- local response = http.get(updateUrl)
- if response ~= nil then
- connection = true
- local data = response.readAll()
- if data ~= currentVersion then
- sleep(1)
- print("There is a new version available.")
- sleep(1)
- for k, v in pairs(files) do
- local l = files[k].link
- local n = files[k].name
- if data ~= currentVersion or not fs.exists(n) then
- term.setTextColor(colors.red)
- if fs.exists(n) then
- print("Deleting current : "..n)
- fs.delete(n)
- downloadFiles("https://pastebin.com/raw/"..l, n)
- else
- print("MISSING FILE : "..n)
- downloadFiles("https://pastebin.com/raw/"..l, n)
- end
- end
- end
- term.setTextColor(colors.white)
- end
- end
- end
- end
- end
- if fs.exists(files[1].name) then
- local h = fs.open(files[1].name, "r")
- local text = h.readAll()
- h.close()
- currentVersion = text
- else
- print("No version file in this directory.")
- sleep(1)
- print("Setting version to 0, this will force an update")
- sleep(1)
- end
- checkForUpdates("http://pastebin.com/raw/"..files[1].link)
- if connection then
- print("Your system is up to date!")
- else
- print("Unable to connect to update server.")
- end
- --shell.run("/server")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement