From 6cbe2d6479494d38a321fea33ee8afd2a73397f5 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 21 May 2019 02:32:05 +1000 Subject: [PATCH] Added the dlfs module, used to download a filesystem from a remote FRequest server to the tmpfs and boot from it. This is used for the nbcore file, which is the actually usable version of that. --- Embedded/dlfs.lua | 36 ++++++++++++++++++++++++++++++++++++ Embedded/dlfs.lua.min | 14 ++++++++++++++ Embedded/fget.lua | 4 ++-- Embedded/minify-all.sh | 5 +++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Embedded/dlfs.lua create mode 100644 Embedded/dlfs.lua.min diff --git a/Embedded/dlfs.lua b/Embedded/dlfs.lua new file mode 100644 index 0000000..2f452c5 --- /dev/null +++ b/Embedded/dlfs.lua @@ -0,0 +1,36 @@ +c="" +do +local host,port,FD=component.invoke(component.list("eeprom")(),"getData"):match("(.+)\n(.+)\n(.+)") +port=tonumber(port) +local fs,dirlist,filelist=component.proxy(computer.tmpAddress()),{FD},{} +for _,dir in pairs(dirlist) do + local content,ftype = fget(host,dir,port) + if ftype == "d" then + for line in content:gmatch("[^\n]+") do + if line:sub(-1) == "/" then + dirlist[#dirlist+1] = dir..line + else + filelist[#filelist+1] = dir..line + end + end + end +end +for _,dir in pairs(dirlist) do + dir=dir:sub(#dirlist[1]) + fs.makeDirectory(dir) +end +for _,file in pairs(filelist) do + local filename=file:sub(#dirlist[1]+1) + local content,ftype = fget(host,file,port) + f=fs.open(filename,"wb") + fs.write(f,content) + fs.close(f) +end +local fh,b = fs.open("boot.lua"),"" +repeat + b=fs.read(fh,4096) or "" + c=c..b +until b == "" +end +computer.getBootAddress = computer.tmpAddress +load(c)() diff --git a/Embedded/dlfs.lua.min b/Embedded/dlfs.lua.min new file mode 100644 index 0000000..e4e76b7 --- /dev/null +++ b/Embedded/dlfs.lua.min @@ -0,0 +1,14 @@ +{ + {"init","I"}, + {"dirlist","DL"}, + {"filelist","FL"}, + {"host","H"}, + {"port","P"}, + {"line","L"}, + {"ftype","F"}, + {"content","K"}, + {"filename","FN"}, + {"table.remove","TR"}, + {"dir","CD"}, + {"file","CF"} +,} diff --git a/Embedded/fget.lua b/Embedded/fget.lua index 5530134..910e9e7 100644 --- a/Embedded/fget.lua +++ b/Embedded/fget.lua @@ -2,9 +2,9 @@ function fget(A,P,V) local b,tb,s="","",net.open(A,V or 70) s:w("t"..P.."\n") repeat - UC.pullSignal() + computer.pullSignal() tb=s:r(2048) b=b..tb until tb == "" and s.s == "c" - return b:sub(2) + return b:sub(2),b:sub(1,1) end diff --git a/Embedded/minify-all.sh b/Embedded/minify-all.sh index d6eab38..9e47be3 100755 --- a/Embedded/minify-all.sh +++ b/Embedded/minify-all.sh @@ -9,6 +9,8 @@ echo ufs.lua lua minify.lua ufs.lua mini-ufs.lua echo init-wrapper.lua lua minify.lua init-wrapper.lua mini-init-wrapper.lua +echo dlfs.lua +lua minify.lua dlfs.lua mini-dlfs.lua echo microtel-3.lua lua minify.lua microtel/microtel-3.lua microtel/mini-microtel-3.lua echo microtel-4.lua @@ -27,3 +29,6 @@ cat microtel/mini-microtel-{3,4,5-core,5-open}.lua mini-vt100.lua mini-minipromp lua minify.lua nminiprompt.lua mini-nminiprompt.lua echo -e "GC,UC=component,computer" | cat - mini-nminiprompt.lua > mini-fnminiprompt.lua mv mini-fnminiprompt.lua mini-nminiprompt.lua + +cat microtel/mini-microtel-{3,4,5-core,5-open}.lua mini-fget.lua mini-dlfs.lua > mini-nbcore.lua +cat microtel/microtel-{3,4,5-core,5-open}.lua fget.lua dlfs.lua > nbcore.lua