melzneni

sys2_service_terminal

Feb 10th, 2020
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. --sys2_service_terminal
  2. args = { ... }
  3. local rootId = tonumber(args[1])
  4. local bootUnitId = tonumber(args[2])
  5.  
  6. print(rootId, ", ", bootUnitId)
  7.  
  8. os.loadAPI("sys/syslib")
  9. --syslib end
  10.  
  11. shell.run("clear")
  12. while true do
  13. io.write("local-network>")
  14. local input = read()
  15. local pts = syslib.split(input, " ")
  16. if pts[1] == "reboot" then
  17. print("do you really want to reboot the whole system? [y/n]")
  18. local answer = read()
  19. if answer == "y" then
  20. syslib.sendRednet(rootId, "@root:command,reboot")
  21. else print("action aborted")
  22. end
  23. --[[elseif pts[1] == "reconnect" then
  24. print("do you really want to reconnect the whole system? [y/n]")
  25. local answer = read()
  26. if answer == "y" then
  27. syslib.sendRednet(rootId, "@root:command,reconnect")
  28. else print("action aborted")
  29. end]]
  30. elseif pts[1] == "door" then
  31. if pts[2] == "setPassword" then
  32. io.write("old password:")
  33. local oldPwd = read("*")
  34. io.write("new password:")
  35. local newPwd1 = read("*")
  36. io.write("repeat new password:")
  37. local newPwd2 = read("*")
  38. if newPwd1 ~= newPwd2 then
  39. print("password and repetition don't match")
  40. else
  41. rednet.broadcast("@doorLock:setPwd," .. oldPwd .. "," .. newPwd1)
  42. end
  43. elseif pts[2] == "open" then
  44. io.write("password:")
  45. local pwd = read("*")
  46. rednet.broadcast("@doorLock:keepOpen," .. pwd)
  47. elseif pts[2] == "close" then
  48. rednet.broadcast("@doorLock:close")
  49. else print("unknown command>door: " .. pts[2])
  50. end
  51. elseif pts[1] == "turtle" then
  52. if pts[2] == "rename" then
  53. local oldLabel = pts[3]
  54. local newLabel = pts[4]
  55. if oldLabel == nil or newLabel == nil then
  56. print("command 'turtle rename' takes 4 arguments at total")
  57. else
  58. print("do you want to rename unit '" .. oldLabel .. "' to '" .. newLabel .. "'? [y/n] ")
  59. local answer = read()
  60. if answer == "y" then
  61. syslib.sendRednet(rootId, "@root:command,label,renameTurtle," .. oldLabel .. "," .. newLabel)
  62. else print("action aborted")
  63. end
  64. end
  65. elseif pts[2] == "list" then
  66. print("command isn't defined yet")
  67. elseif pts[2] == "reboot" then
  68. if pts[3] == nil then
  69. print("label expected (got nothing)")
  70. else
  71. syslib.sendRednet(rootId,"@root:command,reboot,turtle,"..pts[3])
  72. end
  73. else print("unknown command>turtle: " .. pts[2])
  74. end
  75. elseif pts[1] == "unit" then
  76. if pts[2] == "rename" then
  77. local oldLabel = pts[3]
  78. local newLabel = pts[4]
  79. if oldLabel == nil or newLabel == nil then
  80. print("command 'unit rename' takes 4 arguments at total")
  81. else
  82. print("do you want to rename unit '" .. oldLabel .. "' to '" .. newLabel .. "'? [y/n] ")
  83. local answer = read()
  84. if answer == "y" then
  85. syslib.sendRednet(rootId, "@root:command,label,renameUnit," .. oldLabel .. "," .. newLabel)
  86. else print("action aborted")
  87. end
  88. end
  89. elseif pts[2] == "list" then
  90. syslib.sendRednet(rootId, "@root:command,unit,list")
  91. elseif pts[2] == "reboot" then
  92. if pts[3] == nil then
  93. print("label expected (got nothing)")
  94. else
  95. syslib.sendRednet(rootId, "@root:command,reboot,unit," .. pts[3])
  96. end
  97. else print("unknown command>unit: " .. pts[2])
  98. end
  99. elseif pts[1] == "log" then
  100. local group = pts[2]
  101. local txt = pts[3]
  102. if group == nil or txt == nil then
  103. if group == "clear" then
  104. rednet.broadcast("@log:clear")
  105. else print("command 'log' takes exactly 3 arguments")
  106. end
  107. else
  108. rednet.broadcast("@log:" .. group .. "," .. txt)
  109. end
  110. elseif pts[1] == "service" then
  111. if pts[2] == "register" then
  112. local name = pts[3]
  113. local exId = pts[4]
  114. if name == nil or exId == nil then
  115. print("command 'service register' takes 4 arguments at total")
  116. else
  117. print("do you want to register service '" .. exId .. "' to label '" .. name .. "'? [y/n] ")
  118. local answer = read()
  119. if answer == "y" then
  120. syslib.sendRednet(rootId, "@root:command,service,register," .. exId .. "," .. name)
  121. else print("action aborted")
  122. end
  123. end
  124. elseif pts[2] == "remove" then
  125. local name = pts[3]
  126. if name == nil then
  127. print("command 'service remove' takes 3 arguments at total")
  128. else
  129. print("do you want to remove service with label '" .. name .. "'? [y/n]")
  130. local answer = read()
  131. if answer == "y" then
  132. syslib.sendRednet(rootId, "@root:command,service,remove," .. name)
  133. else print("action aborted")
  134. end
  135. end
  136. elseif pts[2] == nil then
  137. print("please add further keywords")
  138. else print("unknown command>service" .. pts[2])
  139. end
  140. else print("unknown command: " .. pts[1])
  141. end
  142. end
Add Comment
Please, Sign In to add comment