Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- folder where to put the APIs
- local apiFolder = "npeAPIs"
- -- list of files
- local fileInfos= {
- -- APIs
- {
- name = "updater.lua",
- pbcode = "HF7vwabd",
- isApi = true,
- startupParams = "--noupdatecheck",
- needsTurtle = false
- },
- {
- name = "betterturtle.lua",
- pbcode = "6XL8EYXe",
- isApi = true,
- needsTurtle = true
- },
- -- programs
- {
- name = "quarry.lua",
- pbcode = "HqXCPzCg",
- needsTurtle = true
- },
- {
- name = "quarry-minion.lua",
- pbcode = "5pFNPRZv",
- needsTurtle = true
- },
- {
- name = "ignorelist-generator.lua",
- pbcode = "fw5C7u8t",
- needsTurtle = true
- },
- {
- name = "oredict-sorter.lua",
- pbcode = "94eCzump",
- needsTurtle = true
- },
- {
- name = "testcode.lua",
- pbcode = "dP7Rm6p7"
- },
- -- files
- {
- name = "ignore.list",
- pbcode = "ymBVBbt1"
- },
- {
- name = "oredict.config",
- pbcode = "iPPApNHk"
- },
- }
- local function status(text, color, delay)
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- end
- print(" NPE Installation Tool ")
- print("-----------------------")
- print()
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- term.write("--> ")
- if term.isColor() then
- if color == nil then
- color = colors.white
- end
- term.setTextColor(color)
- end
- print(text)
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- if delay then
- sleep(delay)
- end
- end
- local function getFileContent( path )
- local result
- if fs.exists(path) then
- local file = fs.open(path, "r")
- result = file.readAll()
- file.close()
- end
- return result
- end
- local function key()
- local event, c = os.pullEvent("char")
- return c
- end
- -- main program part
- local startupLines = nil
- local wait = 0.5
- if not fs.exists(apiFolder) then
- fs.makeDir(apiFolder)
- end
- for _,fileInfo in ipairs(fileInfos) do
- local filePath = fileInfo.isApi and fs.combine(apiFolder, fileInfo.name)
- or fileInfo.name
- if fileInfo.needsTurtle and (not turtle) then
- status("Skipping \""..fileInfo.name.."\" (Turtle)", colors.orange, wait)
- elseif fs.exists(filePath) then
- -- ignore if the file already exists
- status("Skip: \""..fileInfo.name.."\" already exists", colors.orange, wait)
- else
- local install = true
- -- always install APIs
- if not fileInfo.isApi then
- local c = nil
- repeat
- status("Install "..fileInfo.name.."? -> y/n")
- c = key()
- install = c == "y"
- until (c == "y" or c == "n")
- end
- if install then
- status("Installing file: \""..fileInfo.name.."\"", colors.lightBlue, wait)
- shell.run("pastebin", "get", fileInfo.pbcode, filePath)
- if fileInfo.isApi then
- if (startupLines == nil) then
- startupLines = { "--- LOAD APIs ---" }
- end
- local startupline = "shell.run(\""..filePath
- if fileInfo.startupParams then
- startupline = startupline.."\", \""..fileInfo.startupParams
- end
- startupline = startupline.."\")"
- startupLines[#startupLines+1] = startupline
- end
- status("File installed!", colors.lime, wait)
- end
- end
- end
- -- merge the new startup lines in at the front of old startup file (or create a new one)
- if startupLines then
- local oldStartup = getFileContent("startup")
- if oldStartup then
- status("Modifying startup file...", colors.lightBlue, wait)
- else
- status("Creating startup file...", colors.lightBlue, wait)
- end
- local file = fs.open("startup", "w")
- for i=1,#startupLines do
- file.writeLine(startupLines[i])
- end
- if oldStartup then
- file.writeLine()
- file.writeLine("--- BEGIN OF STARTUP ---")
- file.writeLine(oldStartup)
- end
- file.close()
- end
- -- print success message
- status("Installation complete!", colors.lime, wait)
- shell.run("reboot")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement