From f8e6adb064be213527f0b828aa74b1f226bed2b6 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 12 Jul 2017 01:01:25 +1000 Subject: [PATCH 01/11] dunno why io wasn't in the builds but \o/ now it is --- configs/everything-noinit.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 97ccab4..7a1f9db 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -15,6 +15,7 @@ library/base64.lua library/chauth.lua library/fs-ext.lua library/readline.lua +library/io.lua net/nshd.lua net/nshc.lua net/nshd-auth.lua From 5ce319c0e45bdac863194c3ce33332d763765686 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 12 Jul 2017 01:07:20 +1000 Subject: [PATCH 02/11] and io requires buffer. I am not a clever man. --- configs/everything-noinit.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 7a1f9db..9fac386 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -15,6 +15,7 @@ library/base64.lua library/chauth.lua library/fs-ext.lua library/readline.lua +library/buffer.lua library/io.lua net/nshd.lua net/nshc.lua From 43f00e76696c4427483cfcb4aa7a284673901aa4 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 12 Jul 2017 04:15:41 +1000 Subject: [PATCH 03/11] added an okay-enough netbooting system, can somewhat build images on its own --- modules/net/nbsrv.lua | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 modules/net/nbsrv.lua diff --git a/modules/net/nbsrv.lua b/modules/net/nbsrv.lua new file mode 100644 index 0000000..5c3561c --- /dev/null +++ b/modules/net/nbsrv.lua @@ -0,0 +1,49 @@ +for k,v in ipairs(tM) do v.open(9671) end +s("nbsrv",function() print(pcall(function() + print("[netboot] loading data") + local f,tnbd=io.open("boot:/nbsrv.csv"),{} + setmetatable(tnbd,{__index=function(t,k) + return rawget(t,k) or {} + end}) + if f then + local c=f:read("*a") + f:close() + for l in c:gmatch("[^\n]+") do + local c,i = 1,"" + for d in l:gmatch("[^,]+") do + if c == 1 then + i=d + tnbd[i]={} + else + tnbd[i][#tnbd[i]+1]=d + end + c=c+1 + end + end + end + local d,d2="","" + local f=io.open("boot:/nbstart.lua") + if f then + d=f:read("*a") + f:close() + end + local f=io.open("boot:/nbend.lua") + if f then + d2=f:read("*a") + f:close() + end + while true do + if ev[1] == "modem_message" and ev[4] == 9671 then + print("[netboot] request from "..ev[3]) + for k,v in ipairs(tnbd[ev[3]]) do + d=d..v.."\n" + end + d=d..d2 + for i = 1, d:len(), 2048 do + component.invoke(ev[2],"send",ev[3],9671,d:sub(i,i+2047)) + end + component.invoke(ev[2],"send",ev[3],9671,".") + end + C.yield() + end +end)) end) From 7518483d2506d3a157b0db211de7b99d068475fe Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 13 Jul 2017 18:05:44 +1000 Subject: [PATCH 04/11] added PixICE, the network bootloader firmware --- modules/net/nbsrv.lua | 49 ----------------------------------- modules/net/pxesrv.lua | 59 ++++++++++++++++++++++++++++++++++++++++++ util/pixice.lua | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 49 deletions(-) delete mode 100644 modules/net/nbsrv.lua create mode 100644 modules/net/pxesrv.lua create mode 100644 util/pixice.lua diff --git a/modules/net/nbsrv.lua b/modules/net/nbsrv.lua deleted file mode 100644 index 5c3561c..0000000 --- a/modules/net/nbsrv.lua +++ /dev/null @@ -1,49 +0,0 @@ -for k,v in ipairs(tM) do v.open(9671) end -s("nbsrv",function() print(pcall(function() - print("[netboot] loading data") - local f,tnbd=io.open("boot:/nbsrv.csv"),{} - setmetatable(tnbd,{__index=function(t,k) - return rawget(t,k) or {} - end}) - if f then - local c=f:read("*a") - f:close() - for l in c:gmatch("[^\n]+") do - local c,i = 1,"" - for d in l:gmatch("[^,]+") do - if c == 1 then - i=d - tnbd[i]={} - else - tnbd[i][#tnbd[i]+1]=d - end - c=c+1 - end - end - end - local d,d2="","" - local f=io.open("boot:/nbstart.lua") - if f then - d=f:read("*a") - f:close() - end - local f=io.open("boot:/nbend.lua") - if f then - d2=f:read("*a") - f:close() - end - while true do - if ev[1] == "modem_message" and ev[4] == 9671 then - print("[netboot] request from "..ev[3]) - for k,v in ipairs(tnbd[ev[3]]) do - d=d..v.."\n" - end - d=d..d2 - for i = 1, d:len(), 2048 do - component.invoke(ev[2],"send",ev[3],9671,d:sub(i,i+2047)) - end - component.invoke(ev[2],"send",ev[3],9671,".") - end - C.yield() - end -end)) end) diff --git a/modules/net/pxesrv.lua b/modules/net/pxesrv.lua new file mode 100644 index 0000000..dc4e600 --- /dev/null +++ b/modules/net/pxesrv.lua @@ -0,0 +1,59 @@ +function pxesrv(i,P,LF) -- port, image, log file + _G.pxcl = {} + local P,i,LF = P or 9671,i or "boot:/pxeimage.lua",LF or "boot:/pxetab.csv" + for k,v in ipairs(tM) do v.open(P) end + print("[netboot] loading data") + f=io.open(i) + if f then d=f:read("*a") f:close() + else error("image not found") + end + print("[netboot] server starting, port "..TS(P)..", image file "..i) + print("[netboot] loading existing data") + local f=io.open(LF) + C.yield() + if f then + local c = f:read("*a") + f:close() + for m,C,h,p in c:gmatch("(.-),(.-),(.-),(.-)\n") do + print(m.." = {"..C..", "..h..", "..p.."}") + pxcl[m]={C,h,p} + end + end + s("pxesrv",function() print(pcall(function() + while true do + if ev[1] == "modem_message" and ev[4] == P then + print("[netboot] request from "..ev[3]:sub(1,8)..":"..TS(ev[6]):sub(1,8)) + if type(pxcl[ev[3]]) ~= "table" then + pxcl[ev[3]]={ev[6],ev[6]:sub(1,8),"pass"} + else + pxcl[ev[3]]={ev[6],pxcl[ev[3]][2] or ev[6]:sub(1,8),pxcl[ev[3]][3] or "pass"} + end + fd=d:gsub("HOSTNAME",pxcl[ev[3]][2]) + fd=fd:gsub("PASSWORD",pxcl[ev[3]][3]) + local la,fr = ev[2],ev[3] + print(fd:len()) + for i = 1, fd:len(), 2048 do + component.invoke(la,"send",fr,P,fd:sub(i,i+2047)) + C.yield() + end + component.invoke(la,"send",fr,P,".") + end + C.yield() + end + end)) end) + s("pxesrv logger",function() print(pcall(function() + while true do + for i = 1, 100 do + C.yield() + end + f=fopen(LF,"w") + if f then + for k,v in pairs(pxcl) do + fwrite(f,k..","..v[1]..","..v[2]..","..v[3].."\n") + end + fclose(f) + C.yield() + end + end + end)) end) +end diff --git a/util/pixice.lua b/util/pixice.lua new file mode 100644 index 0000000..599c6d3 --- /dev/null +++ b/util/pixice.lua @@ -0,0 +1,58 @@ +--base/loadlin.lua +if pcall(require,"computer") then + print("OpenOS detected.") + print(os.getenv("_")) + local computer = require "computer" + local process = require "process" + os.execute("cp "..os.getenv("_").." /tmp/init.lua") + computer.setBootAddress(computer.tmpAddress()) + computer.shutdown(true) +end +-- actual code starts here +s="" +computer.getBootAddress = computer.tmpAddress +do + local addr=nil + local OCPS,OCSD,OCI=computer.pullSignal,computer.shutdown,component.invoke + function computer.pullSignal(...) + local tA={...} + local eV={OCPS(...)} + if eV[1] == "modem_message" and eV[3] == addr and eV[4] == 9671 then + if eV[6] == "reboot" then + OCSD(true) + end + return + end + return table.unpack(eV) + end + function computer.shutdown() + OCSD(true) + end + function component.invoke(...) + tA={...} + if tA[2] == "stop" then return end + return OCI(...) + end + local m=component.proxy(component.list("modem")()) + m.open(9671) + if addr then + m.send(addr,9671,computer.address()) + while true do + local ev={computer.pullSignal()} + if ev[1] == "modem_message" and ev[3] == addr and ev[4] == 9671 then + if ev[6] == "." then break end + s=s..ev[6] + end + end + else + m.broadcast(9671,computer.address()) + while true do + local ev={computer.pullSignal()} + if ev[1] == "modem_message" and ev[4] == 9671 then + if ev[6] == "." then break end + s=s..ev[6] + end + end + end +end +load(s)() From ac9bb0d5ccf0ed87d33ba710e735e37d57ecd27b Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 13 Jul 2017 18:07:03 +1000 Subject: [PATCH 05/11] added pxesrv to everything-noinit.cfg --- configs/everything-noinit.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 9fac386..26fb338 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -21,6 +21,7 @@ net/nshd.lua net/nshc.lua net/nshd-auth.lua net/nshc-auth.lua +net/pxesrv.lua applications/shutil.lua applications/skex2.lua applications/luash.lua From d8c8dc73d889bce7aa7c1d8b35f2cdf2834da6c1 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 13 Jul 2017 20:21:28 +1000 Subject: [PATCH 06/11] made the fs play nice with drive names with numbers in them --- modules/library/fs-min.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/library/fs-min.lua b/modules/library/fs-min.lua index 7415c52..7b22c5f 100644 --- a/modules/library/fs-min.lua +++ b/modules/library/fs-min.lua @@ -1,6 +1,6 @@ fT = {} function fres(p) - local F = (p:match("(%a-):") or p:match("/?(%a-)/")) - local P = (p:match("%a-:(.+)") or p:match("/?%a-/(.+)")) + local F = (p:match("(.-):") or p:match("/?(.-)/")) + local P = (p:match(".-:(.+)") or p:match("/?.-/(.+)")) if fT[F] ~= nil then return fT[F],P else return false end end From b16f56439a85c767b03f68c149a930daa5cf1d11 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 13 Jul 2017 20:22:04 +1000 Subject: [PATCH 07/11] fs-automount-ext: mounts extra filesystems as fs00, fs01 etc. --- modules/util/fs-automount-ext.lua | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 modules/util/fs-automount-ext.lua diff --git a/modules/util/fs-automount-ext.lua b/modules/util/fs-automount-ext.lua new file mode 100644 index 0000000..2879ae6 --- /dev/null +++ b/modules/util/fs-automount-ext.lua @@ -0,0 +1,9 @@ +do + local C=0 + for c in component.list("filesystem") do + if c ~= fT.boot.address and c ~= fT.tmp.address then + fT["fs"..string.format("%02d",C)] = component.proxy(c) + C=C+1 + end + end +end From a70b40d39443b08c47fe91003479284828532357 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 13 Jul 2017 23:51:52 +1000 Subject: [PATCH 08/11] added the FS automounter to everything-noinit.cfg --- configs/everything-noinit.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 26fb338..535d1d5 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -5,6 +5,7 @@ library/fs-min.lua library/fs-std.lua library/fs-util.lua util/fs-automount.lua +util/fs-automount-ext.lua drivers/tty.lua drivers/kbd.lua util/autogpu.lua From ab636ef6559de58f146a6d2e44a675a28d607aa1 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 14 Jul 2017 00:01:55 +1000 Subject: [PATCH 09/11] added some modules to run nsh and a file at startup \o/ --- modules/util/autoexec.lua | 7 +++++++ modules/util/autonsh.lua | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 modules/util/autoexec.lua create mode 100644 modules/util/autonsh.lua diff --git a/modules/util/autoexec.lua b/modules/util/autoexec.lua new file mode 100644 index 0000000..fb27cf6 --- /dev/null +++ b/modules/util/autoexec.lua @@ -0,0 +1,7 @@ +do + local f=io.open("/boot/autoexec.lua") + if f then + pcall(load(f:read("*a"))) + f:close() + end +end diff --git a/modules/util/autonsh.lua b/modules/util/autonsh.lua new file mode 100644 index 0000000..3665884 --- /dev/null +++ b/modules/util/autonsh.lua @@ -0,0 +1,3 @@ +_G.pass = "PASSWORD" +nshd("nsh") +nshds("nshs",pass) From f4747c076f61e20a26d1a1cf0dde80c811178ce4 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 14 Jul 2017 00:03:16 +1000 Subject: [PATCH 10/11] added a version of luash that requires you to enter _G.pass before letting you do anything. --- modules/applications/luash-login.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 modules/applications/luash-login.lua diff --git a/modules/applications/luash-login.lua b/modules/applications/luash-login.lua new file mode 100644 index 0000000..ae4025a --- /dev/null +++ b/modules/applications/luash-login.lua @@ -0,0 +1,18 @@ +function luash(si) +s("lua shell",function() + local np = "" + while np ~= pass do + write("Password: ") + np=readln("*") + end + if _OSVERSION and _BD then + write(_OSVERSION.." on "..nID.." (built at ".._BD..")\t") + end + print(tostring(computer.freeMemory()/1024).."K free.",_G.motd) + print(_VERSION) + while true do + write("> ") + print(pcall(load(readln()))) + end +end,si) +end From f77374f31c92dac39cef90d66698ecab6d340386 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 14 Jul 2017 00:05:41 +1000 Subject: [PATCH 11/11] added a headless server config file, for my use mostly --- configs/headless-server.cfg | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 configs/headless-server.cfg diff --git a/configs/headless-server.cfg b/configs/headless-server.cfg new file mode 100644 index 0000000..f7cdcca --- /dev/null +++ b/configs/headless-server.cfg @@ -0,0 +1,20 @@ +base/header.lua +library/print.lua +library/net.lua +library/readline.lua +net/nshd.lua +library/crc32.lua +library/chauth.lua +net/nshd.lua +net/nshd-auth.lua +applications/luash-login.lua +applications/shutil.lua +library/fs-min.lua +library/fs-std.lua +library/fs-ext.lua +library/buffer.lua +library/io.lua +util/fs-automount-min.lua +util/fs-automount-ext.lua +util/autonsh.lua +base/footer.lua