Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputTable = {
- bin = {
- which = "print(shell.resolveProgram(...))",
- login = "os.loadAPI(\"/kernel/sha256\")\
- term.clear()\
- term.setCursorPos(1,1)\
- if term.isColor() then term.setTextColor(colors.yellow) end\
- print(os.version()..\": Login\")\
- if term.isColor() then term.setTextColor(colors.white) end\
- write(\"Username: \")\
- local user = read()\
- write(\"Password: \")\
- local pass = read(\"\")\
- local h = fs.open(\"/etc/passwd\",\"r\")\
- local passwd = textutils.unserialize(h.readAll())\
- h.close()\
- if next(passwd)==nil then return \"root\",\"\" end\
- if passwd[user] == nil then\
- printError(\"Invalid user or password\")\
- sleep(3)\
- os.shutdown()\
- else\
- if passwd[user].pass ~= sha256.sha256(pass) then\
- printError(\"Invalid user or password\")\
- sleep(3)\
- os.shutdown()\
- end\
- end\
- if bash then\
- bash.user = function() return user end\
- bash.curHomeDir = function() return passwd[user].homedir end\
- else\
- return user,passwd[user].homedir\
- end",
- cat = "local tArgs = {...}\
- if #tArgs~=1 then\
- print(\"Usage: cat <file>\")\
- error(\"\",0)\
- end\
- local h = fs.open(tArgs[1],\"r\")\
- if not h then error(\"File not found\",0) end\
- print(h.readAll())\
- h.close()",
- version = "print(os.version())",
- panic = "prevState = {}\
- prevState.isCCLinux = os.isCCLinux\
- prevState.version = os.version\
- prevState.dir = shell.dir()\
- os.isCCLinux = nil\
- os.version = function() return \"CraftOS 1.7\" end\
- term.clear()\
- term.setCursorPos(1,1)\
- shell.setDir(\"\")\
- shell.run(\"shell\")\
- term.clear()\
- term.setCursorPos(1,1)\
- os.isCCLinux = prevState.isCCLinux\
- os.version = prevState.version\
- shell.setDir(prevState.dir)",
- mkuser = "os.loadAPI(\"/kernel/sha256\")\
- local h = fs.open(\"/etc/passwd\",\"r\")\
- local passwd = textutils.unserialise(h.readAll())\
- h.close()\
- write(\"Username: \")\
- local name = read()\
- passwd[name] = {}\
- passwd[name].homedir = \"home/\"..name\
- if not fs.exists(passwd[name].homedir) then fs.makeDir(passwd[name].homedir) end\
- write(\"Password: \")\
- passwd[name].pass = sha256.sha256(read(\"\"))\
- h = fs.open(\"/etc/passwd\",\"w\")\
- h.write(textutils.serialise(passwd))\
- h.close()",
- less = "local tArgs = {...}\
- if #tArgs ~= 1 then\
- print(\"Usage: less <path>\")\
- error(\"\",0)\
- end\
- if not fs.exists(tArgs[1]) then error(\"File not found\",0) end\
- term.clear()\
- term.setCursorPos(1,1)\
- local lineNum = 1\
- local lines = {}\
- local w,h = term.getSize()\
- h = h - 2 -- Weird hack to make long file handling work\
- local function getFile(n)\
- local ret = {}\
- local h = fs.open(n,\"r\")\
- local nextLine = h.readLine()\
- while nextLine do\
- table.insert(ret,nextLine)\
- nextLine = h.readLine()\
- end\
- return ret\
- end\
- \
- lines = getFile(tArgs[1])\
- \
- local function showLines(l,n)\
- local atbottom = (n>(#l-h))\
- local bottom = #l-h\
- for i=(atbottom and bottom or n),(atbottom and #l or n+h) do\
- if l[i] then print(l[i]) else print() end\
- end\
- end\
- \
- local first = true\
- \
- while true do\
- showLines(lines,lineNum)\
- local _,k = os.pullEvent(\"key\")\
- if k == keys.down then lineNum = lineNum + 1 end\
- if k == keys.up then lineNum = lineNum - 1 end\
- if lineNum > #lines then lineNum = #lines end\
- if lineNum < 1 then lineNum = 1 end\
- if k == keys.q then\
- os.pullEvent(\"char\")\
- error(\"\",0)\
- end\
- term.clear()\
- term.setCursorPos(1,1)\
- end",
- whoami = "if bash then print(bash.user()) else print(\"Unknown\") end",
- passwd = "os.loadAPI(\"/kernel/sha256\")\
- local h = fs.open(\"/etc/passwd\",\"r\")\
- local passwd = textutils.unserialise(h.readAll())\
- h.close()\
- local name = ...\
- if name ~= bash.user() and bash.user()~=\"root\" then error(\"Can't set someone else's password!\",0) end\
- write(\"Password: \")\
- passwd[name].pass = sha256.sha256(read(\"\"))\
- h = fs.open(\"/etc/passwd\",\"w\")\
- h.write(textutils.serialise(passwd))\
- h.close()",
- },
- [ ".settings" ] = "{\
- [ \"bios.use_multishell\" ] = true,\
- [ \"shell.autocomplete\" ] = true,\
- [ \"shell.allow_disk_startup\" ] = true,\
- [ \"shell.allow_startup\" ] = true,\
- [ \"lua.autocomplete\" ] = true,\
- [ \"list.show_hidden\" ] = false,\
- [ \"bash.autocomplete\" ] = true,\
- [ \"edit.autocomplete\" ] = true,\
- }",
- kernel = {
- sha256 = "\
- -- \
- -- Adaptation of the Secure Hashing Algorithm (SHA-244/256)\
- -- Found Here: http://lua-users.org/wiki/SecureHashAlgorithm\
- -- \
- -- Using an adapted version of the bit library\
- -- Found Here: https://bitbucket.org/Boolsheet/bslf/src/1ee664885805/bit.lua\
- -- \
- \
- local MOD = 2^32\
- local MODM = MOD-1\
- \
- local function memoize(f)\
- \009local mt = {}\
- \009local t = setmetatable({}, mt)\
- \009function mt:__index(k)\
- \009\009local v = f(k)\
- \009\009t[k] = v\
- \009\009return v\
- \009end\
- \009return t\
- end\
- \
- local function make_bitop_uncached(t, m)\
- \009local function bitop(a, b)\
- \009\009local res,p = 0,1\
- \009\009while a ~= 0 and b ~= 0 do\
- \009\009\009local am, bm = a % m, b % m\
- \009\009\009res = res + t[am][bm] * p\
- \009\009\009a = (a - am) / m\
- \009\009\009b = (b - bm) / m\
- \009\009\009p = p*m\
- \009\009end\
- \009\009res = res + (a + b) * p\
- \009\009return res\
- \009end\
- \009return bitop\
- end\
- \
- local function make_bitop(t)\
- \009local op1 = make_bitop_uncached(t,2^1)\
- \009local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\
- \009return make_bitop_uncached(op2, 2 ^ (t.n or 1))\
- end\
- \
- local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\
- \
- local function bxor(a, b, c, ...)\
- \009local z = nil\
- \009if b then\
- \009\009a = a % MOD\
- \009\009b = b % MOD\
- \009\009z = bxor1(a, b)\
- \009\009if c then z = bxor(z, c, ...) end\
- \009\009return z\
- \009elseif a then return a % MOD\
- \009else return 0 end\
- end\
- \
- local function band(a, b, c, ...)\
- \009local z\
- \009if b then\
- \009\009a = a % MOD\
- \009\009b = b % MOD\
- \009\009z = ((a + b) - bxor1(a,b)) / 2\
- \009\009if c then z = bit32_band(z, c, ...) end\
- \009\009return z\
- \009elseif a then return a % MOD\
- \009else return MODM end\
- end\
- \
- local function bnot(x) return (-1 - x) % MOD end\
- \
- local function rshift1(a, disp)\
- \009if disp < 0 then return lshift(a,-disp) end\
- \009return math.floor(a % 2 ^ 32 / 2 ^ disp)\
- end\
- \
- local function rshift(x, disp)\
- \009if disp > 31 or disp < -31 then return 0 end\
- \009return rshift1(x % MOD, disp)\
- end\
- \
- local function lshift(a, disp)\
- \009if disp < 0 then return rshift(a,-disp) end \
- \009return (a * 2 ^ disp) % 2 ^ 32\
- end\
- \
- local function rrotate(x, disp)\
- x = x % MOD\
- disp = disp % 32\
- local low = band(x, 2 ^ disp - 1)\
- return rshift(x, disp) + lshift(low, 32 - disp)\
- end\
- \
- local k = {\
- \0090x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
- \0090x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
- \0090xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
- \0090x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
- \0090xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
- \0090x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
- \0090x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
- \0090xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
- \0090x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
- \0090x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
- \0090xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
- \0090xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
- \0090x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
- \0090x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
- \0090x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
- \0090x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
- }\
- \
- local function str2hexa(s)\
- \009return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\
- end\
- \
- local function num2s(l, n)\
- \009local s = \"\"\
- \009for i = 1, n do\
- \009\009local rem = l % 256\
- \009\009s = string.char(rem) .. s\
- \009\009l = (l - rem) / 256\
- \009end\
- \009return s\
- end\
- \
- local function s232num(s, i)\
- \009local n = 0\
- \009for i = i, i + 3 do n = n*256 + string.byte(s, i) end\
- \009return n\
- end\
- \
- local function preproc(msg, len)\
- \009local extra = 64 - ((len + 9) % 64)\
- \009len = num2s(8 * len, 8)\
- \009msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\
- \009assert(#msg % 64 == 0)\
- \009return msg\
- end\
- \
- local function initH256(H)\
- \009H[1] = 0x6a09e667\
- \009H[2] = 0xbb67ae85\
- \009H[3] = 0x3c6ef372\
- \009H[4] = 0xa54ff53a\
- \009H[5] = 0x510e527f\
- \009H[6] = 0x9b05688c\
- \009H[7] = 0x1f83d9ab\
- \009H[8] = 0x5be0cd19\
- \009return H\
- end\
- \
- local function digestblock(msg, i, H)\
- \009local w = {}\
- \009for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\
- \009for j = 17, 64 do\
- \009\009local v = w[j - 15]\
- \009\009local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\
- \009\009v = w[j - 2]\
- \009\009w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\
- \009end\
- \
- \009local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\
- \009for i = 1, 64 do\
- \009\009local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\
- \009\009local maj = bxor(band(a, b), band(a, c), band(b, c))\
- \009\009local t2 = s0 + maj\
- \009\009local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\
- \009\009local ch = bxor (band(e, f), band(bnot(e), g))\
- \009\009local t1 = h + s1 + ch + k[i] + w[i]\
- \009\009h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\
- \009end\
- \
- \009H[1] = band(H[1] + a)\
- \009H[2] = band(H[2] + b)\
- \009H[3] = band(H[3] + c)\
- \009H[4] = band(H[4] + d)\
- \009H[5] = band(H[5] + e)\
- \009H[6] = band(H[6] + f)\
- \009H[7] = band(H[7] + g)\
- \009H[8] = band(H[8] + h)\
- end\
- \
- function sha256(msg)\
- \009msg = preproc(msg, #msg)\
- \009local H = initH256({})\
- \009for i = 1, #msg, 64 do digestblock(msg, i, H) end\
- \009return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\
- \009\009num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\
- end",
- boot = "--TLCO\
- local tlco_lp = {\
- function() os.run({},\"/kernel/bash\") end\
- }\
- local prevState = {}\
- prevState.shutdown = function() end\
- local function recover()\
- --Fix os.shutdown\
- os.shutdown = prevState.shutdown\
- --Ditch rednet\
- _G[\"rednet\"] = nil\
- end\
- local function _os_shutdown()\
- recover()\
- term.clear()\
- term.setCursorPos(1,1)\
- os.isCCLinux = function() return true end\
- os.version = function() return \"CCLinux v0.1b\" end\
- parallel.waitForAny(unpack(tlco_lp))\
- sleep(3)\
- os.shutdown()\
- end\
- local function inject()\
- prevState.shutdown = os.shutdown\
- os.shutdown = _os_shutdown\
- end\
- local function exploit()\
- inject()\
- shell.exit()\
- end\
- exploit()",
- bash = "local multishell = multishell\
- local parentShell = bash\
- local parentTerm = term.current()\
- \
- if multishell then\
- multishell.setTitle( multishell.getCurrent(), \"bash\" )\
- end\
- \
- 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 {[\"bash\"]=\"/kernel/bash\"}\
- local tCompletionInfo = (parentShell and parentShell.getCompletionInfo()) or {}\
- local tProgramStack = {}\
- \
- local bash = {}\
- local tEnv = {\
- \009[ \"shell\" ] = bash,\
- \009[ \"bash\" ] = bash,\
- \009[ \"multishell\" ] = multishell,\
- }\
- \
- -- Colours\
- local promptColour, textColour, bgColour\
- if term.isColour() then\
- \009promptColour = colours.yellow\
- \009textColour = colours.white\
- \009bgColour = colours.black\
- else\
- \009promptColour = colours.white\
- \009textColour = colours.white\
- \009bgColour = colours.black\
- end\
- \
- local function run( _sCommand, ... )\
- \009local sPath = bash.resolveProgram( _sCommand )\
- \009if sPath ~= nil then\
- \009\009tProgramStack[#tProgramStack + 1] = sPath\
- \009\009if multishell then\
- \009\009 multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\
- \009\009end\
- \009\009local result = os.run( tEnv, sPath, ... )\
- \009\009tProgramStack[#tProgramStack] = nil\
- \009\009if multishell then\
- \009\009 if #tProgramStack > 0 then\
- \009\009 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\
- \009\009else\
- \009\009 multishell.setTitle( multishell.getCurrent(), \"shell\" )\
- \009\009end\
- \009\009end\
- \009\009return result\
- \009else\
- \009printError( \"No such program\" )\
- \009return false\
- end\
- end\
- \
- local function tokenise( ... )\
- local sLine = table.concat( { ... }, \" \" )\
- \009local tWords = {}\
- local bQuoted = false\
- for match in string.gmatch( sLine .. \"\\\"\", \"(.-)\\\"\" ) do\
- if bQuoted then\
- table.insert( tWords, match )\
- else\
- for m in string.gmatch( match, \"[^ \\t]+\" ) do\
- table.insert( tWords, m )\
- end\
- end\
- bQuoted = not bQuoted\
- end\
- return tWords\
- end\
- \
- -- Install bash API\
- function bash.run( ... )\
- \009local tWords = tokenise( ... )\
- \009local sCommand = tWords[1]\
- \009if sCommand then\
- \009\009return run( sCommand, table.unpack( tWords, 2 ) )\
- \009end\
- \009return false\
- end\
- \
- function bash.exit()\
- bExit = true\
- end\
- \
- function bash.dir()\
- \009return sDir\
- end\
- \
- function bash.setDir( _sDir )\
- \009sDir = _sDir\
- end\
- \
- function bash.path()\
- \009return sPath\
- end\
- \
- function bash.setPath( _sPath )\
- \009sPath = _sPath\
- end\
- \
- function bash.resolve( _sPath )\
- \009local sStartChar = string.sub( _sPath, 1, 1 )\
- \009if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
- \009\009return fs.combine( \"\", _sPath )\
- \009else\
- \009\009return fs.combine( sDir, _sPath )\
- \009end\
- end\
- \
- function bash.resolveProgram( _sCommand )\
- \009-- Substitute aliases firsts\
- \009if tAliases[ _sCommand ] ~= nil then\
- \009\009_sCommand = tAliases[ _sCommand ]\
- \009end\
- \
- -- If the path is a global path, use it directly\
- local sStartChar = string.sub( _sCommand, 1, 1 )\
- if sStartChar == \"/\" or sStartChar == \"\\\\\" then\
- \009local sPath = fs.combine( \"\", _sCommand )\
- \009if fs.exists( sPath ) and not fs.isDir( sPath ) then\
- \009\009\009return sPath\
- \009end\
- \009\009return nil\
- end\
- \
- \009-- Otherwise, look on the path variable\
- for sPath in string.gmatch(sPath, \"[^:]+\") do\
- \009sPath = fs.combine( bash.resolve( sPath ), _sCommand )\
- \009if fs.exists( sPath ) and not fs.isDir( sPath ) then\
- \009\009\009return sPath\
- \009end\
- end\
- \009\
- \009-- Not found\
- \009return nil\
- end\
- \
- function bash.programs( _bIncludeHidden )\
- \009local tItems = {}\
- \009\
- \009-- Add programs from the path\
- for sPath in string.gmatch(sPath, \"[^:]+\") do\
- \009sPath = bash.resolve( sPath )\
- \009\009if fs.isDir( sPath ) then\
- \009\009\009local tList = fs.list( sPath )\
- for n=1,#tList do\
- local sFile = tList[n]\
- \009\009\009\009if not fs.isDir( fs.combine( sPath, sFile ) ) and\
- \009\009\009\009 (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \".\") then\
- \009\009\009\009\009tItems[ sFile ] = true\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- end\009\
- \
- \009-- Sort and return\
- \009local tItemList = {}\
- \009for sItem, b in pairs( tItems ) do\
- \009\009table.insert( tItemList, sItem )\
- \009end\
- \009table.sort( tItemList )\
- \009return tItemList\
- end\
- \
- local function completeProgram( sLine )\
- \009if #sLine > 0 and string.sub( sLine, 1, 1 ) == \"/\" then\
- \009 -- Add programs from the root\
- \009 return fs.complete( sLine, \"\", true, false )\
- \
- else\
- local tResults = {}\
- local tSeen = {}\
- \
- -- Add aliases\
- for sAlias, sCommand in pairs( tAliases ) do\
- if #sAlias > #sLine and string.sub( sAlias, 1, #sLine ) == sLine then\
- local sResult = string.sub( sAlias, #sLine + 1 )\
- if not tSeen[ sResult ] then\
- table.insert( tResults, sResult )\
- tSeen[ sResult ] = true\
- end\
- end\
- end\
- \
- -- Add programs from the path\
- local tPrograms = bash.programs()\
- for n=1,#tPrograms do\
- local sProgram = tPrograms[n]\
- if #sProgram > #sLine and string.sub( sProgram, 1, #sLine ) == sLine then\
- local sResult = string.sub( sProgram, #sLine + 1 )\
- if not tSeen[ sResult ] then\
- table.insert( tResults, sResult )\
- tSeen[ sResult ] = true\
- end\
- end\
- end\
- \
- -- Sort and return\
- table.sort( tResults )\
- return tResults\
- end\
- end\
- \
- local function completeProgramArgument( sProgram, nArgument, sPart, tPreviousParts )\
- local tInfo = tCompletionInfo[ sProgram ]\
- if tInfo then\
- return tInfo.fnComplete( bash, nArgument, sPart, tPreviousParts )\
- end\
- return nil\
- end\
- \
- function bash.complete( sLine )\
- if #sLine > 0 then\
- local tWords = tokenise( sLine )\
- local nIndex = #tWords\
- if string.sub( sLine, #sLine, #sLine ) == \" \" then\
- nIndex = nIndex + 1\
- end\
- if nIndex == 1 then\
- local sBit = tWords[1] or \"\"\
- local sPath = bash.resolveProgram( sBit )\
- if tCompletionInfo[ sPath ] then\
- return { \" \" }\
- else\
- local tResults = completeProgram( sBit )\
- for n=1,#tResults do\
- local sResult = tResults[n]\
- local sPath = bash.resolveProgram( sBit .. sResult )\
- if tCompletionInfo[ sPath ] then\
- tResults[n] = sResult .. \" \"\
- end\
- end\
- return tResults\
- end\
- \
- elseif nIndex > 1 then\
- local sPath = bash.resolveProgram( tWords[1] )\
- local sPart = tWords[nIndex] or \"\"\
- local tPreviousParts = tWords\
- tPreviousParts[nIndex] = nil\
- return completeProgramArgument( sPath , nIndex - 1, sPart, tPreviousParts )\
- \
- end\
- end\
- \009return nil\
- end\
- \
- function bash.completeProgram( sProgram )\
- return completeProgram( sProgram )\
- end\
- \
- function bash.setCompletionFunction( sProgram, fnComplete )\
- tCompletionInfo[ sProgram ] = {\
- fnComplete = fnComplete\
- }\
- end\
- \
- function bash.getCompletionInfo()\
- return tCompletionInfo\
- end\
- \
- function bash.getRunningProgram()\
- \009if #tProgramStack > 0 then\
- \009\009return tProgramStack[#tProgramStack]\
- \009end\
- \009return nil\
- end\
- \
- function bash.setAlias( _sCommand, _sProgram )\
- \009tAliases[ _sCommand ] = _sProgram\
- end\
- \
- function bash.clearAlias( _sCommand )\
- \009tAliases[ _sCommand ] = nil\
- end\
- \
- function bash.aliases()\
- \009-- Copy aliases\
- \009local tCopy = {}\
- \009for sAlias, sCommand in pairs( tAliases ) do\
- \009\009tCopy[sAlias] = sCommand\
- \009end\
- \009return tCopy\
- end\
- \
- if multishell then\
- function bash.openTab( ... )\
- local tWords = tokenise( ... )\
- local sCommand = tWords[1]\
- if sCommand then\
- \009local sPath = bash.resolveProgram( sCommand )\
- \009if sPath == \"kernel/bash\" then\
- return multishell.launch( tEnv, sPath, table.unpack( tWords, 2 ) )\
- elseif sPath ~= nil then\
- return multishell.launch( tEnv, \"kernel/bash\", sCommand, table.unpack( tWords, 2 ) )\
- else\
- printError( \"No such program\" )\
- end\
- end\
- end\
- \
- function bash.switchTab( nID )\
- multishell.setFocus( nID )\
- end\
- end\
- \
- local tArgs = { ... }\
- if #tArgs > 0 then\
- -- \"bash x y z\"\
- -- Run the program specified on the commandline\
- bash.run( ... )\
- \
- else\
- -- \"bash\"\
- -- Print the header\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- print( os.version() )\
- term.setTextColour( textColour )\
- \
- -- Run the startup program\
- if parentShell == nil then\
- bash.run( \"/kernel/startup\" )\
- end\
- \
- -- Read commands and execute them\
- local tCommandHistory = {}\
- while not bExit do\
- term.redirect( parentTerm )\
- term.setBackgroundColor( bgColour )\
- term.setTextColour( promptColour )\
- if bash.user()~=\"root\" then\
- write( string.gsub(\"/\"..bash.dir(),\"/\"..bash.curHomeDir(),\"~\") .. \" $ \" )\
- else\
- write( \"/\"..bash.dir() .. \" # \" )\
- end\
- term.setTextColour( textColour )\
- \
- local sLine\
- if settings.get( \"bash.autocomplete\" ) then\
- sLine = read( nil, tCommandHistory, bash.complete )\
- else\
- sLine = read( nil, tCommandHistory )\
- end\
- table.insert( tCommandHistory, sLine )\
- bash.run( sLine )\
- end\
- end",
- startup = "\
- -- Setup paths\
- local sPath = \".:/bin:/rom/programs\"\
- if term.isColor() then\
- \009sPath = sPath..\":/rom/programs/advanced\"\
- end\
- if turtle then\
- \009sPath = sPath..\":/rom/programs/turtle\"\
- else\
- sPath = sPath..\":/rom/programs/rednet:/rom/programs/fun\"\
- if term.isColor() then\
- \009sPath = sPath..\":/rom/programs/fun/advanced\"\
- end\
- end\
- if pocket then\
- sPath = sPath..\":/rom/programs/pocket\"\
- end\
- if commands then\
- sPath = sPath..\":/rom/programs/command\"\
- end\
- if http then\
- \009sPath = sPath..\":/rom/programs/http\"\
- end\
- shell.setPath( sPath )\
- help.setPath( \"/rom/help\" )\
- \
- -- Setup aliases\
- shell.setAlias( \"ls\", \"list\" )\
- shell.setAlias( \"dir\", \"list\" )\
- shell.setAlias( \"cp\", \"copy\" )\
- shell.setAlias( \"mv\", \"move\" )\
- shell.setAlias( \"rm\", \"delete\" )\
- shell.setAlias( \"clr\", \"clear\" )\
- shell.setAlias( \"rs\", \"redstone\" )\
- shell.setAlias( \"sh\", \"shell\" )\
- if term.isColor() then\
- shell.setAlias( \"background\", \"bg\" )\
- shell.setAlias( \"foreground\", \"fg\" )\
- end\
- \
- -- Setup completion functions\
- local function completeMultipleChoice( sText, tOptions, bAddSpaces )\
- local tResults = {}\
- for n=1,#tOptions do\
- local sOption = tOptions[n]\
- if #sOption + (bAddSpaces and 1 or 0) > #sText and string.sub( sOption, 1, #sText ) == sText then\
- local sResult = string.sub( sOption, #sText + 1 )\
- if bAddSpaces then\
- table.insert( tResults, sResult .. \" \" )\
- else\
- table.insert( tResults, sResult )\
- end\
- end\
- end\
- return tResults\
- end\
- local function completePeripheralName( sText, bAddSpaces )\
- return completeMultipleChoice( sText, peripheral.getNames(), bAddSpaces )\
- end\
- local tRedstoneSides = redstone.getSides()\
- local function completeSide( sText, bAddSpaces )\
- return completeMultipleChoice( sText, tRedstoneSides, bAddSpaces )\
- end\
- local function completeFile( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return fs.complete( sText, shell.dir(), true, false )\
- end\
- end\
- local function completeDir( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return fs.complete( sText, shell.dir(), false, true )\
- end\
- end\
- local function completeEither( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return fs.complete( sText, shell.dir(), true, true )\
- end\
- end\
- local function completeEitherEither( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- local tResults = fs.complete( sText, shell.dir(), true, true )\
- for n=1,#tResults do\
- local sResult = tResults[n]\
- if string.sub( sResult, #sResult, #sResult ) ~= \"/\" then\
- tResults[n] = sResult .. \" \"\
- end\
- end\
- return tResults\
- elseif nIndex == 2 then\
- return fs.complete( sText, shell.dir(), true, true )\
- end\
- end\
- local function completeProgram( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return shell.completeProgram( sText )\
- end\
- end\
- local function completeHelp( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return help.completeTopic( sText )\
- end\
- end\
- local function completeAlias( shell, nIndex, sText, tPreviousText )\
- if nIndex == 2 then\
- return shell.completeProgram( sText )\
- end\
- end\
- local function completePeripheral( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completePeripheralName( sText )\
- end\
- end\
- local tGPSOptions = { \"host\", \"host \", \"locate\" }\
- local function completeGPS( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tGPSOptions )\
- end\
- end\
- local tLabelOptions = { \"get\", \"get \", \"set \", \"clear\", \"clear \" }\
- local function completeLabel( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tLabelOptions )\
- elseif nIndex == 2 then\
- return completePeripheralName( sText )\
- end\
- end\
- local function completeMonitor( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completePeripheralName( sText, true )\
- elseif nIndex == 2 then\
- return shell.completeProgram( sText )\
- end\
- end\
- local tRedstoneOptions = { \"probe\", \"set \", \"pulse \" }\
- local function completeRedstone( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tRedstoneOptions )\
- elseif nIndex == 2 then\
- return completeSide( sText )\
- end\
- end\
- local tDJOptions = { \"play\", \"play \", \"stop \" }\
- local function completeDJ( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tDJOptions )\
- elseif nIndex == 2 then\
- return completePeripheralName( sText )\
- end\
- end\
- local tPastebinOptions = { \"put \", \"get \", \"run \" }\
- local function completePastebin( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tPastebinOptions )\
- elseif nIndex == 2 then\
- if tPreviousText[2] == \"put\" then\
- return fs.complete( sText, shell.dir(), true, false )\
- end\
- end\
- end\
- local tChatOptions = { \"host \", \"join \" }\
- local function completeChat( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, tChatOptions )\
- end\
- end\
- local function completeSet( shell, nIndex, sText, tPreviousText )\
- if nIndex == 1 then\
- return completeMultipleChoice( sText, settings.getNames(), true )\
- end\
- end\
- shell.setCompletionFunction( \"rom/programs/alias\", completeAlias )\
- shell.setCompletionFunction( \"rom/programs/cd\", completeDir )\
- shell.setCompletionFunction( \"rom/programs/copy\", completeEitherEither )\
- shell.setCompletionFunction( \"rom/programs/delete\", completeEither )\
- shell.setCompletionFunction( \"rom/programs/drive\", completeDir )\
- shell.setCompletionFunction( \"rom/programs/edit\", completeFile )\
- shell.setCompletionFunction( \"rom/programs/eject\", completePeripheral )\
- shell.setCompletionFunction( \"rom/programs/gps\", completeGPS )\
- shell.setCompletionFunction( \"rom/programs/help\", completeHelp )\
- shell.setCompletionFunction( \"rom/programs/id\", completePeripheral )\
- shell.setCompletionFunction( \"rom/programs/label\", completeLabel )\
- shell.setCompletionFunction( \"rom/programs/list\", completeDir )\
- shell.setCompletionFunction( \"rom/programs/mkdir\", completeFile )\
- shell.setCompletionFunction( \"rom/programs/monitor\", completeMonitor )\
- shell.setCompletionFunction( \"rom/programs/move\", completeEitherEither )\
- shell.setCompletionFunction( \"rom/programs/redstone\", completeRedstone )\
- shell.setCompletionFunction( \"rom/programs/rename\", completeEitherEither )\
- shell.setCompletionFunction( \"rom/programs/shell\", completeProgram )\
- shell.setCompletionFunction( \"rom/programs/type\", completeEither )\
- shell.setCompletionFunction( \"rom/programs/set\", completeSet )\
- shell.setCompletionFunction( \"rom/programs/advanced/bg\", completeProgram )\
- shell.setCompletionFunction( \"rom/programs/advanced/fg\", completeProgram )\
- shell.setCompletionFunction( \"rom/programs/fun/dj\", completeDJ )\
- shell.setCompletionFunction( \"rom/programs/fun/advanced/paint\", completeFile )\
- shell.setCompletionFunction( \"rom/programs/http/pastebin\", completePastebin )\
- shell.setCompletionFunction( \"rom/programs/rednet/chat\", completeChat )\
- \
- -- Run autorun files\
- if fs.exists( \"/rom/autorun\" ) and fs.isDir( \"/rom/autorun\" ) then\
- \009local tFiles = fs.list( \"/rom/autorun\" )\
- \009table.sort( tFiles )\
- \009for n, sFile in ipairs( tFiles ) do\
- \009\009if string.sub( sFile, 1, 1 ) ~= \".\" then\
- \009\009\009local sPath = \"/rom/autorun/\"..sFile\
- \009\009\009if not fs.isDir( sPath ) then\
- \009\009\009\009shell.run( sPath )\
- \009\009\009end\
- \009\009end\
- \009end\
- end\
- \
- -- Run the user created startup, either from disk drives or the root\
- local user,homedir = loadfile(\"/bin/login\")()\
- if settings.get( \"bash.run_bashrc\" ) then\
- if fs.exists(homedir..\"/.bashrc\") then bash.run(homedir..\"/.bashrc\") end\
- end\
- bash.user = function() return user end\
- bash.curHomeDir = function() return homedir end\
- bash.setDir(homedir)",
- },
- etc = {
- passwd = "{}",
- },
- }
- local function writeFile(path,content)
- local file = fs.open(path,"w")
- file.write(content)
- file.close()
- end
- function writeDown(input,dir)
- for i,v in pairs(input) do
- if type(v) == "table" then
- writeDown(v,dir.."/"..i)
- elseif type(v) == "string" then
- writeFile(dir.."/"..i,v)
- end
- end
- end
- args = {...}
- if #args == 0 then
- print("Please input a destination folder.")
- else
- writeDown(inputTable,args[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement