Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sUserStartup = false
- -- FORMAT FOR BIOS.LUA/OS MAKING:
- -- #*path of OS startup INSIDE OF DISK (don't add disk/)*
- -- *anything here will be ignored*
- -- *insert ur code here*
- local parentShell = shell
- local bExit = false
- local sDir = (parentShell and parentShell.dir()) or ""
- local sPath = (parentShell and parentShell.path()) or ".:/rom/programs"
- local tAliases = (parentShell and parentShell.aliases()) or {}
- local tProgramStack = {}
- local shell = {}
- local tEnv = {
- ["shell"] = shell,
- }
- -- Install shell API
- function shell.run( _sCommand, ... )
- local sPath = shell.resolveProgram( _sCommand )
- if sPath ~= nil then
- tProgramStack[#tProgramStack + 1] = sPath
- local result = os.run( tEnv, sPath, ... )
- tProgramStack[#tProgramStack] = nil
- return result
- else
- print( "No such program" )
- return false
- end
- end
- function shell.exit()
- bExit = true
- end
- function shell.dir()
- return sDir
- end
- function shell.setDir( _sDir )
- sDir = _sDir
- end
- function shell.path()
- return sPath
- end
- function shell.setPath( _sPath )
- sPath = _sPath
- end
- function shell.resolve( _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
- function shell.resolveProgram( _sCommand )
- -- Substitute aliases firsts
- if tAliases[ _sCommand ] ~= nil then
- _sCommand = tAliases[ _sCommand ]
- end
- -- If the path is a global path, use it directly
- local sStartChar = string.sub( _sCommand, 1, 1 )
- if sStartChar == "/" or sStartChar == "\\" then
- local sPath = fs.combine( "", _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return sPath
- end
- return nil
- end
- -- Otherwise, look on the path variable
- for sPath in string.gmatch(sPath, "[^:]+") do
- sPath = fs.combine( shell.resolve( sPath ), _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return sPath
- end
- end
- -- Not found
- return nil
- end
- function shell.programs( _bIncludeHidden )
- local tItems = {}
- -- Add programs from the path
- for sPath in string.gmatch(sPath, "[^:]+") do
- sPath = shell.resolve( sPath )
- if fs.isDir( sPath ) then
- local tList = fs.list( sPath )
- for n,sFile in pairs( tList ) do
- if not fs.isDir( fs.combine( sPath, sFile ) ) and
- (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
- tItems[ sFile ] = true
- end
- end
- end
- end
- -- Sort and return
- local tItemList = {}
- for sItem, b in pairs( tItems ) do
- table.insert( tItemList, sItem )
- end
- table.sort( tItemList )
- return tItemList
- end
- function shell.getRunningProgram()
- if #tProgramStack > 0 then
- return tProgramStack[#tProgramStack]
- end
- return nil
- end
- function shell.setAlias( _sCommand, _sProgram )
- tAliases[ _sCommand ] = _sProgram
- end
- function shell.clearAlias( _sCommand )
- tAliases[ _sCommand ] = nil
- end
- function shell.aliases()
- -- Add aliases
- local tCopy = {}
- for sAlias, sCommand in pairs( tAliases ) do
- tCopy[sAlias] = sCommand
- end
- return tCopy
- end
- -- Attempt to boot the disks bios.
- for n,sSide in pairs( redstone.getSides() ) do
- if disk.isPresent( sSide ) and disk.hasData( sSide ) then
- sDiskStartup = fs.exists( "disk/bios.lua" )
- if sDiskStartup then
- sUserStartup = true
- break
- end
- end
- end
- if sUserStartup then
- local tLines = {}
- local file = io.open("disk/bios.lua", "r")
- local line
- while true do
- line = file:read()
- if not line then break end
- tLines[#tLines+1] = line
- end
- file:close()
- if string.find( tLines[1], "#" ) then
- sUserStartup = string.sub( tLines[1], 2, string.len( tLines[1] ) )
- fs.delete("disk/.bios.lua.CNFG")
- local file2 = fs.open("disk/.bios.lua.CNFG", "w")
- for i = 3, #tLines do
- file2.writeLine(tLines[i])
- end
- file2:close()
- shell.run( "disk/.bios.lua.CNFG" )
- shell.run( "disk/" ..sUserStartup )
- else
- print( "unsuported/corrupted bios." )
- sleep(2)
- os.shutdown()
- end
- else
- print( "bios undetected." )
- print( "Please insert a boot disk." )
- sleep(2)
- os.shutdown()
- end
Advertisement
Add Comment
Please, Sign In to add comment