dcleondc

startup

Sep 6th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. --Luanub's LnShell Installer
  2.  
  3. local a = "false"
  4. local craft = os.version()
  5. local ver = "LnShell 1.0"
  6. local currentX = 2
  7. local currentY = 11
  8. local selection = 1
  9.  
  10. local uname = ""
  11. local pword = ""
  12. local perms = ""
  13. local user = {}
  14. local pass = {}
  15. local perm = {}
  16.  
  17.  
  18. function banner()
  19. shell.run("clear")
  20. print("=================================================")
  21. print (" | |")
  22. print (" | | /--\\ | | /--- | | |")
  23. print (" | | | | | | | | |")
  24. print (" | | /\\ | \\--\\ |--| |-- | | |")
  25. print (" | | | \\ | || | | | | |")
  26. print (" | \\--- | \\| \\--/ | | \\--- \\--- \\--- |")
  27. print (" | |")
  28. print("=================================================")
  29. end
  30.  
  31. function drawMenu()
  32. banner()
  33. term.setCursorPos(4, 11)
  34. local version = string.sub(ver, 9)
  35. if not fs.exists("/LnShell/os") then
  36. print ("Install LnShell Version "..version)
  37. else
  38. write ("Uninstall LnShell")
  39. end
  40. term.setCursorPos(4, 12)
  41. write ("Exit")
  42. end
  43.  
  44. function drawCursor()
  45. term.setCursorPos(currentX, currentY)
  46. write("->")
  47. end
  48.  
  49. function installShell()
  50. shell.run("clear")
  51. banner()
  52. term.setCursorPos(1, 10)
  53. textutils.slowWrite ("Installing files.")
  54. if not fs.isDir("/LnShell") then fs.makeDir("/LnShell") end
  55. sleep(.1) write(".")
  56. if not fs.isDir("/LnShell/apis") then fs.makeDir("/LnShell/apis") end
  57. sleep(.1) write(".")
  58. if not fs.isDir("/LnShell/.fya1976") then fs.makeDir("/LnShell/.fya1976") end
  59. sleep(.1) write(".")
  60. if not fs.isDir("/LnShell/programs") then fs.makeDir("/LnShell/programs") end
  61. sleep(.1) write(".")
  62. if not fs.isDir("/LnShell/.fya1976/.unames") then fs.makeDir("/LnShell/.fya1976/.unames") end
  63. sleep(.1) write(".")
  64. if not fs.isDir("/LnShell/.fya1976/.pwords") then fs.makeDir("/LnShell/.fya1976/.pwords") end
  65. sleep(.1) write(".")
  66. if not fs.isDir("/LnShell/.fya1976/.perm") then fs.makeDir("/LnShell/.fya1976/.perm") end
  67. sleep(.1) write(".")
  68. if not fs.exists("/LnShell/os") then fs.copy("disk/os.lua", "/LnShell/os") end
  69. sleep(.1) write(".")
  70. if not fs.exists("/LnShell/apis/login") then fs.copy("disk/login", "/LnShell/apis/login") end
  71. sleep(.1) write(".")
  72. if not fs.exists("/LnShell/programs/gedit") then fs.copy("disk/gedit", "/LnShell/programs/gedit") end
  73. sleep(.1) write(".")
  74. if not fs.exists("/LnShell/programs/fileman") then fs.copy("disk/fman", "/LnShell/programs/fileman") end
  75. sleep(.1) write(".")
  76. local file = io.open("/startup", "w")
  77. file:write("shell.run(\"/LnShell/os\")")
  78. file:close()
  79. sleep(.1) write(".")
  80. term.setCursorPos(1,12)
  81. write ("Would you like to setup admin account now y/n? ")
  82. local input1 = string.lower(read())
  83. if input1 == "y" then
  84. shell.run("clear")
  85. banner()
  86. term.setCursorPos(1, 12)
  87. write ("Username:")
  88. term.setCursorPos(1,13)
  89. write ("Password:")
  90. term.setCursorPos(11,12)
  91. uname = read()
  92. term.setCursorPos(11,13)
  93. pword = read("*")
  94. perms = "admin"
  95. table.insert(user, uname)
  96. table.insert(user, "guest")
  97. table.insert(pass, pword)
  98. table.insert(pass, "guest")
  99. table.insert(perm, perms)
  100. table.insert(perm, "guest")
  101. print ("Admin "..uname.." has been created")
  102. print ("User guest was also created, password = guest")
  103. print ("Press Enter to continue")
  104. os.pullEvent("key")
  105. while true do
  106. shell.run("clear")
  107. banner()
  108. term.setCursorPos(1, 11)
  109. write ("Add additional users now y/n? ")
  110. local input2 = string.lower(read())
  111. if input2 == "y" then
  112. shell.run("clear")
  113. banner()
  114. term.setCursorPos(1, 12)
  115. write ("Username:")
  116. term.setCursorPos(1,13)
  117. write ("Password:")
  118. term.setCursorPos(1,14)
  119. write ("Account Type(admin/user):")
  120. term.setCursorPos(11,12)
  121. uname = read()
  122. term.setCursorPos(11,13)
  123. pword = read("*")
  124. term.setCursorPos(27,14)
  125. perms = read()
  126. table.insert(user, uname)
  127. table.insert(pass, pword)
  128. table.insert(perm, perms)
  129. print ("User "..uname.." has been created with "..perms.." access")
  130. print ("Press Enter to continue")
  131. os.pullEvent("key")
  132. elseif input2 == "n" then
  133. break
  134. end
  135. end
  136. if input1 == "y" or input2 == "y" then
  137. local sNames = textutils.serialize(user)
  138. local file = io.open("/LnShell/.fya1976/.unames/.users", "w")
  139. file:write(sNames)
  140. file:close()
  141. local sPass = textutils.serialize(pass)
  142. local file = io.open("/LnShell/.fya1976/.pwords/.pass", "w")
  143. file:write(sPass)
  144. file:close()
  145. local sPerms = textutils.serialize(perm)
  146. local file = io.open("/LnShell/.fya1976/.perm/.perms", "w")
  147. file:write(sPerms)
  148. file:close()
  149. end
  150. end
  151. shell.run("clear")
  152. banner()
  153. term.setCursorPos(1, 11)
  154. print ("Installation Complete")
  155. disk.eject("left")
  156. a = 5
  157. for x=1, 5 do
  158. term.setCursorPos(1,12)
  159. write ("System will reboot in "..a.." seconds")
  160. a = a - 1
  161. sleep(1)
  162. end
  163. os.reboot()
  164. end
  165.  
  166.  
  167. function uninstallShell()
  168. shell.run("clear")
  169. banner()
  170. term.setCursorPos(1, 11)
  171. write ("You are about to uninstall LnShell continue (y/n)? ")
  172. local input = string.lower(read())
  173. if input == "y" then
  174. term .setCursorPos(1, 13)
  175. textutils.slowWrite ("Uninstalling.")
  176. fs.delete("/startup")
  177. sleep(.1) write (".")
  178. fs.delete("/LnShell")
  179. for x=1, 8 do
  180. sleep(.1) write (".")
  181. end
  182. print ("\nLnShell Successfully Uninstalled")
  183. textutils.slowWrite ("System Rebooting...")
  184. sleep(.5)
  185. disk.eject("left")
  186. sleep(.5)
  187. os.reboot()
  188. end
  189. end
  190.  
  191. function Menu()
  192. while true do
  193. drawMenu()
  194. drawCursor()
  195. local event, p1 = os.pullEvent("key")
  196. if p1 == 17 or p1 == 200 then --up
  197. if selection - 1 >= 1 then
  198. selection = selection - 1
  199. currentY = currentY -1
  200. end
  201. elseif p1 == 31 or p1 == 208 then --down
  202. if selection + 1 <= 2 then
  203. selection = selection + 1
  204. currentY = currentY + 1
  205. end
  206. elseif p1 == 28 then -- enter key pressed
  207. if not fs.exists("/LnShell/os") and selection == 1 then
  208. installShell()
  209. elseif fs.exists("/LnShell/os") and selection == 1 then
  210. uninstallShell()
  211. elseif selection == 2 then
  212. shell.run("clear")
  213. return
  214. else
  215. print ("Error, selection out of bounds. Press Enter to continue")
  216. read()
  217. end
  218. end
  219. end
  220. end
  221.  
  222. Menu()
Advertisement
Add Comment
Please, Sign In to add comment