Обновить ckg.min.lua

This commit is contained in:
p2vman 2025-05-05 09:19:42 +00:00
parent 86ec686ca6
commit b1a341b4e4
1 changed files with 1 additions and 1 deletions

View File

@ -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={"http://193.23.220.51:3000/p2vman/cpkg/raw/branch/main/packages.json","http://193.23.220.51:3000/p2vman/luastd/raw/branch/main/packages.json"}local g="/"local function h()if not fs.exists(e)then return{repos=f}end;local i=fs.open(e,"r")local j=textutils.unserialize(i.readAll())i.close()return j end;local function k(j)local i=fs.open(e,"w")i.write(textutils.serialize(j))i.close()end;local function l(j)if not fs.exists(d)then fs.makeDir(d)end;local m={}for n,o in ipairs(j.repos)do local p=fs.combine(d,"repo_"..n..".json")if fs.exists(p)then local i=fs.open(p,"r")local q=textutils.unserializeJSON(i.readAll())i.close()for r,s in pairs(q)do m[r]=s end else if http.checkURL(o)then print("Fetching index from "..o)local t=".pkg_tmp_repo.json"if fs.exists(t)then fs.delete(t)end;shell.run("wget",o,t)local i=fs.open(t,"r")local q=textutils.unserializeJSON(i.readAll())i.close()fs.delete(t)local u=fs.open(p,"w")u.write(textutils.serializeJSON(q))u.close()for r,s in pairs(q)do m[r]=s end else print("Warning: cannot reach repo "..o)end end end;return m end;local function v(w,x,y)for z,A in ipairs(x)do local o=w.."/"..A;local B=fs.combine(y,A)local C=fs.getDir(B)if not fs.exists(C)then fs.makeDir(C)end;if fs.exists(B)then fs.delete(B)end;shell.run("wget",o,B)end end;local function D(r,E,F)if F[r]then return end;local G=E[r]if not G then local j=h()print("Package not found. Updating repositories...")a.update()E=l(j)G=E[r]if not G then error("Package still not found: "..r)end end;if G.dependencies then for z,H in ipairs(G.dependencies)do D(H,E,F)end end;local y=fs.combine(g,r)if fs.exists(y)then print("Already installed: "..r)F[r]=true;return end;if not fs.exists(c)then fs.makeDir(c)end;local I=fs.combine(c,r)if fs.exists(I)then print("Installing "..r.." from cache...")fs.copy(I,y)else print("Downloading "..r.."...")fs.makeDir(I)v(G.base_url,G.files,I)fs.copy(I,y)end;print("Installed "..r)F[r]=true end;function a.install(r)local j=h()local E=l(j)D(r,E,{})end;function a.fetch(r)local j=h()local E=l(j)local G=E[r]if not G then print("Package not found. Updating repositories...")a.update()E=l(j)G=E[r]if not G then error("Package still not found: "..r)end end;if not fs.exists(c)then fs.makeDir(c)end;local I=fs.combine(c,r)if fs.exists(I)then fs.delete(I)end;fs.makeDir(I)v(G.base_url,G.files,I)print("Fetched "..r.." to cache")end;function a.remove(r)local y=fs.combine(g,r)if fs.exists(y)then fs.delete(y)print("Removed "..r)else print("Package not installed: "..r)end end;function a.list()if not fs.exists(g)then print("No packages installed.")return end;local E=fs.list(g)for z,G in ipairs(E)do if G~="cache"and G~="config.txt"then print(G)end end end;function a.add_repo(o)local j=h()table.insert(j.repos,o)k(j)print("Repository added: "..o)end;function a.list_repos()local j=h()for z,o in ipairs(j.repos)do print(o)end end;function a.clear_repos()k({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 j=h()for n,o in ipairs(j.repos)do if http.checkURL(o)then print("Updating index from "..o)local t=".pkg_tmp_repo.json"if fs.exists(t)then fs.delete(t)end;shell.run("wget",o,t)local i=fs.open(t,"r")local q=textutils.unserializeJSON(i.readAll())i.close()fs.delete(t)local p=fs.combine(d,"repo_"..n..".json")local u=fs.open(p,"w")u.write(textutils.serializeJSON(q))u.close()else print("Warning: cannot reach repo "..o)end end;print("Repository indexes updated!")end;local J={...}local K=J[1]if K=="install"then a.install(J[2])elseif K=="remove"then a.remove(J[2])elseif K=="list"then a.list()elseif K=="fetch"then a.fetch(J[2])elseif K=="clear-cache"then a.clear_cache()elseif K=="add-repo"then a.add_repo(J[2])elseif K=="list-repos"then a.list_repos()elseif K=="clear-repos"then a.clear_repos()elseif K=="update"then a.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={"https://git.eptaproject.space/p2vman/cpkg/raw/branch/main/packages.json","https://git.eptaproject.space/p2vman/luastd/raw/branch/main/packages.json"}local g="/"local function h()if not fs.exists(e)then return{repos=f}end;local i=fs.open(e,"r")local j=textutils.unserialize(i.readAll())i.close()return j end;local function k(j)local i=fs.open(e,"w")i.write(textutils.serialize(j))i.close()end;local function l(j)if not fs.exists(d)then fs.makeDir(d)end;local m={}for n,o in ipairs(j.repos)do local p=fs.combine(d,"repo_"..n..".json")if fs.exists(p)then local i=fs.open(p,"r")local q=textutils.unserializeJSON(i.readAll())i.close()for r,s in pairs(q)do m[r]=s end else if http.checkURL(o)then print("Fetching index from "..o)local t=".pkg_tmp_repo.json"if fs.exists(t)then fs.delete(t)end;shell.run("wget",o,t)local i=fs.open(t,"r")local q=textutils.unserializeJSON(i.readAll())i.close()fs.delete(t)local u=fs.open(p,"w")u.write(textutils.serializeJSON(q))u.close()for r,s in pairs(q)do m[r]=s end else print("Warning: cannot reach repo "..o)end end end;return m end;local function v(w,x,y)for z,A in ipairs(x)do local o=w.."/"..A;local B=fs.combine(y,A)local C=fs.getDir(B)if not fs.exists(C)then fs.makeDir(C)end;if fs.exists(B)then fs.delete(B)end;shell.run("wget",o,B)end end;local function D(r,E,F)if F[r]then return end;local G=E[r]if not G then local j=h()print("Package not found. Updating repositories...")a.update()E=l(j)G=E[r]if not G then error("Package still not found: "..r)end end;if G.dependencies then for z,H in ipairs(G.dependencies)do D(H,E,F)end end;local y=fs.combine(g,r)if fs.exists(y)then print("Already installed: "..r)F[r]=true;return end;if not fs.exists(c)then fs.makeDir(c)end;local I=fs.combine(c,r)if fs.exists(I)then print("Installing "..r.." from cache...")fs.copy(I,y)else print("Downloading "..r.."...")fs.makeDir(I)v(G.base_url,G.files,I)fs.copy(I,y)end;print("Installed "..r)F[r]=true end;function a.install(r)local j=h()local E=l(j)D(r,E,{})end;function a.fetch(r)local j=h()local E=l(j)local G=E[r]if not G then print("Package not found. Updating repositories...")a.update()E=l(j)G=E[r]if not G then error("Package still not found: "..r)end end;if not fs.exists(c)then fs.makeDir(c)end;local I=fs.combine(c,r)if fs.exists(I)then fs.delete(I)end;fs.makeDir(I)v(G.base_url,G.files,I)print("Fetched "..r.." to cache")end;function a.remove(r)local y=fs.combine(g,r)if fs.exists(y)then fs.delete(y)print("Removed "..r)else print("Package not installed: "..r)end end;function a.list()if not fs.exists(g)then print("No packages installed.")return end;local E=fs.list(g)for z,G in ipairs(E)do if G~="cache"and G~="config.txt"then print(G)end end end;function a.add_repo(o)local j=h()table.insert(j.repos,o)k(j)print("Repository added: "..o)end;function a.list_repos()local j=h()for z,o in ipairs(j.repos)do print(o)end end;function a.clear_repos()k({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 j=h()for n,o in ipairs(j.repos)do if http.checkURL(o)then print("Updating index from "..o)local t=".pkg_tmp_repo.json"if fs.exists(t)then fs.delete(t)end;shell.run("wget",o,t)local i=fs.open(t,"r")local q=textutils.unserializeJSON(i.readAll())i.close()fs.delete(t)local p=fs.combine(d,"repo_"..n..".json")local u=fs.open(p,"w")u.write(textutils.serializeJSON(q))u.close()else print("Warning: cannot reach repo "..o)end end;print("Repository indexes updated!")end;local J={...}local K=J[1]if K=="install"then a.install(J[2])elseif K=="remove"then a.remove(J[2])elseif K=="list"then a.list()elseif K=="fetch"then a.fetch(J[2])elseif K=="clear-cache"then a.clear_cache()elseif K=="add-repo"then a.add_repo(J[2])elseif K=="list-repos"then a.list_repos()elseif K=="clear-repos"then a.clear_repos()elseif K=="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