OC-XPM/src/install.lua

59 lines
1.3 KiB
Lua

local function resolve_deps(pkgname, deps)
local pkg = cache.check_cache(pkgname)
if not pkg then
io.stderr:write("Package not found.\n")
os.exit(1)
end
local info = pkg.pkginfo
if (info.dependencies) then
for k, v in pairs(info.dependencies) do
if not cache.getlocal()[k] and not deps[k] then
resolve_deps(k, deps)
deps[#deps+1] = k
deps[k] = true
end
end
end
end
local function install_pkg(pkgname, prefix)
prefix = prefix or config.prefix
-- Look up in cache
local pkg = cache.check_cache(pkgname)
if not pkg then
io.stderr:write("Package not found.\n")
os.exit(1)
end
pkg.tracked_files = {}
for k, v in pairs(pkg.pkginfo.files) do
if (v:sub(1, 2) ~= "//") then
v = config.prefix .. v
else
v = v:sub(2)
end
if (k:sub(1, 1) ~= ":") then
--print(k)
local fp = k:sub(#k:match("^(.+)/.+$")+1)
fs.makeDirectory(v)
--print(v..fp)
local f = io.open(v..fp, "w")
f:write(github_download(pkg.repo, k))
f:close()
pkg.tracked_files[#pkg.tracked_files+1] = v .. fp
else
print(k)
end
end
return pkg
end
local function pkg_postinstall(pkg, info)
cache.update_local_cache(pkg, info)
local pkgi = cache.getlocal()[pkg].pkginfo
if (pkgi.postinstall) then
local pi = pkgi.postinstall
for i=1, #pi do
os.execute(pi[i])
end
end
end