Advertisement
Guest User

Opencomputers SecureOS installer.lua

a guest
Jan 17th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. local computer = require("computer")
  2. local fs = require("filesystem")
  3. local kb = require("keyboard")
  4. local event = require("event")
  5. local shell = require("shell")
  6. local term = require("term")
  7.  
  8. local running = true
  9.  
  10. local function greeting()
  11. term.clear()
  12. term.setCursor(1,1)
  13.   print("Welcome to the SecureOS installer!")
  14.   print("This installer will help guide you through setting up and installing SecureOS.")
  15.   print("Press any key to continue.")
  16. local event = event.pull("key_down")
  17.   if event and not kb.isControlDown() then
  18.     term.clear()
  19.     term.setCursor(1,1)
  20.   end
  21. end
  22.  
  23. local function downLoad()
  24.  
  25.   if not fs.exists("/tmp/.root") then
  26.     r = io.open("/tmp/.root", "w")
  27.      r:write("true")
  28.       r:close()
  29.   end
  30.  
  31.   if not fs.exists("/root/") then
  32.     fs.makeDirectory("/root/")
  33.   end
  34.  
  35.   if not fs.exists("/etc/update.cfg") then
  36.     c = io.open("/etc/update.cfg", "w")
  37.      c:write("release")
  38.       c:close()
  39.   end
  40.  
  41.   term.write("Please wait while the files are downloaded and installed.")
  42.   os.sleep(1)
  43.   term.setCursor(1,2)
  44.  
  45. shell.execute("wget https://raw.githubusercontent.com/Shuudoushi/SecureOS/release/bin/update.lua /bin/update.lua \n")
  46. shell.execute("/bin/update.lua")
  47. end
  48.  
  49. local function userInfo()
  50.   term.clear()
  51.   term.setCursor(1,1)
  52.   term.write("Please enter a username and password. Usernames must be lowercase.")
  53.   term.setCursor(1,2)
  54.   term.write("Username: ")
  55.     username = term.read()
  56.     username = string.gsub(username, "\n", "")
  57.     username = string.lower(username)
  58.   term.setCursor(1,3)
  59.   term.write("Password: ")
  60.     password = term.read(nil, nil, nil, "")
  61.     password = string.gsub(password, "\n", "")
  62.  
  63.   require("auth").addUser(username, password, true)
  64.  
  65.   if not fs.exists("/home/" .. username .. "/") then
  66.     fs.makeDirectory("/home/" .. username .. "/")
  67.     fs.makeDirectory("/home/" .. username .. "/bin/")
  68.     fs.makeDirectory("/home/" .. username .. "/lib/")
  69.     fs.makeDirectory("/home/" .. username .. "/var/")
  70.   end
  71.  
  72.   term.clear()
  73.   term.setCursor(1,1)
  74.   term.write("Would you like to restart now? [Y/n]")
  75.   term.setCursor(1,2)
  76.     input = term.read()
  77.     input = string.gsub(input, "\n", "")
  78.     input = string.lower(input)
  79.  
  80.     if input == "y" or input == "yes" then
  81.       computer.shutdown(true)
  82.     elseif input == "n" or input == "no" then
  83.       io.write("Returning to shell.")
  84.       os.sleep(1.5)
  85.       term.clear()
  86.       term.setCursor(1,1)
  87.       running = false
  88.     end
  89. end
  90.  
  91. while running do
  92.     greeting()
  93.     downLoad()
  94.     userInfo()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement