mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-24 20:27:39 -05:00
Compare commits
10 Commits
36a73b892a
...
2edbb42aa4
Author | SHA1 | Date | |
---|---|---|---|
|
2edbb42aa4 | ||
|
7849fca4a0 | ||
|
ae634bc52e | ||
|
904fdce527 | ||
|
e85b948f4d | ||
|
30db695c4e | ||
|
ef2c01b1d4 | ||
|
eb98acc232 | ||
|
3d6017f87e | ||
|
86149d7e85 |
@ -1,7 +1,4 @@
|
|||||||
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(...)
|
||||||
|
5
build.sh
5
build.sh
@ -1,9 +1,10 @@
|
|||||||
#!/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 module/init.lua target/init.lua
|
$LUA build.lua kcfg/$KVAR.cfg target/init.lua
|
||||||
echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua
|
echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)-$KVAR\" > 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/
|
||||||
|
@ -1 +1 @@
|
|||||||
{enabled={"getty","minitel","fsmanager","rtfsman","partman"}}
|
{enabled={"getty","minitel"}}
|
||||||
|
2
kcfg/base.cfg
Normal file
2
kcfg/base.cfg
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
--#include "module/base.lua"
|
||||||
|
--#include "module/init.lua"
|
3
kcfg/full.cfg
Normal file
3
kcfg/full.cfg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
--#include "module/base.lua"
|
||||||
|
--#include "module/rtfsboot.lua"
|
||||||
|
--#include "module/init.lua"
|
@ -7,6 +7,8 @@ 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()
|
||||||
|
10
module/base.lua
Normal file
10
module/base.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
--#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"
|
@ -1,14 +1,3 @@
|
|||||||
--#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()
|
||||||
|
@ -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).." ")
|
io.write(tostring(v).."\t")
|
||||||
end
|
end
|
||||||
io.write("\n")
|
io.write("\n")
|
||||||
end
|
end
|
||||||
|
19
module/rtfsboot.lua
Normal file
19
module/rtfsboot.lua
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
--#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
|
@ -1,4 +1,3 @@
|
|||||||
--#include "module/ocelot-debug.lua"
|
|
||||||
do
|
do
|
||||||
syslog = {}
|
syslog = {}
|
||||||
syslog.emergency = 0
|
syslog.emergency = 0
|
||||||
|
41
preproc.lua
41
preproc.lua
@ -59,6 +59,47 @@ 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)
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
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}
|
|
Loading…
Reference in New Issue
Block a user