Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
More work on installer
Browse files Browse the repository at this point in the history
  • Loading branch information
ajh123 committed Aug 21, 2022
1 parent e994f1a commit 8658bef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ local preset = {
branch = "main",

-- The local folder to save all the files to (defaults to '/')
path = nil,
path = "/tmp",

-- Function to run before starting the download
start = function()
if not silent then print("Downloading IPvCC...") end
if not silent then print("Downloading IPvCC setup...") end
end,

-- Function to run when the download completes
done = function()
if not silent then print("Done") end
shell.run("/tmp/IPvCC/setup/main.lua")
end
}

Expand Down
35 changes: 35 additions & 0 deletions setup/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
fs.makeDir("GuiH")
local github_api = http.get(
"https://api.github.com/repos/9551-Dev/GuiH/git/trees/main?recursive=1",
_G._GIT_API_KEY and {Authorization = 'token ' .. _G._GIT_API_KEY}
)

local list = textutils.unserialiseJSON(github_api.readAll())
local ls = {}
local len = 0
github_api.close()
for k,v in pairs(list.tree) do
if v.type == "blob" and v.path:lower():match(".+%.lua") then
ls["https://raw.githubusercontent.com/9551-Dev/GuiH/main/"..v.path] = v.path
len = len + 1
end
end
local percent = 100/len
local finished = 0
local size_gained = 0
local downloads = {}
for k,v in pairs(ls) do
table.insert(downloads,function()
local web = http.get(k)
local file = fs.open("/tmp/GuiH/"..v,"w")
file.write(web.readAll())
file.close()
web.close()
finished = finished + 1
local file_size = fs.getSize("/tmp/GuiH/"..v)
size_gained = size_gained + file_size
print("downloading "..v.." "..tostring(math.ceil(finished*percent)).."% "..tostring(math.ceil(file_size/1024*10)/10).."kB total: "..math.ceil(size_gained/1024).."kB")
end)
end
parallel.waitForAll(table.unpack(downloads))
print("Finished downloading GuiH")

0 comments on commit 8658bef

Please sign in to comment.