From ed8aca42e0d43debf47dad9c5f0ab2dfbd6c1e70 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 23 Sep 2017 11:24:37 +1000 Subject: [PATCH] fixed a bunch of stuff with all the update/package related programs, added pkg, etc. --- exec/pkg.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ exec/update.lua | 2 +- exec/wget.lua | 4 ++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 exec/pkg.lua diff --git a/exec/pkg.lua b/exec/pkg.lua new file mode 100644 index 0000000..6c138d1 --- /dev/null +++ b/exec/pkg.lua @@ -0,0 +1,57 @@ +local tA = {...} +local rf = tA[1] +local wget = wget or loadfile("/boot/exec/wget.lua") +if not wget then + print("wget is required to run this program") +elseif rf and pcall(fs.exists,rf) then + local pref = tA[2] or "/boot/" + local files = {} + local lrf = "/tmp/rf.txt" + + local function precipe(s) + local t = {} + for line in s:gmatch("[^\n\r]+") do + t[#t+1] = {line:match("(.+)[ \t](.+)")} + local S = t[#t][1] + t[#t][1] = "" + for c in S:gmatch(".") do + if (string.byte(c) > 31 and string.byte(c) < 127) then + t[#t][1] = t[#t][1]..c + end + local S = t[#t][2] + t[#t][2] = "" + for c in S:gmatch(".") do + if (string.byte(c) > 31 and string.byte(c) < 127) then + t[#t][2] = t[#t][2]..c + end + end + end + end + return t + end + local function dl(p,u) + if u:sub(1,8) == "https://" or u:sub(1,7) == "http://" then + wget(u,pref..p) + end + end + + if rf:sub(1,8) == "https://" or rf:sub(1,7) == "http://" then + wget(rf,"/tmp/rf.txt") + else + lrf = rf + end + + local f=io.open(lrf) + if not f then return false, "no recipe" end + files=precipe(f:read("*a")) + f:close() + local count = 1 + local total = #files + + for k,v in ipairs(files) do + print(tostring(count).."/"..tostring(total)..": "..pref..v[2]) + dl(v[2],v[1]) + count=count+1 + end +end + diff --git a/exec/update.lua b/exec/update.lua index 1aaa916..f08c749 100644 --- a/exec/update.lua +++ b/exec/update.lua @@ -6,7 +6,7 @@ else local repo = tA[1] or "https://lain.shadowkat.net/~izaya/ocdoc/PsychOS-build/fsdev/PsychOS-fsdev-latest/" local fl = repo .. "files.txt" local pref = tA[1] or "/boot/" - local files = {{"everything"},{"minimal"},{"headless"},{"severything"},{"sminimal"},{"sheadless"},{"exec/addperm"},{"exec/cat"},{"exec/free"},{"exec/ls"},{"exec/luash"},{"exec/nbsrv"},{"exec/nshd"},{"exec/nsh"},{"exec/passwd"},{"exec/ps"},{"exec/rmperm"},{"exec/skex2"},{"exec/su"},{"exec/wget"}} + local files = {{"everything"},{"minimal"},{"headless"},{"severything"},{"sminimal"},{"sheadless"},{"exec/addperm"},{"exec/cat"},{"exec/free"},{"exec/ls"},{"exec/luash"},{"exec/nbsrv"},{"exec/nshd"},{"exec/nsh"},{"exec/passwd"},{"exec/ps"},{"exec/rmperm"},{"exec/skex2"},{"exec/su"},{"exec/wget"},{"exec/update.lua"},{"exec/pkg.lua"}} local count = 1 local total = #files print(total) diff --git a/exec/wget.lua b/exec/wget.lua index b8b6ee1..f4ad840 100644 --- a/exec/wget.lua +++ b/exec/wget.lua @@ -8,6 +8,10 @@ if not f then return false end repeat coroutine.yield() until R.finishConnect() +local code, msg = R.response() +if code ~= 200 then + return false, code, msg +end repeat coroutine.yield() ns = R.read(2048)