SHARE
TWEET

1234

a guest Feb 28th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local VERSION_FILE = "/stockpile/version"
  2.  
  3. function parseVersion(v)
  4.   local version = {}
  5.   for i in string.gmatch(v, "%d+") do
  6.     table.insert(version, i)
  7.   end
  8.   return version
  9. end
  10.  
  11. function isNewerVersion(v1, v2)
  12.   for i = 1, #v1 do
  13.     if v1[i] > v2[i] then
  14.       return true
  15.     elseif v1[i] < v2[i] then
  16.       return false
  17.     end
  18.   end
  19.   return false
  20. end
  21.  
  22. local runInstall = false
  23.  
  24. if fs.exists(VERSION_FILE) then
  25.   local handle = fs.open(VERSION_FILE, "r")
  26.   local rawVersion = handle.readAll()
  27.   handle.close()
  28.  
  29.   local currentVersion = parseVersion(rawVersion)
  30.  
  31.   handle = http.get("https://raw.githubusercontent.com/sidoh/stockpile/master" .. VERSION_FILE)
  32.   local rawRemoteVersion = handle.readAll()
  33.   handle.close()
  34.   local remoteVersion = parseVersion(rawRemoteVersion)
  35.  
  36.   if not isNewerVersion(remoteVersion, currentVersion) then
  37.     print("Already at newest version (" .. rawVersion .. ")! Continue update anyway?")
  38.     print("(y)es / (n)o")
  39.     io.write("> ")
  40.    
  41.     while true do
  42.       local sEvent, key = os.pullEvent("key")
  43.    
  44.       if key == keys.y then
  45.         runInstall = true
  46.         break
  47.       elseif key == keys.n then
  48.         print("Aborting.")
  49.         break
  50.       end
  51.     end
  52.   else
  53.     runInstall = true
  54.   end
  55. else
  56.   runInstall = true
  57. end
  58.  
  59. if runInstall = true then
  60.   shell.run("pastebin get wPtGKMam github")
  61.   shell.run("github sidoh stockpile /downloads")
  62.   shell.run("/downloads/stockpile/bootstrap")
  63. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top