59 lines
1.4 KiB
Lua
59 lines
1.4 KiB
Lua
|
--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)()
|