Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bExit = false
- local sDir = (shell and shell.dir()) or ""
- local tEnv = {}
- local function fnRun( _sCommand, ... )
- -- Look in the current dir first
- local sPath = fs.combine( sDir, _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return os.run( tEnv, sPath, ... )
- end
- -- Then look at programs
- local sPath = fs.combine( "rom/programs", _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return os.run( tEnv, sPath, ... )
- end
- -- Then fail
- print( "No such program" )
- return false
- end
- -- Install shell API -- startup
- tEnv["shell"] = {
- ["exit"] = function( )
- bExit = true
- end,
- ["dir"] = function( )
- return sDir
- end,
- ["setDir"] = function( _sDir )
- sDir = _sDir
- end,
- ["resolve"] = function( _sPath )
- local sStartChar = string.sub( _sPath, 1, 1 )
- if sStartChar == "/" or sStartChar == "\\" then
- return fs.combine( "", _sPath )
- else
- return fs.combine( sDir, _sPath )
- end
- end,
- ["run"] = function( _sCommand, ... )
- fnRun( _sCommand, ... )
- end,
- }
- print( os.version() )
- print("______ _ _ _ _ ___ _ _ _ _ _____ _____ __ ")
- print("| ___ \ | || | | | | | / _ \ | | | | | | | || _ | | _ |/ | ")
- print("| |_/ / ___ __| || | | | ___ _ __ | | __ ___ / /_\ \| | _ __ | |__ __ _ | | | || |/' | | |/' |`| | ")
- print("| / / _ \ / _` || |/\| | / _ \ | '__|| |/ // __| | _ || || '_ \ | '_ \ / _` | | | | || /| | | /| | | | ")
- print("| |\ \| __/| (_| |\ /\ /| (_) || | | < \__ \ | | | || || |_) || | | || (_| | \ \_/ /\ |_/ /_\ |_/ /_| |_")
- print("\_| \_|\___| \__,_| \/ \/ \___/ |_| |_|\_\|___/ \_| |_/|_|| .__/ |_| |_| \__,_| \___/ \___/(_)\___/ \___/")
- print(" | | ")
- print(" |_| ")
- passwords = {
- ['Sarkynin'] = '12345',
- ['root'] = 'root'
- }
- term.clear()term.setCursorPos(1,1)
- while true do
- print '\nUsername'
- user = read()
- if passwords[user] ~= nil then
- break
- end
- print '\nInvalid Username'
- sleep(1)
- end
- tries = 5
- while tries > 0
- do print '\nPassword'
- pass = read()
- if passwords[user] == pass then
- break
- end
- print '\nIncorrect Password'
- tries = tries - 1
- sleep(1)
- end
- if tries <= 0 then
- print '\nMaximum number of tries used.'
- sleep(2)
- print 'System will now shut down.'
- sleep(2)
- os.shutdown()
- end
- print('\nWelcome, ' .. user .. '.')
- local tArgs = { ... }
- if #tArgs > 0 then
- fnRun( ... )
- end
- while not bExit do
- io.write( sDir .. "> " )
- local sLine = read( )
- local tWords = {}
- for match in string.gmatch(sLine, "[^ \t]+") do
- table.insert( tWords, match )
- end
- local sCommand = tWords[1]
- if sCommand then
- fnRun( sCommand, unpack( tWords, 2 ) )
- end
- end
Add Comment
Please, Sign In to add comment