Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Luanub's LnShell Installer
- local a = "false"
- local craft = os.version()
- local ver = "LnShell 1.0"
- local currentX = 2
- local currentY = 11
- local selection = 1
- local uname = ""
- local pword = ""
- local perms = ""
- local user = {}
- local pass = {}
- local perm = {}
- function banner()
- shell.run("clear")
- print("=================================================")
- print (" | |")
- print (" | | /--\\ | | /--- | | |")
- print (" | | | | | | | | |")
- print (" | | /\\ | \\--\\ |--| |-- | | |")
- print (" | | | \\ | || | | | | |")
- print (" | \\--- | \\| \\--/ | | \\--- \\--- \\--- |")
- print (" | |")
- print("=================================================")
- end
- function drawMenu()
- banner()
- term.setCursorPos(4, 11)
- local version = string.sub(ver, 9)
- if not fs.exists("/LnShell/os") then
- print ("Install LnShell Version "..version)
- else
- write ("Uninstall LnShell")
- end
- term.setCursorPos(4, 12)
- write ("Exit")
- end
- function drawCursor()
- term.setCursorPos(currentX, currentY)
- write("->")
- end
- function installShell()
- shell.run("clear")
- banner()
- term.setCursorPos(1, 10)
- textutils.slowWrite ("Installing files.")
- if not fs.isDir("/LnShell") then fs.makeDir("/LnShell") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/apis") then fs.makeDir("/LnShell/apis") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/.fya1976") then fs.makeDir("/LnShell/.fya1976") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/programs") then fs.makeDir("/LnShell/programs") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/.fya1976/.unames") then fs.makeDir("/LnShell/.fya1976/.unames") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/.fya1976/.pwords") then fs.makeDir("/LnShell/.fya1976/.pwords") end
- sleep(.1) write(".")
- if not fs.isDir("/LnShell/.fya1976/.perm") then fs.makeDir("/LnShell/.fya1976/.perm") end
- sleep(.1) write(".")
- if not fs.exists("/LnShell/os") then fs.copy("disk/os.lua", "/LnShell/os") end
- sleep(.1) write(".")
- if not fs.exists("/LnShell/apis/login") then fs.copy("disk/login", "/LnShell/apis/login") end
- sleep(.1) write(".")
- if not fs.exists("/LnShell/programs/gedit") then fs.copy("disk/gedit", "/LnShell/programs/gedit") end
- sleep(.1) write(".")
- if not fs.exists("/LnShell/programs/fileman") then fs.copy("disk/fman", "/LnShell/programs/fileman") end
- sleep(.1) write(".")
- local file = io.open("/startup", "w")
- file:write("shell.run(\"/LnShell/os\")")
- file:close()
- sleep(.1) write(".")
- term.setCursorPos(1,12)
- write ("Would you like to setup admin account now y/n? ")
- local input1 = string.lower(read())
- if input1 == "y" then
- shell.run("clear")
- banner()
- term.setCursorPos(1, 12)
- write ("Username:")
- term.setCursorPos(1,13)
- write ("Password:")
- term.setCursorPos(11,12)
- uname = read()
- term.setCursorPos(11,13)
- pword = read("*")
- perms = "admin"
- table.insert(user, uname)
- table.insert(user, "guest")
- table.insert(pass, pword)
- table.insert(pass, "guest")
- table.insert(perm, perms)
- table.insert(perm, "guest")
- print ("Admin "..uname.." has been created")
- print ("User guest was also created, password = guest")
- print ("Press Enter to continue")
- os.pullEvent("key")
- while true do
- shell.run("clear")
- banner()
- term.setCursorPos(1, 11)
- write ("Add additional users now y/n? ")
- local input2 = string.lower(read())
- if input2 == "y" then
- shell.run("clear")
- banner()
- term.setCursorPos(1, 12)
- write ("Username:")
- term.setCursorPos(1,13)
- write ("Password:")
- term.setCursorPos(1,14)
- write ("Account Type(admin/user):")
- term.setCursorPos(11,12)
- uname = read()
- term.setCursorPos(11,13)
- pword = read("*")
- term.setCursorPos(27,14)
- perms = read()
- table.insert(user, uname)
- table.insert(pass, pword)
- table.insert(perm, perms)
- print ("User "..uname.." has been created with "..perms.." access")
- print ("Press Enter to continue")
- os.pullEvent("key")
- elseif input2 == "n" then
- break
- end
- end
- if input1 == "y" or input2 == "y" then
- local sNames = textutils.serialize(user)
- local file = io.open("/LnShell/.fya1976/.unames/.users", "w")
- file:write(sNames)
- file:close()
- local sPass = textutils.serialize(pass)
- local file = io.open("/LnShell/.fya1976/.pwords/.pass", "w")
- file:write(sPass)
- file:close()
- local sPerms = textutils.serialize(perm)
- local file = io.open("/LnShell/.fya1976/.perm/.perms", "w")
- file:write(sPerms)
- file:close()
- end
- end
- shell.run("clear")
- banner()
- term.setCursorPos(1, 11)
- print ("Installation Complete")
- disk.eject("left")
- a = 5
- for x=1, 5 do
- term.setCursorPos(1,12)
- write ("System will reboot in "..a.." seconds")
- a = a - 1
- sleep(1)
- end
- os.reboot()
- end
- function uninstallShell()
- shell.run("clear")
- banner()
- term.setCursorPos(1, 11)
- write ("You are about to uninstall LnShell continue (y/n)? ")
- local input = string.lower(read())
- if input == "y" then
- term .setCursorPos(1, 13)
- textutils.slowWrite ("Uninstalling.")
- fs.delete("/startup")
- sleep(.1) write (".")
- fs.delete("/LnShell")
- for x=1, 8 do
- sleep(.1) write (".")
- end
- print ("\nLnShell Successfully Uninstalled")
- textutils.slowWrite ("System Rebooting...")
- sleep(.5)
- disk.eject("left")
- sleep(.5)
- os.reboot()
- end
- end
- function Menu()
- while true do
- drawMenu()
- drawCursor()
- local event, p1 = os.pullEvent("key")
- if p1 == 17 or p1 == 200 then --up
- if selection - 1 >= 1 then
- selection = selection - 1
- currentY = currentY -1
- end
- elseif p1 == 31 or p1 == 208 then --down
- if selection + 1 <= 2 then
- selection = selection + 1
- currentY = currentY + 1
- end
- elseif p1 == 28 then -- enter key pressed
- if not fs.exists("/LnShell/os") and selection == 1 then
- installShell()
- elseif fs.exists("/LnShell/os") and selection == 1 then
- uninstallShell()
- elseif selection == 2 then
- shell.run("clear")
- return
- else
- print ("Error, selection out of bounds. Press Enter to continue")
- read()
- end
- end
- end
- end
- Menu()
Advertisement
Add Comment
Please, Sign In to add comment