Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --sys2_service_unit
- os.loadAPI("sys/syslib")
- --syslib_end
- rednet.open("back")
- function identify()
- local label = os.getComputerLabel()
- if label == nil then
- label = "<unnamed>"
- end
- rednet.broadcast("@root:identifyServiceUnit," .. label)
- end
- print("<serviceUnit>")
- identify()
- local rootId
- local bootUnitId
- function main()
- local id, msg = syslib.receiveRednet()
- local tag, pts = syslib.getMsgData(msg)
- if tag == "@serviceUnit" then
- if pts[1] == "identifyToRoot" then
- bootUnitId = id
- rootId = pts[2]
- identify()
- elseif pts[1] == "setRootData" then
- rootId = id
- bootUnitId = pts[2]
- elseif pts[1] == "action" then
- if pts[2] == "setStartup" then
- print("setStartup")
- shell.run("delete", "startup")
- local f = fs.open("startup", "w")
- f.write("shell.run(\"delete\",\"unitHandler\")\n")
- f.write("shell.run(\"pastebin\",\"get\",\"" .. pts[3] .. "\",\"unitHandler\")\n")
- f.write("shell.run(\"unitHandler\")\n")
- f.close()
- elseif pts[2] == "executePastebin" then
- shell.run("delete", "temp")
- shell.run("pastebin", "get", pts[3], "temp")
- shell.run("temp", rootId, bootUnitId)
- syslib.sendRednet(id, "@root:answer,executionTerminated")
- elseif pts[2] == "setLabel" then
- syslib.log("root", "successfully renamed unit '" .. os.getComputerLabel() .. "' to '" .. pts[3] .. "'")
- os.setComputerLabel(pts[3])
- syslib.sendRednet(rootId, "@root:answer,renamedUnit," .. pts[3])
- else print("unknown message>action: ", msg)
- end
- else print("unknown message: ", msg)
- end
- end
- end
- while true do
- local status, err = pcall(main)
- if err == "Terminated" then
- break
- elseif not status then
- print("error thrown: " .. err)
- rednet.broadcast("@err:" .. os.getComputerID() .. "," .. os.getComputerLabel() .. ",serviceUnit")
- end
- end
Add Comment
Please, Sign In to add comment