Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local exStr = [[shell.run("/usr/bin/easy-shell execute")]]
- local function loadStartup()
- local lines = {}
- if fs.exists("/startup") then
- local handle = io.open("/startup", "r")
- if handle then
- for line in handle:lines() do
- table.insert(lines, line)
- end
- handle:close()
- end
- end
- return lines
- end
- local function writeStartup(contents)
- local handle = io.open("/startup", "w")
- if handle then
- for i, line in ipairs(contents) do
- handle:write(line.."\n")
- end
- handle:close()
- else
- error("Could not write startup file!")
- end
- end
- if #args >= 1 then
- if args[1] == "execute" then
- shell.setPath(shell.path()..":/usr/bin")
- local loadAPI = os.loadAPI
- os.loadAPI = function(path)
- if fs.exists(path) then
- return loadAPI(path)
- elseif fs.exists(fs.combine("/usr/apis", path)) then
- return loadAPI(fs.combine("/usr/apis", path))
- end
- end
- elseif args[1] == "install" then
- if tonumber(string.sub(os.version(), 9)) and tonumber(string.sub(os.version(), 9)) > 1.7 and fs.isDir("/startup") then
- --In CraftOS 1.8+, simply add a file to the startup folder.
- local handle = io.open("/startup/easy-shell.lua")
- if handle then
- handle:write(exStr)
- handle:close()
- else
- error("Could not write file!")
- end
- else
- --otherwise, attempt to cleanly add a line to the startup file.
- local contents = loadStartup()
- local changed = false
- if fs.exists("/startup") then
- local exists = false
- for i = 1, #contents do
- if contents[i] == exStr then
- exists = true
- break
- end
- end
- if not exists then
- table.insert(contents, 1, exStr)
- changed = true
- end
- else
- contents[1] = exStr
- changed = true
- end
- if changed then
- writeStartup(contents)
- end
- end
- shell.run("usr/bin/easy-shell execute")
- elseif args[1] == "remove" then
- if tonumber(string.sub(os.version(), 9)) and tonumber(string.sub(os.version(), 9)) > 1.7 and fs.exists("/startup/easy-shell.lua") then
- --in 1.8+, we just have to delete the file we added.
- fs.delete("/startup/easy-shell.lua")
- else
- local contents = loadStartup()
- for i = #contents, 1, -1 do
- if contents[i] == exStr then
- table.remove(contents, i)
- end
- end
- writeStartup(contents)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement