Advertisement
mypal125

CWCOS Installer - /bin/init

May 24th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. -- CWCOS and its installer is licensed under the BSD 3-Clause License.
  2. -- Copyright (c) 2014 ClassCoder
  3. -- See the license at http://opensource.org/licenses/BSD-3-Clause.
  4.  
  5. textcolor = colors.blue
  6. term.setTextColor(textcolor)
  7.  
  8. init = {}
  9.  
  10. function init.postmessageInfo(from, message)
  11.   write("["..from.."] ")
  12.   term.setTextColor(colors.lightBlue)
  13.   print(message)
  14.   term.setTextColor(textcolor)
  15. end
  16. function init.postmessageWarn(from, message)
  17.   write("["..from.."] ")
  18.   term.setTextColor(colors.orange)
  19.   print(message)
  20.   term.setTextColor(textcolor)
  21. end
  22. function init.postmessageError(from, message)
  23.   write("["..from.."] ")
  24.   term.setTextColor(colors.red)
  25.   print(message)
  26.   term.setTextColor(textcolor)
  27. end
  28.  
  29. function init.ok()
  30.   term.setTextColor(colors.green)
  31.   local sizex, sizey = term.getSize()
  32.   local x, y = term.getCursorPos()
  33.   term.setCursorPos(sizex-9, y-1)
  34.   print("[  OK  ]")
  35.   term.setTextColor(textcolor)
  36. end
  37. function init.fail()
  38.   term.setTextColor(colors.red)
  39.   local sizex, sizey = term.getSize()
  40.   local x, y = term.getCursorPos()
  41.   term.setCursorPos(sizex-9, y-1)
  42.   print("[ FAIL ]")
  43.   term.setTextColor(textcolor)
  44. end
  45. function init.termClear()
  46.   term.setTextColor(textcolor)
  47.   term.clear()
  48.   term.setCursorPos(1, 1)
  49. end
  50. function init.termReset()
  51.   term.setTextColor(textcolor)
  52. end
  53. local mon = peripheral.find("monitor")
  54. if mon then
  55.   init.monitor = mon
  56.   term.redirect(mon)
  57.   init.termClear()
  58. end
  59.  
  60. acpi = {}
  61.  
  62. function acpi.shutdown()
  63.   init.termReset()
  64.   init.postmessageInfo("init", "Shutting down")
  65.   for x,file in pairs(fs.list("/etc/init.d/off")) do
  66.     os.run(giveChild, "/etc/init.d/off/"..file)
  67.     term.setTextColor(textcolor)
  68.   end
  69.   init.postmessageInfo("init", "Telling kernel")
  70.   init.ok()
  71.   sleep(0.5)
  72.   kernel.shutdown()
  73. end
  74. function acpi.reboot()
  75.   init.termReset()
  76.   init.postmessageInfo("init", "Rebooting")
  77.   for x,file in pairs(fs.list("/etc/init.d/off")) do
  78.     os.run(giveChild, "/etc/init.d/off/"..file)
  79.     term.setTextColor(textcolor)
  80.   end
  81.   init.postmessageInfo("init", "Telling kernel")
  82.   init.ok()
  83.   sleep(0.5)
  84.   kernel.reboot()
  85. end
  86.  
  87. giveChild = {
  88.   ['init'] = init,
  89.   ['acpi'] = acpi,
  90.   ['textcolor'] = textcolor,
  91.   ['kernel'] = kernel,
  92. }
  93.  
  94. init.postmessageInfo("init", "Loading init")
  95. sleep(0.125)
  96. init.postmessageWarn("init", "Starting in single-user mode (runlevel 1)")
  97. sleep(0.125)
  98. for x,file in pairs(fs.list("/etc/init.d/on")) do
  99.   os.run(giveChild, "/etc/init.d/on/"..file)
  100.   init.termReset()
  101. end
  102. sleep(0.125)
  103. init.postmessageInfo("init", "Finished")
  104. init.ok()
  105. sleep(0.625)
  106. acpi.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement