Advertisement
RealChaoz

Auto Update (startup)

Jul 25th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. pastebin=""
  2. backup=""
  3. file=""
  4.  
  5. print("[ Updating script to latest version ]")
  6. if (fs.exists(backup)) then
  7.     print("Old backup file detected, deleting: " .. backup)
  8.     fs.delete(backup)
  9. end
  10. if (fs.exists(file)) then
  11.     print("Creating new backup file: " .. backup)
  12.     fs.move(file, backup)
  13. end
  14. print("Fetching latest (" .. file .. ") version from pastebin: " .. pastebin)
  15. result = shell.run("pastebin", "get " .. pastebin .. " " .. file)
  16. print("Operation finished. Result: ")
  17. if (result) then print("Success")
  18. else print("Failure")
  19. end
  20. print("Attempting to run: " .. file)
  21. if (not fs.exists(file)) then
  22.     print("Error: File not found: " .. file)
  23.     print("Attempting reverting to backup...")
  24.     if (not fs.exists(backup)) then
  25.         print("Fatal error: No backup file found.")
  26.         error("Stopping...")
  27.     end
  28.     fs.copy(backup, file)
  29. end
  30. print("Executing: " .. file)
  31. shell.run(file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement