From 40d366ce69bf3fd7ced7aa8458e33f9705ec642a Mon Sep 17 00:00:00 2001 From: p2vman Date: Sat, 26 Apr 2025 17:09:32 +0300 Subject: [PATCH] add std --- ckg.min.lua | 2 +- src/ckg.lua | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ckg.min.lua b/ckg.min.lua index 500f69e..8a38c8a 100644 --- a/ckg.min.lua +++ b/ckg.min.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={"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([[ +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 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: ckg install Install a package ckg remove Remove a package diff --git a/src/ckg.lua b/src/ckg.lua index 723dd24..8d1cf8c 100644 --- a/src/ckg.lua +++ b/src/ckg.lua @@ -10,7 +10,8 @@ local CACHE_DIR = fs.combine(INSTALL_DIR, "cache") local REPO_CACHE_DIR = fs.combine(CACHE_DIR, "repos") local CONFIG_FILE = fs.combine(INSTALL_DIR, "config.txt") local DEFAULT_REPOS = { - "http://193.23.220.51:3000/p2vman/cpkg/raw/branch/main/packages.json" + "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 function load_config()