Posted 30 August 2012 - 11:40 PM
I'm trying to make a custom network-loading script that runs on startup. the only problem with this, though, is that it can't use the shell API's functions. This also happens with any programs run by the downloaded shell.
From what I've seen of the code, this shouldn't happen, as the shell program itself loads the shell API, and then runs the startup program.
Below is the code:
From what I've seen of the code, this shouldn't happen, as the shell program itself loads the shell API, and then runs the startup program.
Below is the code:
-- Network Boot System
local timeout = 10
local side = "top"
rednet.open(side)
function advancedOptions()
print("Select a boot file:")
bootID = io.read()
return bootID
end
function doBoot()
local bootFile = "default"
term.clear()
term.setCursorPos(1,1)
print("NETWORK BOOT CLIENT")
print("Press any key within 5 seconds to select a boot file.")
os.startTimer(5)
while true do
event = os.pullEvent()
if event == "timer" then
print("Boot file not selected. Going to default...")
break
end
if event == "key" then
bootFile = advancedOptions()
break
end
end
rednet.broadcast("boot:"..bootFile)
bootServer, bootshell, distance = rednet.receive(timeout)
if bootshell == nil then
print("ERROR: Could not contact boot server!")
shell.exit()
end
print("Boot server contacted. Boot Server ID:"..bootServer)
shell = fs.open("shell", "w")
shell.write(bootshell)
shell.close()
print("Boot file downloaded! Running shell...")
os.sleep(2)
term.clear()
term.setCursorPos(1,1)
shell.setPath("/")
rednet.close(side)
os.sleep(2)
os.run({},"shell")
end
doBoot()