-- Desc: Lum Package Manager -- Auth: Layla Manley -- Link: https://gitea.layla.gg/layla/computercraft 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") local dir = bin_path local package_dir = "packages/" --if package starts with lib then remove lib if string.sub(package, 1, 3) == "lib" then package = string.sub(package, 4) dir = lib_path package_dir = "lib/" end download_lua(package_dir .. package .. ".lua", dir .. package .. ".lua") if dir == lib_path then os.loadAPI(lib_path .. package .. ".lua") end end function remove(package) io.write("Removing " .. package .. "\n") local dir = bin_path --if package starts with lib then remove lib if string.sub(package, 1, 3) == "lib" then package = string.sub(package, 5) dir = lib_path end fs.delete(dir .. package .. ".lua") end