SHOW:
|
|
- or go back to the newest paste.
| 1 | -- List of programs to check for updates | |
| 2 | local programs = {
| |
| 3 | - | {name = "Bastion", pastebinCode = "Czt0xUgp"},
|
| 3 | + | {name = "startup", pastebinCode = "jnj8PdyL"},
|
| 4 | - | {name = "RBastion", pastebinCode = "YLMd18xC"},
|
| 4 | + | {name = "Dial", pastebinCode = "b3MuJrtj"},
|
| 5 | - | {name = "FBastion", pastebinCode = "8pF6ds3s"},
|
| 5 | + | {name = "Update", pastebinCode = "BBBJSdLh"},
|
| 6 | - | {name = "GPS", pastebinCode = "d8WLzv0U"},
|
| 6 | + | {name = "Lockdown", pastebinCode = "svrWKbdP"},
|
| 7 | - | {name = "Update", pastebinCode = "8w6Ni2U1"},
|
| 7 | + | {name = "CloseGate", pastebinCode = "mx2mPrhU"}
|
| 8 | - | {name = "Greeting", pastebinCode = "T9Jf2wmy"},
|
| 8 | + | |
| 9 | - | {name = "ArtilleryControl", pastebinCode = "BGUJrLzV"},
|
| 9 | + | |
| 10 | - | {name = "startup", pastebinCode = "u2ey5fkZ"},
|
| 10 | + | |
| 11 | - | {name = "todo", pastebinCode = "tfqc42mJ"},
|
| 11 | + | -- Function to check for updates |
| 12 | - | {name = "Teleport", pastebinCode = "CLpkvMg8"}
|
| 12 | + | local function checkForUpdates(program) |
| 13 | -- Loop through the list of programs | |
| 14 | for i, program in ipairs(programs) do | |
| 15 | -- Check if the file already exists | |
| 16 | - | -- Function to delete existing program files |
| 16 | + | if not fs.exists(program.name) then |
| 17 | - | local function deleteFiles() |
| 17 | + | -- Open a new file with the current program name |
| 18 | local file = fs.open(program.name, "w") | |
| 19 | - | if fs.exists(program.name) then |
| 19 | + | |
| 20 | - | fs.delete(program.name) |
| 20 | + | -- Write a message to the file |
| 21 | - | print("Deleted " .. program.name)
|
| 21 | + | file.write("This is " .. program.name .. ". The pastebin code is " .. program.pastebinCode)
|
| 22 | ||
| 23 | -- Close the file | |
| 24 | file.close() | |
| 25 | end | |
| 26 | - | -- Function to download and update a single program |
| 26 | + | |
| 27 | - | local function updateProgram(program) |
| 27 | + | print("Files have been created.")
|
| 28 | - | print("Updating " .. program.name .. "...")
|
| 28 | + | |
| 29 | print("Checking for updates for " .. program.name .. "...")
| |
| 30 | local response = http.get("https://pastebin.com/raw/" .. program.pastebinCode)
| |
| 31 | if response then | |
| 32 | local remoteVersion = response.readAll() | |
| 33 | response.close() | |
| 34 | local localVersion = fs.exists(program.name) and fs.open(program.name, "r").readAll() or nil | |
| 35 | if localVersion and localVersion ~= remoteVersion then | |
| 36 | - | file.write(remoteVersion) |
| 36 | + | print("Updating " .. program.name .. "...")
|
| 37 | local file = fs.open(program.name, "w") | |
| 38 | file.write(remoteVersion) | |
| 39 | - | print(program.name .. " updated successfully.") |
| 39 | + | file.close() |
| 40 | print(program.name .. " updated successfully.") | |
| 41 | - | print("Failed to update " .. program.name .. ". Check the Pastebin code or your internet connection.")
|
| 41 | + | else |
| 42 | print(program.name .. " is up to date.") | |
| 43 | end | |
| 44 | else | |
| 45 | - | -- Main function to delete all files and download new versions |
| 45 | + | print("Failed to check for updates for " .. program.name)
|
| 46 | end | |
| 47 | - | deleteFiles() -- Delete all existing files first |
| 47 | + | |
| 48 | ||
| 49 | - | updateProgram(program) |
| 49 | + | -- Main function to check for updates for all programs |
| 50 | local function main() | |
| 51 | for _, program in ipairs(programs) do | |
| 52 | checkForUpdates(program) | |
| 53 | end | |
| 54 | end | |
| 55 | - | -- Run main function |
| 55 | + | |
| 56 | main() | |
| 57 | ||
| 58 | - | shell.run("Greeting") |
| 58 | + | os.sleep(1) |
| 59 | os.reboot() |