Advertisement
dapiedude_

Mining Turtle - Check for jakeExcavate Updates

Apr 27th, 2024 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. -- Constants for the update process
  2. local pastebinCode = "gQV6Jvhv" -- Replace with your actual Pastebin code
  3. local scriptName = "jakeExcavate"
  4. local version = 0.1 -- Increment this version in your Pastebin script when updated
  5.  
  6. -- Function to download and update from Pastebin
  7. function updateFromPastebin()
  8. local response = http.get("https://pastebin.com/raw/" .. pastebinCode)
  9. if response then
  10. local scriptContent = response.readAll()
  11. response.close()
  12.  
  13. local file = fs.open(scriptName, "w")
  14. file.write(scriptContent)
  15. file.close()
  16.  
  17. print(scriptName.. " - Update downloaded. Restarting script...")
  18. os.sleep(1) -- Short pause before reboot
  19. os.reboot()
  20. else
  21. print("Failed to check for updates.")
  22. end
  23. end
  24.  
  25. -- Function to check for new updates and apply them
  26. function checkForUpdates()
  27. local response = http.get("https://pastebin.com/raw/" .. pastebinCode)
  28. if response then
  29. local scriptContent = response.readAll()
  30. response.close()
  31.  
  32. -- Check if the first line in the updated file contains a new version number
  33. local remoteVersion = tonumber(string.match(scriptContent, "%-%- Version: (%d+%.%d+)"))
  34. if remoteVersion and remoteVersion > version then
  35. print(scriptName.. " - New version found: " .. remoteVersion)
  36. updateFromPastebin()
  37. else
  38. print(scriptName.. " - Running the latest version.")
  39. end
  40. else
  41. print("Failed to connect to Pastebin for update check.")
  42. end
  43. end
  44.  
  45. -- Call this function at the start of your script
  46. checkForUpdates()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement