computercraft/lib/lum.lua
2023-10-08 04:14:52 -04:00

42 lines
1.2 KiB
Lua

local target_branch = "main"
local bin_path = "/bin/"
local lib_path = "/lib/"
local startup_path = "/startup/"
settings.define("lum.target_branch", {
description = "Target branch for updates",
type = "string",
default = "main"
})
settings.define("lum.log_level", {
description = "Log Level",
type = "string",
default = "debug"
})
function download_lua(remote_path, local_path)
local url = "https://gitea.layla.gg/layla/computercraft/raw/branch/" .. settings.get("lum.target_branch") .. "/" .. remote_path
if settings.get("lum.log_level") == "debug" then
io.write("Downloading " .. url .. " to " .. local_path .. "\n")
end
local response = http.get(url, nil)
if response.getResponseCode() == 200 then
file = fs.open(local_path, "w")
file.write(response.readAll())
file.close()
else
io.write("Failed to download " .. remote_path .. ".lua\n")
io.write(response)
end
end
function install(package)
io.write("Installing " .. package .. "\n")
download_lua("packages/" .. package .. ".lua", bin_path .. package .. ".lua")
end
function remove(package)
io.write("Removing " .. package .. "\n")
fs.delete(bin_path .. package .. ".lua")
end