Forte40

Extra Turtles - Utility turtles for automating your base

Sep 3rd, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local branch = "master"
  2. if fs.exists(".extur.branch") then
  3.   local f = fs.open(".extur.branch", "r")
  4.   branch = f.readAll()
  5.   f.close()
  6. end  
  7.  
  8. local files = {
  9.   {
  10.     name = "extur-get",
  11.     url = "https://raw.github.com/Forte40/extraturtles/"..branch.."/extur-get.lua"
  12.   },
  13.   {
  14.     name = "startup",
  15.     folder = "disk",
  16.     url = "https://raw.github.com/Forte40/extraturtles/"..branch.."/startup.lua"
  17.   },
  18.   {
  19.     name = "beekeeper",
  20.     folder = "disk",
  21.     url = "https://raw.github.com/Forte40/extraturtles/"..branch.."/beekeeper.lua"
  22.   },
  23. }
  24.  
  25. local scripts = {"Unleashed_1.1.3"}
  26.  
  27. if not http then
  28.   print("No access to web")
  29.   return
  30. end
  31.  
  32. for _, file in ipairs(files) do
  33.   local path
  34.   if file.folder then
  35.     if not fs.exists(file.folder) then
  36.       if file.folder == "disk" then
  37.         print("Place computer or turtle next to disk drive with blank floppy to install")
  38.         return
  39.       else
  40.         fs.makeDir(file.folder)
  41.       end
  42.     end
  43.     path = fs.combine(file.folder, file.name)
  44.   else
  45.     path = file.name
  46.   end
  47.   local currText = ""
  48.   if fs.exists(path) then
  49.     local f = fs.open(path, "r")
  50.     currText = f.readAll()
  51.     f.close()
  52.     io.write("update  ")
  53.   else
  54.     io.write("install ")
  55.   end
  56.   io.write("'"..file.name.."'"..string.rep(" ", math.max(0, 8 - #file.name)))
  57.   if file.folder then
  58.     io.write(" in '"..file.folder.."'"..string.rep(".", math.max(0, 8 - #file.folder)).."...")
  59.   else
  60.     io.write("    .............")
  61.   end
  62.   local request = http.get(file.url)
  63.   if request then
  64.     local response = request.getResponseCode()
  65.     if response == 200 then
  66.       local newText = request.readAll()
  67.       if newText == currText then
  68.         print("skip")
  69.       else
  70.         local f = fs.open(path, "w")
  71.         f.write(newText)
  72.         f.close()
  73.         print("done")
  74.       end
  75.     else
  76.       print(" bad HTTP response code " .. response)
  77.     end
  78.   else
  79.     print(" no request handle")
  80.   end
  81.   os.sleep(0.1)
  82. end
Advertisement
Add Comment
Please, Sign In to add comment