Advertisement
fishermedders

FishOS Main

Nov 5th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. tUtils = fs.list("/bin/util/")
  2. for i = 1,#tUtils do
  3. os.loadAPI("/bin/util/"..tUtils[i])
  4. end
  5.  
  6. --Start Environment Variables Setup
  7. environment = {
  8. ["system"]={
  9. ["keys"]={},
  10. ["terminal"]={
  11. ["cmds"]={}
  12. },
  13. ["dirs"]={}
  14. },
  15. ["colors"]={}
  16. }
  17. --System
  18. environment.system.branch = "dev1"
  19. environment.system.keys = {nil,"1","2","3","4","5","6","7","8","9","0",nil,nil,nil,nil,"q","w","e","r","t","y","u","i","o","p",nil,nil,nil,nil,"a","s","d","f","g","h","j","k","l",nil,nil,nil,nil,nil,"z","x","c","v","b","n","m"}
  20. environment.system.user = nil
  21. environment.system.dirs = {"bin","boot","dev","etc","home","lib","lost+found","misc","mnt","net","opt","proc","root","sbin","tmp","usr","var"}
  22. --Colors
  23. environment.colors.background = colors.black
  24. environment.colors.text = colors.white
  25. environment.colors.vanity = colors.red
  26. --End Environmental Variable Setup
  27.  
  28. _G["exitcmd"] = false
  29.  
  30. users = {"fisher"}
  31. passwords = {"fishae"}
  32.  
  33.  
  34. function reset()
  35. term.setBackgroundColor(environment.colors.background)
  36. term.setTextColor(environment.colors.text)
  37. end
  38.  
  39. function auth(user,pass)
  40. pwfile = fs.open("/etc/shadow","r")
  41. tbl = textutils.unserialize(pwfile.readAll())
  42. pwfile.close()
  43. for i = 1,#tbl do
  44. for u = 1,#tbl[i] do
  45. if user == tbl[i][1] then
  46. if str.SHA1(pass) == tbl[i][2] then
  47. environment.system.user = user
  48. return true
  49. end
  50. end
  51. end
  52. end
  53. return false
  54. end
  55.  
  56. function invisread()
  57. returnstr = ""
  58. term.setCursorBlink(true)
  59. while true do
  60. evnt = {os.pullEvent("key")}
  61. if evnt[2] == 14 then
  62. returnstr = returnstr:sub(1,#returnstr-1)
  63. elseif evnt[2] == 28 then
  64. break
  65. else
  66. if environment.system.keys[evnt[2]] ~= nil then
  67. returnstr = returnstr..environment.system.keys[evnt[2]]
  68. end
  69. end
  70. end
  71. term.setCursorBlink(false)
  72. return returnstr
  73. end
  74.  
  75. function login()
  76. reset()
  77. term.setCursorPos(1,1)
  78. term.clear()
  79. print("")
  80. print("FishOS Core release "..environment.system.branch.." "..os.computerID())
  81. print("")
  82. write("FOSC "..os.computerID().." login: ")
  83. user = read()
  84. write("Password: ")
  85. pass = invisread()
  86. print(" ")
  87. tbl = {}
  88. table.insert(tbl,user)
  89. table.insert(tbl,pass)
  90. return tbl
  91. end
  92.  
  93. function dfind( sFile )
  94. if fs.exists( sFile ) then
  95. if not fs.isDir( sFile ) then
  96. return true
  97. end
  98. end
  99. return false
  100. end
  101.  
  102. if fs.exists("/etc/shadow") then
  103. file = fs.open("/etc/shadow","r")
  104. tbl = textutils.unserialize(file.readAll())
  105. for i = 1,#tbl do
  106. if not fs.isDir("home/"..tbl[i][1]) then
  107. fs.makeDir("home/"..tbl[i][1])
  108. end
  109. end
  110. tbl = nil
  111. end
  112.  
  113. for i = 1,#environment.system.dirs do
  114. if not fs.isDir(environment.system.dirs[i]) then
  115. fs.makeDir(environment.system.dirs[i])
  116. end
  117. end
  118.  
  119. if not fs.exists("/etc/shadow") then
  120. term.clear()
  121. term.setCursorPos(1,1)
  122. print("Welcome to FishOS, the only OS you'll need.")
  123. print(" ")
  124. print("FishOS has been customized to be very useful on the CL Tekkit server.")
  125. print(" ")
  126. print("We will now setup your first user account.")
  127. print("NOTE: You will be able to add more accounts later by using the command 'addusr'.")
  128. print("Also note, the password field will be invisible for security reasons.")
  129. term.write("User: ")
  130. user = read()
  131. term.write("Pass: ")
  132. pass = invisread()
  133. file = fs.open("/etc/shadow","w")
  134. ptbl = {}
  135. tbl = {}
  136. table.insert(tbl,user)
  137. table.insert(tbl,str.SHA1(pass))
  138. table.insert(ptbl,tbl)
  139. file.write(textutils.serialize(ptbl))
  140. file.close()
  141. print("User '"..user.."' added. Press any key to Continue!")
  142. os.pullEvent("key")
  143. os.reboot()
  144. end
  145.  
  146. function boot()
  147. while true do
  148. _G["logout"] = false
  149. l = login()
  150. if auth(l[1],l[2]) then
  151. print("Welcome to FishOS Core Release "..environment.system.branch.." "..os.computerID())
  152. print(" ")
  153. print(" * Documentation: /usr/share/doc/")
  154. print(" * Support: XMedders ingame")
  155. print(" ")
  156. print("[num] Packages can be updated.")
  157. print("[num] updates are security updates.")
  158. print(" ")
  159. print(" ")
  160. write("The programs included with the FishOS system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/copyright")
  161. print(" ")
  162. write("FishOS comes with no warranty, but ask XMedders ingame for a new copy and he will give ya one :D")
  163. print(" ")
  164. print(" ")
  165. print(" ")
  166. print("Press any Key to continue")
  167. os.pullEvent("key")
  168. while true do
  169. if _G["exitcmd"] or _G["logout"] then
  170. break
  171. end
  172. if shell.dir() == "" then
  173. dir = ""
  174. else
  175. dir = "/"..shell.dir()
  176. end
  177. label = ""
  178. if os.getComputerLabel() ~= nil then
  179. label = os.getComputerLabel()
  180. else
  181. label = "Comp"
  182. end
  183. write(environment.system.user.."@"..label.."-"..os.computerID()..":~"..dir.."$ ")
  184. console = read(nil, environment.system.terminal.cmds)
  185. table.insert(environment.system.terminal.cmds,console)
  186. found = false
  187. if console:gsub(" ","") ~= "" then
  188. args = {}
  189. for arg in console:gmatch("%w+") do table.insert(args, arg) end
  190. if dfind("/bin/"..args[1]) then
  191. found = true
  192. shell.run("/bin/"..console)
  193. end
  194. end
  195. if not found then
  196. shell.run(console)
  197. end
  198. reset()
  199. end
  200. end
  201. if _G["exitcmd"] then
  202. break
  203. end
  204. end
  205. end
  206.  
  207. boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement