Advertisement
Alexr360

Update

Mar 26th, 2024 (edited)
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -- List of programs to check for updates
  2. local programs = {
  3.     {name = "Bastion", pastebinCode = "YLMd18xC"},
  4.     {name = "GPS", pastebinCode = "d8WLzv0U"},
  5.     {name = "Update", pastebinCode = "RAVBceBu"},
  6.     {name = "startup", pastebinCode = "REfxrLkG"},
  7.     {name = "startup", pastebinCode = "REfxrLkG"},
  8.     {name = "ArtillaryControl", pastebinCode = "BGUJrLzV"},
  9.     {name = "StargateLogs", pastebinCode = "eg0sWHxc"}
  10.     -- Add more programs as needed
  11. }
  12.  
  13. -- Function to check for updates
  14. local function checkForUpdates(program)
  15.     -- Loop through the list of programs
  16.     for i, program in ipairs(programs) do
  17.       -- Check if the file already exists
  18.       if not fs.exists(program.name) then
  19.         -- Open a new file with the current program name
  20.         local file = fs.open(program.name, "w")
  21.  
  22.         -- Write a message to the file
  23.         file.write("This is " .. program.name .. ". The pastebin code is " .. program.pastebinCode)
  24.  
  25.         -- Close the file
  26.         file.close()
  27.       end
  28.     end
  29.     print("Files have been created.")
  30.    
  31.     print("Checking for updates for " .. program.name .. "...")
  32.     local response = http.get("https://pastebin.com/raw/" .. program.pastebinCode)
  33.     if response then
  34.         local remoteVersion = response.readAll()
  35.         response.close()
  36.         local localVersion = fs.exists(program.name) and fs.open(program.name, "r").readAll() or nil
  37.         if localVersion and localVersion ~= remoteVersion then
  38.             print("Updating " .. program.name .. "...")
  39.             local file = fs.open(program.name, "w")
  40.             file.write(remoteVersion)
  41.             file.close()
  42.             print(program.name .. " updated successfully.")
  43.         else
  44.             print(program.name .. " is up to date.")
  45.         end
  46.     else
  47.         print("Failed to check for updates for " .. program.name)
  48.     end
  49. end
  50.  
  51. -- Main function to check for updates for all programs
  52. local function main()
  53.     for _, program in ipairs(programs) do
  54.         checkForUpdates(program)
  55.     end
  56. end
  57.  
  58. -- Run main function
  59. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement