RedTech0Inc

MCNet Installer

Jun 30th, 2025 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.71 KB | Gaming | 0 0
  1. function githubUrl(owner,repo,path)
  2.     local path = path or ""
  3.     return 'https://api.github.com/repos/'..owner..'/'..repo..'/contents/'..path
  4. end
  5.  
  6. local function download(url,GITHUB_TOKEN)
  7.     local handle, err, err_handle
  8.     if GITHUB_TOKEN then
  9.         handle, err, err_handle = http.get(url,{
  10.             ["Authorization"] = "token " .. GITHUB_TOKEN,
  11.             ["User-Agent"] = "mcNet-Installer"
  12.         })
  13.     else
  14.         handle, err, err_handle = http.get(url)
  15.     end
  16.  
  17.     if not handle then
  18.         printError(err_handle and err_handle.readAll() or "-")
  19.         error(err, 0)
  20.     end
  21.  
  22.     return handle.readAll()
  23. end
  24.  
  25.  
  26. function downloadRepo(path,url,GITHUB_TOKEN)
  27.     path = path or ""
  28.     local paths = textutils.unserialiseJSON(download(url,GITHUB_TOKEN))
  29.     for _,p in pairs(paths) do
  30.         print(p.path)
  31.         if p.download_url then
  32.             local h = fs.open(path..p.path,"w")
  33.             h.write(download(p.download_url, GITHUB_TOKEN))
  34.             h.close()
  35.         else
  36.             downloadRepo(path,p.url)
  37.         end
  38.     end
  39. end
  40.  
  41. local function readInput(strings,arrow)
  42.     arrow = arrow or ">"
  43.  
  44.     for i=1,#strings do
  45.         print(tostring(strings[i]))
  46.     end
  47.     local _,y =term.getCursorPos()
  48.     term.write(tostring(arrow))
  49.     local input = io.read()
  50.     term.setCursorPos(1,y+1)
  51.  
  52.     return input
  53. end
  54.  
  55. local function programEnd(token)
  56.     if token then
  57.         local input = readInput({"do you want me to remember this token: "..string.sub(token, 1, 4).."..."..string.sub(token, -4).."? under setting 'github.token'","this setting will be deleted together with the installer"},"y/n:")
  58.         if string.find(input,"y",nil,true) then
  59.             settings.set("github.token",token)
  60.             settings.save()
  61.         end
  62.     end
  63.     if token then
  64.         print("to protect you secrete token this chat will auto wipe in 1 seconds")
  65.         sleep(1)
  66.         term.clear()
  67.         term.setCursorPos(1,1)
  68.     end
  69. end
  70.  
  71. print("This is the mcNET installer to install certain assets please select what asset to install")
  72. print("-'D'   : DNSServer (will delete all other files)")
  73. print("-'C'   : Client")
  74. print("-'S'   : Server (will delete all other files)")
  75. print("-'E'   : deinstall this Installer")
  76. print("- other: exits installer")
  77.  
  78. local _,y =term.getCursorPos()
  79. term.write("D/C/S/E:")
  80. local input = io.read()
  81. term.setCursorPos(1,y+1)
  82. input = string.lower(input)
  83.  
  84. local confirmed, token
  85.  
  86. if settings.get("github.token") and input ~= "e" then
  87.     token = settings.get("github.token")
  88.     local input = readInput({"you have provided a token:"..string.sub(token, 1, 4).."..."..string.sub(token, -4),"do you want to reset it?"},"y/n:")
  89.     if string.find(input,"y",nil,true) then
  90.         settings.unset("github.token")
  91.         settings.save()
  92.     end
  93.     token = nil
  94.     print()
  95. end
  96.  
  97. while not (confirmed or token)and input ~= "e" do
  98.     token = readInput({"please enter your github token for a higher rate limit (5,000 requests/hour)","press enter if you don't want to do this"})
  99.     if #token < 1 then
  100.         print("warning you are using unauthenticated download requests")
  101.         print("this means you can only do 60 requests / hour")
  102.         confirmed = true
  103.         token = nil
  104.     else
  105.         local input = readInput({"is this your token? "..string.sub(token, 1, 4).."..."..string.sub(token, -4)},"y/n:")
  106.         if string.find(input,"y",nil,true) then
  107.             confirmed = true
  108.         end
  109.     end
  110. end
  111. if token and input ~= "e" then
  112.     print()
  113.     print("using github token: "..string.sub(token, 1, 4).."..."..string.sub(token, -4))
  114. end
  115. print()
  116.  
  117. if input == "d" then
  118.     for _,i in pairs(fs.list("")) do
  119.         print(i)
  120.         if i ~= "rom" then
  121.             fs.delete(i)
  122.         end
  123.     end
  124.  
  125.     downloadRepo("",githubUrl("Redtech0inc","MCNet","mcNet/dnsServer-Stuff"),token)
  126.  
  127.     for _,i in pairs(fs.list("mcNet/dnsServer-Stuff")) do
  128.         print(i)
  129.         local lasPathDiv = 0
  130.         while string.find(i,"/",lasPathDiv+1,true) do
  131.             local pathDiv = string.find(i,"/",lasPathDiv+1,true)
  132.             if pathDiv then lasPathDiv = pathDiv end
  133.         end
  134.         local path = string.sub(i,lasPathDiv+1,#i)
  135.         fs.move("mcNet/dnsServer-Stuff/"..path,path)
  136.     end
  137.     fs.delete("mcNet/")
  138.  
  139.     fs.delete(shell.getRunningProgram())
  140.  
  141.     shell.run("initDns.lua")
  142. elseif input == "c" then
  143.     print("enter the name of the directory that you want the client to be installed in")
  144.     local _,y =term.getCursorPos()
  145.     term.write("> ")
  146.     local name = io.read()
  147.     term.setCursorPos(1,y+1)
  148.  
  149.     if #name < 1 then
  150.         name = "mcNet"
  151.     end
  152.  
  153.     downloadRepo("temporary/",githubUrl("Redtech0inc","MCNet","mcNet/client-stuff"),token)
  154.  
  155.  
  156.     fs.delete(name.."/")
  157.  
  158.     fs.move("temporary/mcNet/client-stuff/*",name.."/")
  159.  
  160.     fs.delete("temporary/")
  161.  
  162.     fs.makeDir(name.."/libs")
  163.     fs.makeDir(name.."/pages")
  164.  
  165.     fs.move(name.."/openUILib.lua",name.."/libs/openUILib.lua")
  166.     fs.move(name.."/logo.nfp",name.."/libs/logo.nfp")
  167.  
  168.     print("do you want to deinstall the installer?")
  169.     local _,y =term.getCursorPos()
  170.     term.write("y/n:")
  171.     local input = io.read()
  172.     term.setCursorPos(1,y+1)
  173.     if string.find(input,"y",nil,true) then
  174.         fs.delete(shell.getRunningProgram())
  175.     end
  176.  
  177.     programEnd(token)
  178.  
  179.     print("do you want to run the program now?")
  180.     local _,y =term.getCursorPos()
  181.     term.write("y/n:")
  182.     local input = io.read()
  183.     term.setCursorPos(1,y+1)
  184.     if string.find(input,"y",nil,true) then
  185.         shell.run(name.."/mcNet-Client.lua")
  186.     end
  187. elseif input == "s" then
  188.     for _,i in pairs(fs.list("")) do
  189.         print(i)
  190.         if i ~= "rom" then
  191.             fs.delete(i)
  192.         end
  193.     end
  194.  
  195.     downloadRepo("",githubUrl("Redtech0inc","MCNet","mcNet/serverFramework"),token)
  196.  
  197.     for _,i in pairs(fs.list("mcNet/serverFramework")) do
  198.         print(i)
  199.         local lasPathDiv = 0
  200.         while string.find(i,"/",lasPathDiv+1,true) do
  201.             local pathDiv = string.find(i,"/",lasPathDiv+1,true)
  202.             if pathDiv then lasPathDiv = pathDiv end
  203.         end
  204.         local path = string.sub(i,lasPathDiv+1,#i)
  205.         fs.move("mcNet/serverFramework/"..path,path)
  206.     end
  207.     fs.delete("mcNet/")
  208.  
  209.     fs.delete(shell.getRunningProgram())
  210.  
  211.     print("do you want to run the program now?")
  212.     local _,y =term.getCursorPos()
  213.     term.write("y/n:")
  214.     local input = io.read()
  215.     term.setCursorPos(1,y+1)
  216.     if string.find(input,"y",nil,true) then
  217.         shell.run("initServer.lua")
  218.     end
  219. elseif input == "e" then
  220.     fs.delete(shell.getRunningProgram())
  221.     if token then
  222.         settings.unset("github.token")
  223.         settings.save()
  224.     end
  225. end
Advertisement
Add Comment
Please, Sign In to add comment