Ocawesome101

CC-OS Installer

Jan 2nd, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. -- CC-OS installer to accompany CC-BIOS --
  2.  
  3. shell = {}
  4. function shell.resolve(path) -- Make GitGet work!
  5.   return path
  6. end
  7.  
  8. local function find(sStr, tChars)
  9.     for i=1, #tChars, 1 do
  10.         if sStr:find(tChars[i], 1, true) then
  11.             return true
  12.         end
  13.     end
  14.     return false
  15. end
  16.  
  17. local function num(str)
  18.   local rtn = {}
  19.   for i=1, #str, 1 do
  20.     table.insert(rtn, keys[str:sub(i,i)])
  21.     print(str:sub(i,i), keys[str:sub(i,i)])
  22.   end
  23.  
  24.   return rtn
  25. end
  26.  
  27. local function encode(str)
  28.   local rtn = ""
  29.   local tNum = num(str)
  30.   for i=1, #tNum, 1 do
  31.     rtn = rtn .. tostring(bit32.arshift(tNum[i], i))
  32.     if i < #tNum then
  33.       rtn = rtn .. ":"
  34.     end
  35.   end
  36.  
  37.   return rtn
  38. end
  39.  
  40. local function generateFile(uname, pwd)
  41.   return "return {\n  {\n    username = " .. uname .. ",\n    uid = 1,\n    password = " .. pwd .. "\n  }\n}"
  42. end
  43.  
  44. local data = http.get("https://pastebin.com/raw/W5ZkVYSi")
  45. local exec = loadstring(data.readAll())
  46. data.close()
  47. exec("ocawesome101", "cc-os")
  48.  
  49. term.clear()
  50. term.setCursorPos(1,1)
  51. print("CC-OS has been installed. There is now some basic setup to do.")
  52.  
  53. local specialChars = {" ", "/", "?", ".", ",", "<", ">", "\"", "'", "|", "[", "]", "{", "}", "-", "_", "+", "=", "(", ")", "`", "~", "!", "@", "#", "$", "\%", "^", "&", "*"} -- Sorry
  54. local uname, passwd = "", ""
  55.  
  56. while true do
  57.     write("Enter a username: ")
  58.     uname = read()
  59.  
  60.     if find(uname, specialChars) then
  61.         printError("Usernames cannot contain special characters.")
  62.     else
  63.         break
  64.     end
  65. end
  66.  
  67. while true do
  68.     write("Enter a password: ")
  69.  
  70.     passwd = read("*")
  71.  
  72.     if #passwd < 4 then
  73.         break
  74.     else
  75.         print("Password must be four or more characters.")
  76.     end
  77. end
  78.  
  79. passwd = encode(passwd)
  80.  
  81. local toWrite = generateFile(uname, passwd)
  82.  
  83. print("The following operations will be performed:")
  84. print("Create /home/" .. uname)
  85. print("Store " .. toWrite .. " in /etc/passwd")
  86.  
  87. write("Apply changes? [y/n]: ")
  88.  
  89. local c = read()
  90.  
  91. if c:lower() == "n" then
  92.     print("I hope you know the root password!")
  93.     sleep(1)
  94.     os.reboot()
  95. end
  96.  
  97. fs.makeDir("/etc")
  98. fs.makeDir("/home/" .. uname)
  99.  
  100. local handle = fs.open("/etc/passwd")
  101. handle.write(toWrite)
  102. handle.close()
  103.  
  104. print("Done")
  105.  
  106. sleep(2)
  107. os.reboot()
Add Comment
Please, Sign In to add comment