1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-22 12:04:20 -05:00

Compare commits

..

No commits in common. "2edbb42aa470043ceb0d0476f87848e94fc4ed38" and "36a73b892a4719291c0b0ea48bb6313c1871d3b7" have entirely different histories.

13 changed files with 126 additions and 82 deletions

View File

@ -1,4 +1,7 @@
local preproc = require "preproc" local preproc = require "preproc"
--local tA = {...} --local tA = {...}
function preproc.directives.includelib(file,name)
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file))
end
preproc(...) preproc(...)

View File

@ -1,10 +1,9 @@
#!/bin/bash #!/bin/bash
LUA=${LUA:-lua} LUA=${LUA:-lua}
KVAR=${1:-base}
rm -r target/* rm -r target/*
mkdir -p target/doc &>/dev/null mkdir -p target/doc &>/dev/null
$LUA build.lua kcfg/$KVAR.cfg target/init.lua $LUA build.lua module/init.lua target/init.lua
echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)-$KVAR\" > target/version.lua echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua
cat target/version.lua target/init.lua > target/tinit.lua cat target/version.lua target/init.lua > target/tinit.lua
mv target/tinit.lua target/init.lua mv target/tinit.lua target/init.lua
cp -r service/ lib/ cfg/ exec/ target/ cp -r service/ lib/ cfg/ exec/ target/

View File

@ -1 +1 @@
{enabled={"getty","minitel"}} {enabled={"getty","minitel","fsmanager","rtfsman","partman"}}

View File

@ -1,2 +0,0 @@
--#include "module/base.lua"
--#include "module/init.lua"

View File

@ -1,3 +0,0 @@
--#include "module/base.lua"
--#include "module/rtfsboot.lua"
--#include "module/init.lua"

View File

@ -7,8 +7,6 @@ pkg.sourcePath = pkg.cfgPath .. "/sources.cfg"
pkg.installedPath = pkg.cfgPath .. "/installed.cfg" pkg.installedPath = pkg.cfgPath .. "/installed.cfg"
local w, lz16 = pcall(require,"liblz16") local w, lz16 = pcall(require,"liblz16")
if not w then lz16 = nil end if not w then lz16 = nil end
fs.makeDirectory("/boot/pkg")
fs.makeDirectory("/boot/cfg/pkg")
require "pkgfs" require "pkgfs"
local function getSources() local function getSources()

View File

@ -1,10 +0,0 @@
--#include "module/syslog.lua"
--#include "module/sched.lua"
--#include "module/buffer.lua"
--#include "module/osutil.lua"
--#include "module/fs.lua"
--#include "module/io.lua"
--#include "module/devfs.lua"
--#include "module/devfs/syslog.lua"
--#include "module/component-get.lua"
--#include "module/loadfile.lua"

View File

@ -1,3 +1,14 @@
--#include "module/syslog.lua"
--#include "module/sched.lua"
--#include "module/buffer.lua"
--#include "module/osutil.lua"
--#include "module/fs.lua"
--#include "module/io.lua"
--#include "module/devfs.lua"
--#include "module/devfs/syslog.lua"
--#include "module/component-get.lua"
--#include "module/loadfile.lua"
_OSVERSION=_OSVERSION or "PsychOS 2" _OSVERSION=_OSVERSION or "PsychOS 2"
os.spawn(function() os.spawn(function()

View File

@ -34,7 +34,7 @@ end
function print(...) -- Writes each argument to the default output stream, separated by space. function print(...) -- Writes each argument to the default output stream, separated by space.
for k,v in ipairs({...}) do for k,v in ipairs({...}) do
io.write(tostring(v).."\t") io.write(tostring(v).." ")
end end
io.write("\n") io.write("\n")
end end

View File

@ -1,19 +0,0 @@
--#includepkglib "diskpart" "lib/diskpart.lua" "diskpart"
--#includepkglib "rtfs" "lib/rtfs.lua" "rtfs"
do
local a = computer.getBootAddress()
if component.type(a) == "drive" then
local diskpart = require "diskpart"
for k,v in ipairs(diskpart.getPartitions(a)) do
if v[2] == "rtfs" and v[1] == computer.address():sub(1,8) .. "-boot" then
syslog("Partition with suitable name detected, attempting to mount...")
local rtfs = require "rtfs"
fs.makeDirectory("boot")
local m = rtfs.mount(diskpart.proxyPartition(a,k))
m.address = string.format("%s/%i/rtfs",a,k)
fs.mount("boot",m)
break
end
end
end
end

View File

@ -1,3 +1,4 @@
--#include "module/ocelot-debug.lua"
do do
syslog = {} syslog = {}
syslog.emergency = 0 syslog.emergency = 0

View File

@ -59,47 +59,6 @@ end
preproc.directives.include = preproc.preproc preproc.directives.include = preproc.preproc
function preproc.directives.includelib(file, name) -- string string -- string -- Returns a preprocessed inlined library
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file))
end
function preproc.directives.includepkgfile(package, file)
if (_OSVERSION or ""):sub(1,7) == "PsychOS" then
return preproc.preproc(string.format("/pkg/%s", file))
else
for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do
local f = io.open(string.format("%s/%s/%s", path, package, file), "r")
if f then
f:close()
return preproc.preproc(string.format("%s/%s/%s", path, package, file))
end
end
end
error(string.format("unable to locate file %s from package %s", file, package))
end
function preproc.directives.includepkglib(package, file, name) -- string string -- string -- Returns a preprocessed inlined library
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.directives.includepkgfile(package, file))
end
--[[
function preproc.directives.includepkglib(package, file, name)
if (_OSVERSION or ""):sub(1,7) == "PsychOS" then
return preproc.directives.includelib(string.format("/pkg/%s", file), name)
else
for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do
print(string.format("%s/%s/%s", path, package, file))
local f = io.open(string.format("%s/%s/%s", path, package, file), "r")
if f then
f:close()
return preproc.directives.includelib(string.format("%s/%s/%s", path, package, file), name)
end
end
end
error(string.format("unable to locate library %s from package %s", name, package))
end
]]
return setmetatable(preproc,{__call=function(_,...) return setmetatable(preproc,{__call=function(_,...)
local tA = {...} local tA = {...}
local out = table.remove(tA,#tA) local out = table.remove(tA,#tA)

107
service/fserv.lua Normal file
View File

@ -0,0 +1,107 @@
local minitel = require "minitel"
local serial = require "serialization"
local cfg = {["path"]="/boot/srv/frequest",["port"]=70}
local function loadConfig(cfgpath)
local f=io.open(cfgpath or "/boot/cfg/fserv.cfg","rb")
if f then
local ncfg = serial.unserialize(f:read("*a"))
f:close()
for k,v in pairs(ncfg) do
cfg[k] = v
end
end
end
local function fileHandler(socket,rtype,path)
syslog(string.format("[%s:%d] %s %s",socket.addr,socket.port,rtype,path),syslog.info,"fserv")
if rtype == "t" then
if fs.exists(path) and fs.isDirectory(path) then
socket:write("d")
for _,file in ipairs(fs.list(path)) do
socket:write(file.."\n")
end
elseif fs.exists(path) and not fs.isDirectory(path) then
local f,err = io.open(path,"rb")
if f then
socket:write("y")
while true do
local c = f:read(4096)
if not c or c == "" then break end
socket:write(c)
end
else
socket:write("fFailed to open file: "..err)
end
else
socket:write("nFile not found")
end
elseif rtype == "s" then
if fs.exists(path) then
local ftype = "f"
if fs.isDirectory(path) then
ftype = "d"
end
socket:write(string.format("y%s\n%d",ftype,fs.size(path)))
else
socket:write("nFile not found.")
end
else
socket:write("fUnknown request type")
end
end
local function httpHandler(socket,rtype,path)
local tPath = fs.segments(path)
local proto = table.remove(tPath,1)
local url = string.format("%s://%s",proto,table.concat(tPath,"/"))
local request = component.invoke(component.list("internet")(),"request",url)
repeat
coroutine.yield()
until request.finishConnect()
local code, message, headers = request.response()
if code < 200 or code > 299 then
socket:write(string.format("f%d\n%s",code,message))
else
socket:write("y")
local data = ""
repeat
coroutine.yield()
data = request.read()
if data then
socket:write(data)
end
until not data
end
end
local function socketHandler(socket)
return function()
local line = nil
repeat
coroutine.yield()
line = socket:read()
until line
local rtype, path = line:match("(.)(.+)")
if fs.segments(path)[1] == "http" or fs.segments(path)[1] == "https" then
httpHandler(socket,rtype,path)
else
path = (cfg.path .. "/" .. path:gsub("../","")):gsub("/+","/")
fileHandler(socket,rtype,path)
end
socket:close()
end
end
local function fileServer()
while true do
os.spawn(socketHandler(minitel.listen(70)),"fserv worker process")
end
end
function start(cfgpath)
loadConfig(cfgpath)
return os.spawn(fileServer,"fserv")
end
return {start=start}