Advertisement
Ocawesome101

SoLMISS Installer v2

May 17th, 2023 (edited)
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local mode = (select(1, ...) or "--client"):sub(3)
  2.  
  3. local function color(...)
  4.   for i, arg in ipairs({...}) do
  5.     if type(arg) == "number" then
  6.       term.setTextColor(arg)
  7.     else
  8.       write(arg)
  9.     end
  10.   end
  11. end
  12.  
  13. term.clear()
  14. term.setCursorPos(1,1)
  15. color(colors.yellow, "SoLMISS Installer\n")
  16. if mode ~= "client" and mode ~= "server" then
  17.   printError("invalid mode '"..mode.."'; must be 'client' or 'server'")
  18.   return
  19. end
  20. color(colors.white, "Running in ", colors.lightBlue, mode, colors.white, " mode\n")
  21.  
  22. local url = "https://raw.githubusercontent.com/ocawesome101/solmiss/primary/"
  23.  
  24. local function dl(f)
  25.   local hand, err = http.get(url..f, nil, true)
  26.   if not hand then
  27.     return
  28.   end
  29.  
  30.   local data = hand.readAll()
  31.   hand.close()
  32.  
  33.   return data
  34. end
  35.  
  36. color(colors.white, "Downloading files... ")
  37. local common = dl("solmiss/common.lua")
  38. local special = dl(mode == 'server' and "server.lua" or "client.lua")
  39. if not (common and special) then
  40.   printError("failed")
  41.   return
  42. end
  43.  
  44. color(colors.lime, "success\n")
  45.  
  46. fs.makeDir("/solmiss")
  47. io.open("/solmiss/common.lua", "w"):write(common):close()
  48. io.open("/startup.lua", "w"):write(special):close()
  49.  
  50. local function at(x, y, c)
  51.   term.setCursorPos(x, y)
  52.   term.setTextColor(c)
  53.   return term
  54. end
  55.  
  56. local function progress(y, a, b)
  57.   local progress = a/100
  58.   if b then progress = a/b end
  59.  
  60.   local w = term.getSize()
  61.   at(1, y, colors.yellow).write("[")
  62.   at(2, y, colors.white).write(("#"):rep(math.ceil(progress * (w - 2))))
  63.   at(w, y, colors.yellow).write("]")
  64.   term.setTextColor(colors.white)
  65. end
  66.  
  67. color(colors.white, "Done. Restarting into setup screen.\n")
  68. local finish = os.epoch("utc") + 3000
  69. local _, y = term.getCursorPos()
  70. while os.epoch("utc") < finish do
  71.   sleep(0)
  72.   progress(y, os.epoch("utc") - finish + 3000, 3000)
  73. end
  74.  
  75. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement