ItsNoah

install

Apr 15th, 2021 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. local tArgs = {...}
  2. local programs = {"setup", "packyourstuff", "exm", "exf", "exfm", "goTo", "getlavaplus", "getlava", "aTreeFarm", "tfl"}
  3. local codes = {"WJydmc9x", "tf0gVZsZ", "0sAmVV2y", "7kt8vN9V", "uRqQmzdZ", "VsCyYRjN", "k1bggX4i", "nFSUKiYE", "JgRgRK5q", "PrHNL39i"}
  4.  
  5. local list = {}
  6. for i=1, #programs do
  7.     list[programs[i]] = codes[i]
  8. end
  9. list["update"] = "5bsg0h5G"
  10.  
  11. local total = 1
  12. local succ = 0
  13. local fail = 0
  14. local fail_list = {}
  15.  
  16. if tArgs[1] == nil then
  17.     term.clear()
  18.     term.setCursorPos(1, 1)
  19.     print("What would you like to install?")
  20.     for i = 1, #programs do
  21.         print("> " .. programs[i])
  22.     end
  23.     print("> (all)")
  24.     tArgs[1] = read()
  25. end
  26.  
  27. if tArgs[1] == "all" then
  28.     total = "all"
  29. end
  30.  
  31. local function update()
  32.     http.request("http://pastebin.com/raw.php?i=5bsg0h5G")
  33.     requesting = true
  34.     while requesting do
  35.         local event, url, sourceText = os.pullEvent()
  36.         if event == "http_success" then
  37.             respondedText = sourceText.readAll()
  38.             fs.delete("update.lua")
  39.             file = fs.open("update.lua", "w")
  40.             file.write(respondedText)
  41.             file.close()
  42.             requesting = false
  43.         else
  44.             requesting = false
  45.         end
  46.     end
  47. end
  48.  
  49. local function request(_name)
  50.     success = 0
  51.     local c = list[_name]
  52.     http.request("https://pastebin.com/raw/" .. c)
  53.     requesting = true
  54.     while requesting do
  55.         local event, url, sourceText = os.pullEvent()
  56.         if event == "http_success" then
  57.             respondedText = sourceText.readAll()
  58.             if respondedText ~= "" then
  59.                 fs.delete(_name..".lua")
  60.                 file = fs.open(_name..".lua", "w")
  61.                 file.write(respondedText)
  62.                 file.close()
  63.                 succ = succ + 1
  64.                 success = 1
  65.             else
  66.                 success = 2
  67.             end
  68.             requesting = false
  69.         else
  70.             success = 3
  71.             fail = fail +1
  72.             fail_list[fail] = _name
  73.             requesting = false
  74.         end
  75.     end
  76.     return success
  77. end
  78.  
  79. local function contains(_table, _val)
  80.     for i = 1, #_table do
  81.         if _table[i] == _val then
  82.             return true
  83.         end
  84.     end
  85.     return false
  86. end
  87.  
  88. local function index(_table, _val)
  89.     for i = 1, #_table do
  90.         if _table[i] == _val then
  91.             return i
  92.         end
  93.     end
  94.     return 0
  95. end
  96.  
  97.  
  98. -----[ start ]-----
  99.  
  100. if tArgs[1] == "update" then
  101.     sleep(1)
  102.     update()
  103.     sleep(1)
  104. else
  105.     term.clear()
  106.     term.setCursorPos(15, 1)
  107.     term.write("Installing...")
  108.  
  109.     sleep(1)
  110.     update()
  111.     sleep(1)
  112.  
  113.     if total == 1 then
  114.         local tsucc = 0
  115.         term.setCursorPos(2, 3)
  116.         term.write("Installing [" .. tArgs[1] .."]...")
  117.         if contains(programs, tArgs[1]) then
  118.             tsucc = request(tArgs[1])
  119.         end
  120.         if tsucc == 1 then
  121.             term.write(" Success!")
  122.         elseif tsucc == 0 then
  123.             term.write(" Skipped!")
  124.         elseif tsucc == 2 then
  125.             term.write(" Invalid!")
  126.         elseif tsucc == 3 then
  127.             term.write(" Failed!")
  128.         end
  129.         term.setCursorPos(1, 4)
  130.     else
  131.         if total == "all" then
  132.             total = #programs
  133.             for i = 1, #programs do
  134.                 term.setCursorPos(1, 3)
  135.                 term.clearLine()
  136.                 term.setCursorPos(2, 3)
  137.                 term.write("[" .. programs[i] .."]...")
  138.                 term.setCursorPos(33, 3)
  139.                 term.write("(" .. i .. "/" .. total .. ")")
  140.                 term.setCursorPos(16, 3)
  141.  
  142.                 local success = request(programs[i])
  143.                 if tsucc == 1 then
  144.                     term.write(" Success!")
  145.                 elseif tsucc == 0 then
  146.                     term.write(" Skipped!")
  147.                 elseif tsucc == 2 then
  148.                     term.write(" Invalid!")
  149.                 elseif tsucc == 3 then
  150.                     term.write(" Failed!")
  151.                 end
  152.             end
  153.  
  154.             term.setCursorPos(12, 1)
  155.             term.write("Installing Done!")
  156.  
  157.             term.setCursorPos(2, 4)
  158.             term.clearLine()
  159.             term.write("Installed (" .. succ .. "/" .. total .. ") successfully!")
  160.             term.setCursorPos(1, 5)
  161.  
  162.             if fail > 0 then
  163.                 term.setCursorPos(2, 6)
  164.                 term.clearLine()
  165.                 term.write("Failed [" .. fail .. "]:")
  166.                 term.setCursorPos(1, 7)
  167.                 if fail < 6 then
  168.                     for f=1, #fail_list do
  169.                         term.setCursorPos(2, f + 7)
  170.                         term.clearLine()
  171.                         term.write("> " .. fail_list[f])
  172.                     end
  173.                 else
  174.                     for f=1, 4 do
  175.                         term.setCursorPos(2, f + 7)
  176.                         term.clearLine()
  177.                         term.write("> " .. fail_list[f])
  178.                     end
  179.                     term.setCursorPos(2, 12)
  180.                     term.clearLine()
  181.                     term.write("> [" .. (fail-4) .. "] more...")
  182.                 end
  183.                 term.setCursorPos(1, 13)
  184.             end
  185.         end
  186.     end
  187. end
Add Comment
Please, Sign In to add comment