summaryrefslogtreecommitdiff
path: root/pm.lua
blob: 69831388ffc721ecebca3d96d394687bbb79acb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- 'package manager'

local rbase = "https://g.gh0.pw/ccprogs/plain/"

local function perr(err,what)
	if err then error(what..": "..err) end
end

local function manifest(pkgname)
	print("fetching manifest of '"..pkgname.."'...")
	local ,err = http.get(rbase..pkgname..".dat")
	perr(err,"http.get")
	local files={}
	local files_present=false
	local deps={}
	for line in res:gmatch"[^\n]+" do
		local op,argstart = line:match "^(%w+)%s+()"
		if op then
			argstr = line:sub(argstart)
			local args = {}
			for arg in argstr:gmatch"[^ ]+" do
				table.insert(args,arg)
			end
			
			if op == "dep" then
				for _,arg in ipairs(args) do deps[arg]=true end
			elseif op == "file" then
				files_present = true
				for _,arg in ipairs(args) do files[arg]=true end
			end
		end
	end
	if not files_present then files[pkgname]=true end
	return {files=files,deps=deps}
end


local function dl(filename)
	local file,err=fs.open("/"..filename..".lua","w")
	if err then error("fs.open "..err) end
	local res,err = http.get("https://g.gh0.pw/ccprogs/plain/"..filename..".lua")
	if err then error("http.get "..err) end
	file.write(res.readAll())
	file.flush()
	file.close()
end

dl(arg[1])