Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions unicorn/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local unicorn = {}
unicorn.core = dofile("/lib/unicorn/core.lua")
unicorn.util = dofile("/lib/unicorn/util.lua")
unicorn.remote = dofile("/lib/unicorn/remote.lua")

return unicorn
30 changes: 30 additions & 0 deletions unicorn/remote.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---@description Support for using package remotes.
-- @module unicorn.remote

local unicorn = {}
unicorn.core = dofile("/lib/unicorn/core.lua")
unicorn.util = dofile("/lib/unicorn/util.lua")
unicorn.remote = {}

function unicorn.remote.install(package_name)
for _,v in pairs(fs.list("/etc/unicorn/remotes/")) do
local v = fs.open("/etc/unicorn/remotes/"..v, "r")
local v = v.readLine()
local v = v:gsub("https://", "") -- have to remove the https:// prefix because fs.combine does weird stuff with it if it's left in
local v = fs.combine(v, package_name..".lua")
v = 'https://'..v
response, httpError = unicorn.util.smartHttp(v)
if httpError then
if httpError == "Not Found" then
-- do nothing, continue with the loop
else
error("HTTP request to "..v.." failed with error "..httpError)
end
end
unicorn.util.fileWrite(response, "/tmp/"..package_name)
unicorn.core.install(dofile("/tmp/"..package_name))
end
end

return unicorn.remote

3 changes: 1 addition & 2 deletions unicorn/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function unicorn.util.smartHttp(sUrl)
response.close()
return sResponse
else
error("HTTP failed: "..httpError)
return false
return false, httpError
end
end

Expand Down