update min file
This commit is contained in:
parent
4f545783ac
commit
e92510f70d
|
@ -0,0 +1,4 @@
|
||||||
|
Install command
|
||||||
|
```
|
||||||
|
wget http://193.23.220.51:3000/p2vman/cpkg/raw/branch/main/ckg.min.lua ckg.lua
|
||||||
|
```
|
|
@ -1,4 +1,4 @@
|
||||||
local a={}local b="/ckg"local c=fs.combine(b,"cache")local d=fs.combine(c,"repos")local e=fs.combine(b,"config.txt")local f={"https://example.com/repo/packages.json"}local function g()if not fs.exists(e)then return{repos=f}end;local h=fs.open(e,"r")local i=textutils.unserialize(h.readAll())h.close()return i end;local function j(i)local h=fs.open(e,"w")h.write(textutils.serialize(i))h.close()end;local function k(i)if not fs.exists(d)then fs.makeDir(d)end;local l={}for m,n in ipairs(i.repos)do local o=fs.combine(d,"repo_"..m..".json")if fs.exists(o)then local h=fs.open(o,"r")local p=textutils.unserializeJSON(h.readAll())h.close()for q,r in pairs(p)do l[q]=r end else if http.checkURL(n)then print("Fetching index from "..n)local s=".pkg_tmp_repo.json"if fs.exists(s)then fs.delete(s)end;shell.run("wget",n,s)local h=fs.open(s,"r")local p=textutils.unserializeJSON(h.readAll())h.close()fs.delete(s)local t=fs.open(o,"w")t.write(textutils.serializeJSON(p))t.close()for q,r in pairs(p)do l[q]=r end else print("Warning: cannot reach repo "..n)end end end;return l end;local function u(v,w,x)for y,z in ipairs(w)do local n=v.."/"..z;local A=fs.combine(x,z)local B=fs.getDir(A)if not fs.exists(B)then fs.makeDir(B)end;if fs.exists(A)then fs.delete(A)end;shell.run("wget",n,A)end end;local function C(q,D,E)if E[q]then return end;local F=D[q]if not F then error("Package not found: "..q)end;if F.dependencies then for y,G in ipairs(F.dependencies)do C(G,D,E)end end;local x=fs.combine(b,q)if fs.exists(x)then print("Already installed: "..q)E[q]=true;return end;if not fs.exists(c)then fs.makeDir(c)end;local H=fs.combine(c,q)if fs.exists(H)then print("Installing "..q.." from cache...")fs.copy(H,x)else print("Downloading "..q.."...")fs.makeDir(H)u(F.base_url,F.files,H)fs.copy(H,x)end;print("Installed "..q)E[q]=true end;function CKG.install(q)local i=g()local D=k(i)C(q,D,{})end;function CKG.fetch(q)local i=g()local D=k(i)local F=D[q]if not F then error("Package not found: "..q)end;if not fs.exists(c)then fs.makeDir(c)end;local H=fs.combine(c,q)if fs.exists(H)then fs.delete(H)end;fs.makeDir(H)u(F.base_url,F.files,H)print("Fetched "..q.." to cache")end;function CKG.remove(q)local x=fs.combine(b,q)if fs.exists(x)then fs.delete(x)print("Removed "..q)else print("Package not installed: "..q)end end;function CKG.list()if not fs.exists(b)then print("No packages installed.")return end;local D=fs.list(b)for y,F in ipairs(D)do if F~="cache"and F~="config.txt"then print(F)end end end;function CKG.add_repo(n)local i=g()table.insert(i.repos,n)j(i)print("Repository added: "..n)end;function CKG.list_repos()local i=g()for y,n in ipairs(i.repos)do print(n)end end;function CKG.clear_repos()j({repos=f})print("Repositories reset to default")end;function CKG.clear_cache()if fs.exists(c)then fs.delete(c)print("Cache cleared")else print("Cache is already empty")end end;function CKG.update()if fs.exists(d)then fs.delete(d)end;fs.makeDir(d)local i=g()for m,n in ipairs(i.repos)do if http.checkURL(n)then print("Updating index from "..n)local s=".pkg_tmp_repo.json"if fs.exists(s)then fs.delete(s)end;shell.run("wget",n,s)local h=fs.open(s,"r")local p=textutils.unserializeJSON(h.readAll())h.close()fs.delete(s)local o=fs.combine(d,"repo_"..m..".json")local t=fs.open(o,"w")t.write(textutils.serializeJSON(p))t.close()else print("Warning: cannot reach repo "..n)end end;print("Repository indexes updated!")end;local I={...}local J=I[1]if J=="install"then CKG.install(I[2])elseif J=="remove"then CKG.remove(I[2])elseif J=="list"then CKG.list()elseif J=="fetch"then CKG.fetch(I[2])elseif J=="clear-cache"then CKG.clear_cache()elseif J=="add-repo"then CKG.add_repo(I[2])elseif J=="list-repos"then CKG.list_repos()elseif J=="clear-repos"then CKG.clear_repos()elseif J=="update"then CKG.update()else print([[
|
local a={}local b="/ckg"local c=fs.combine(b,"cache")local d=fs.combine(c,"repos")local e=fs.combine(b,"config.txt")local f={"http://193.23.220.51:3000/p2vman/cpkg/raw/branch/main/packages.json"}local function g()if not fs.exists(e)then return{repos=f}end;local h=fs.open(e,"r")local i=textutils.unserialize(h.readAll())h.close()return i end;local function j(i)local h=fs.open(e,"w")h.write(textutils.serialize(i))h.close()end;local function k(i)if not fs.exists(d)then fs.makeDir(d)end;local l={}for m,n in ipairs(i.repos)do local o=fs.combine(d,"repo_"..m..".json")if fs.exists(o)then local h=fs.open(o,"r")local p=textutils.unserializeJSON(h.readAll())h.close()for q,r in pairs(p)do l[q]=r end else if http.checkURL(n)then print("Fetching index from "..n)local s=".pkg_tmp_repo.json"if fs.exists(s)then fs.delete(s)end;shell.run("wget",n,s)local h=fs.open(s,"r")local p=textutils.unserializeJSON(h.readAll())h.close()fs.delete(s)local t=fs.open(o,"w")t.write(textutils.serializeJSON(p))t.close()for q,r in pairs(p)do l[q]=r end else print("Warning: cannot reach repo "..n)end end end;return l end;local function u(v,w,x)for y,z in ipairs(w)do local n=v.."/"..z;local A=fs.combine(x,z)local B=fs.getDir(A)if not fs.exists(B)then fs.makeDir(B)end;if fs.exists(A)then fs.delete(A)end;shell.run("wget",n,A)end end;local function C(q,D,E)if E[q]then return end;local F=D[q]if not F then local i=g()print("Package not found. Updating repositories...")a.update()D=k(i)F=D[q]if not F then error("Package still not found: "..q)end end;if F.dependencies then for y,G in ipairs(F.dependencies)do C(G,D,E)end end;local x=fs.combine(b,q)if fs.exists(x)then print("Already installed: "..q)E[q]=true;return end;if not fs.exists(c)then fs.makeDir(c)end;local H=fs.combine(c,q)if fs.exists(H)then print("Installing "..q.." from cache...")fs.copy(H,x)else print("Downloading "..q.."...")fs.makeDir(H)u(F.base_url,F.files,H)fs.copy(H,x)end;print("Installed "..q)E[q]=true end;function a.install(q)local i=g()local D=k(i)C(q,D,{})end;function a.fetch(q)local i=g()local D=k(i)local F=D[q]if not F then print("Package not found. Updating repositories...")a.update()D=k(i)F=D[q]if not F then error("Package still not found: "..q)end end;if not fs.exists(c)then fs.makeDir(c)end;local H=fs.combine(c,q)if fs.exists(H)then fs.delete(H)end;fs.makeDir(H)u(F.base_url,F.files,H)print("Fetched "..q.." to cache")end;function a.remove(q)local x=fs.combine(b,q)if fs.exists(x)then fs.delete(x)print("Removed "..q)else print("Package not installed: "..q)end end;function a.list()if not fs.exists(b)then print("No packages installed.")return end;local D=fs.list(b)for y,F in ipairs(D)do if F~="cache"and F~="config.txt"then print(F)end end end;function a.add_repo(n)local i=g()table.insert(i.repos,n)j(i)print("Repository added: "..n)end;function a.list_repos()local i=g()for y,n in ipairs(i.repos)do print(n)end end;function a.clear_repos()j({repos=f})print("Repositories reset to default")end;function a.clear_cache()if fs.exists(c)then fs.delete(c)print("Cache cleared")else print("Cache is already empty")end end;function a.update()if fs.exists(d)then fs.delete(d)end;fs.makeDir(d)local i=g()for m,n in ipairs(i.repos)do if http.checkURL(n)then print("Updating index from "..n)local s=".pkg_tmp_repo.json"if fs.exists(s)then fs.delete(s)end;shell.run("wget",n,s)local h=fs.open(s,"r")local p=textutils.unserializeJSON(h.readAll())h.close()fs.delete(s)local o=fs.combine(d,"repo_"..m..".json")local t=fs.open(o,"w")t.write(textutils.serializeJSON(p))t.close()else print("Warning: cannot reach repo "..n)end end;print("Repository indexes updated!")end;local I={...}local J=I[1]if J=="install"then a.install(I[2])elseif J=="remove"then a.remove(I[2])elseif J=="list"then a.list()elseif J=="fetch"then a.fetch(I[2])elseif J=="clear-cache"then a.clear_cache()elseif J=="add-repo"then a.add_repo(I[2])elseif J=="list-repos"then a.list_repos()elseif J=="clear-repos"then a.clear_repos()elseif J=="update"then a.update()else print([[
|
||||||
Usage:
|
Usage:
|
||||||
ckg install <name> Install a package
|
ckg install <name> Install a package
|
||||||
ckg remove <name> Remove a package
|
ckg remove <name> Remove a package
|
||||||
|
|
Loading…
Reference in New Issue