t8rt0t

schemTurtleInstaller1.0.lua

Mar 13th, 2024 (edited)
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. local VERSION = 0.102
  2. local thisVersion = 0.0
  3. local moduleVersions = {}
  4. if fs.exists("versions.json") then
  5.     local file = fs.open("versions.json","r")
  6.     local data = textutils.unserialiseJSON(file.readAll())
  7.     file.close()
  8.     if data then moduleVersions = data end
  9. end
  10. thisVersion = moduleVersions["VERSION"] or thisVersion
  11. if thisVersion >= VERSION then return end
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. term.setTextColor(colors.blue)
  15. print("SCHEM TURTLE INSTALLER",VERSION)
  16. --FCK PASTEBIN
  17. term.setTextColor(colors.white)
  18. print("---------------------------")
  19. local modules = {
  20.     ["apis/stats.lua"]={"pavY2TuB",0.01},
  21.     ["apis/refuel.lua"]={"H9gy2NR1",0.10},
  22.     ["apis/mine.lua"]={"dYAtCsDW",0.02},
  23.     ["apis/turt.lua"]={"K4WXuZY3",0.01},
  24.     ["apis/pattern.lua"]={"yW8jFeZk",1.00},
  25.     ["mine.lua"]={"kMQNPYyh",0.02},
  26.     ["names.json"]={"JegectTG",0.01},
  27.     ["startup/.updates.lua"]={"266b45Vr",0.03},
  28.     ["ore_priority.json"]={"utRhXMhL",0.01},
  29.     ["apis/names.lua"]={"MY23L2Cf",0.06},
  30.     ["apis/docs.lua"]={"97XNLNEw",0.02},
  31.     ["apis/schem.lua"]={"QePY5dHT",0.01},
  32.     ["apis/libs/zzlib.lua"]={"A7SE0U1z",0.02},
  33.     ["apis/libs/inflateBit32.lua"]={"DhJpTgbG",0.01},
  34.     ["apis/screen.lua"]={"qudBZVpH",1.00},
  35.     ["apis/encryption.lua"]={"0eYmhPMt",1.00}
  36. }
  37.  
  38. local patterns = {
  39.     ["test_pattern"] = "U6y91X5v",
  40.     ["circle15"] = "mDBsciBr",
  41.     ["amogus"] = "0zW5dFmS"
  42. }
  43.  
  44. local function downloadModule(pastebinCode,name)
  45.     if not pastebinCode or not name then return end
  46.     term.setTextColor(colors.yellow)
  47.     local x,y = term.getSize()
  48.     for i=3,y do
  49.         term.setCursorPos(1,i)
  50.         term.clearLine()
  51.     end
  52.     term.setCursorPos(1,3)
  53.     if fs.exists("downloads/"..name) then fs.delete("downloads/"..name) end
  54.     print("Retrieving ".. string.gsub(name,"%.%a+",""))
  55.     shell.run("pastebin get "..pastebinCode.." downloads/"..name)
  56.     if not fs.exists("downloads/"..name) then
  57.         term.setTextColor(colors.red)
  58.         print("Error retrieving module",name)
  59.         print("Cancelling update")
  60.         error()
  61.     else
  62.         term.setTextColor(colors.green)
  63.         print("Successfully downloaded module",name)
  64.     end
  65. end
  66.  
  67. local function replaceModule(name)
  68.     if not name or not fs.exists("downloads/"..name) then return end
  69.     local x,y = term.getSize()
  70.     for i=3,y do
  71.         term.setCursorPos(1,i)
  72.         term.clearLine()
  73.     end
  74.     term.setCursorPos(1,3)
  75.     term.setTextColor(colors.yellow)
  76.     if fs.exists(name) then
  77.         print("Module",name,"already exists, removing it now")
  78.         fs.delete(name)
  79.     end
  80.     fs.move("downloads/"..name,name)
  81.     term.setTextColor(colors.green)
  82.     print("Successfully replaced module",name)
  83. end
  84.  
  85. for k,v in pairs(modules) do
  86.     if not tonumber(moduleVersions[k]) or moduleVersions[k] < v[2] then
  87.         downloadModule(v[1],k)
  88.     end
  89. end
  90. for k,v in pairs(patterns) do
  91.     downloadModule(v,"patterns/".. k ..".txt")
  92. end
  93. for k,v in pairs(modules) do
  94.     moduleVersions[k] = v[2]
  95.     replaceModule(k)
  96. end
  97. for k,v in pairs(patterns) do
  98.     replaceModule("patterns/"..k .. ".txt")
  99. end
  100.  
  101. if not os.getComputerLabel() then
  102.     print("Fetching new label")
  103.     local sectionChar = string.sub(utf8.char(167),2,2)
  104.     local file = fs.open("names.json","r")
  105.     local data = textutils.unserialiseJSON(file.readAll())
  106.     file.close()
  107.     local color = string.format("%x",math.random(0,15))
  108.     os.setComputerLabel(sectionChar..color..data[math.random(#data)])
  109. end
  110.  
  111. os.loadAPI("apis/stats.lua")
  112. stats.write("version",VERSION)
  113. moduleVersions["VERSION"] = VERSION
  114.  
  115. if fs.exists("versions.json") then fs.delete("versions.json") end
  116. local file = fs.open("versions.json","w")
  117. file.write(textutils.serialiseJSON(moduleVersions))
  118. file.close()
  119. --local stats = require("statsAPI")
  120. --stats.write("version",VERSION)
Advertisement
Add Comment
Please, Sign In to add comment