computercraft/lupdate.lua
2023-10-07 23:25:42 -04:00

34 lines
890 B
Lua

local args = { ... }
local target_branch = "main"
local bin_path = "/bin/"
local program_name = args[1]
if program_name == nil then
print("Usage: lupdate <program_name>")
return
end
response = http.get("https://gitea.layla.gg/layla/computercraft/raw/branch/" .. target_branch .. "/" .. program_name .. ".lua", nil)
io.write("Updating " .. program_name .. ".lua\n")
if response.getResponseCode() == 200 then
file = fs.open(bin_path .. program_name .. ".lua", "w")
file.write(response.readAll())
file.close()
-- check if program is in path
if not shell.resolveProgram(program_name) then
io.write("Program not in path, adding to path\n")
shell.setPath(shell.path() .. ":" .. bin_path)
end
io.write("Updated " .. program_name .. ".lua\n")
else
io.write("Failed to update " .. program_name .. ".lua\n")
io.write(response)
end