Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --sys2_service_terminal
- args = { ... }
- local rootId = tonumber(args[1])
- local bootUnitId = tonumber(args[2])
- print(rootId, ", ", bootUnitId)
- os.loadAPI("sys/syslib")
- --syslib end
- shell.run("clear")
- while true do
- io.write("local-network>")
- local input = read()
- local pts = syslib.split(input, " ")
- if pts[1] == "reboot" then
- print("do you really want to reboot the whole system? [y/n]")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,reboot")
- else print("action aborted")
- end
- --[[elseif pts[1] == "reconnect" then
- print("do you really want to reconnect the whole system? [y/n]")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,reconnect")
- else print("action aborted")
- end]]
- elseif pts[1] == "door" then
- if pts[2] == "setPassword" then
- io.write("old password:")
- local oldPwd = read("*")
- io.write("new password:")
- local newPwd1 = read("*")
- io.write("repeat new password:")
- local newPwd2 = read("*")
- if newPwd1 ~= newPwd2 then
- print("password and repetition don't match")
- else
- rednet.broadcast("@doorLock:setPwd," .. oldPwd .. "," .. newPwd1)
- end
- elseif pts[2] == "open" then
- io.write("password:")
- local pwd = read("*")
- rednet.broadcast("@doorLock:keepOpen," .. pwd)
- elseif pts[2] == "close" then
- rednet.broadcast("@doorLock:close")
- else print("unknown command>door: " .. pts[2])
- end
- elseif pts[1] == "turtle" then
- if pts[2] == "rename" then
- local oldLabel = pts[3]
- local newLabel = pts[4]
- if oldLabel == nil or newLabel == nil then
- print("command 'turtle rename' takes 4 arguments at total")
- else
- print("do you want to rename unit '" .. oldLabel .. "' to '" .. newLabel .. "'? [y/n] ")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,label,renameTurtle," .. oldLabel .. "," .. newLabel)
- else print("action aborted")
- end
- end
- elseif pts[2] == "list" then
- print("command isn't defined yet")
- elseif pts[2] == "reboot" then
- if pts[3] == nil then
- print("label expected (got nothing)")
- else
- syslib.sendRednet(rootId,"@root:command,reboot,turtle,"..pts[3])
- end
- else print("unknown command>turtle: " .. pts[2])
- end
- elseif pts[1] == "unit" then
- if pts[2] == "rename" then
- local oldLabel = pts[3]
- local newLabel = pts[4]
- if oldLabel == nil or newLabel == nil then
- print("command 'unit rename' takes 4 arguments at total")
- else
- print("do you want to rename unit '" .. oldLabel .. "' to '" .. newLabel .. "'? [y/n] ")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,label,renameUnit," .. oldLabel .. "," .. newLabel)
- else print("action aborted")
- end
- end
- elseif pts[2] == "list" then
- syslib.sendRednet(rootId, "@root:command,unit,list")
- elseif pts[2] == "reboot" then
- if pts[3] == nil then
- print("label expected (got nothing)")
- else
- syslib.sendRednet(rootId, "@root:command,reboot,unit," .. pts[3])
- end
- else print("unknown command>unit: " .. pts[2])
- end
- elseif pts[1] == "log" then
- local group = pts[2]
- local txt = pts[3]
- if group == nil or txt == nil then
- if group == "clear" then
- rednet.broadcast("@log:clear")
- else print("command 'log' takes exactly 3 arguments")
- end
- else
- rednet.broadcast("@log:" .. group .. "," .. txt)
- end
- elseif pts[1] == "service" then
- if pts[2] == "register" then
- local name = pts[3]
- local exId = pts[4]
- if name == nil or exId == nil then
- print("command 'service register' takes 4 arguments at total")
- else
- print("do you want to register service '" .. exId .. "' to label '" .. name .. "'? [y/n] ")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,service,register," .. exId .. "," .. name)
- else print("action aborted")
- end
- end
- elseif pts[2] == "remove" then
- local name = pts[3]
- if name == nil then
- print("command 'service remove' takes 3 arguments at total")
- else
- print("do you want to remove service with label '" .. name .. "'? [y/n]")
- local answer = read()
- if answer == "y" then
- syslib.sendRednet(rootId, "@root:command,service,remove," .. name)
- else print("action aborted")
- end
- end
- elseif pts[2] == nil then
- print("please add further keywords")
- else print("unknown command>service" .. pts[2])
- end
- else print("unknown command: " .. pts[1])
- end
- end
Add Comment
Please, Sign In to add comment