Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Soube - (c) iSoube
- local pUrl = "http://pastebin.com/raw/"
- local soube_path = '/soube.d'
- local soube_backuppath = soube_path..'/backup'
- local soube_installpath = soube_path..'/installed.list'
- local soube_sources = {}
- local soube_installed = {}
- local tArgs = { ... }
- local peripSides = peripheral.getNames()
- if not http or not http.checkURL(pUrl) then
- print("Bei dir ist in der ComputerCraft-config http nicht aktiviert.")
- print("Stelle sicher das 'pastebin.com' in der http.whitelist eingetragen ist.")
- print("Aktiviere es, starte Minecraft neu und fuehre soube erneut aus.")
- return
- end
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- end
- function table.removeKey(tables, key)
- local i = 0
- local ks, vs = {}, {}
- for k, v in pairs(tables) do
- i = i + 1
- ks[i] = k
- vs[i] = v
- end
- while i > 0 do
- if ks[i] == key then
- table.remove(ks, i)
- table.remove(vs, i)
- break
- end
- i = i - 1
- end
- local a = {}
- for i = 1, #ks do
- a[ks[i]] = vs[i]
- end
- return a
- end
- local function loadSources()
- local dl = http.get(pUrl.."01W8xQyC")
- if dl then
- soube_sources = textutils.unserialize(dl.readAll())
- dl.close()
- else
- exit("Konnte sources.list nicht aufrufen! Bitte kontaktiere monster8570 auf Twitter oder YouTube!")
- end
- end
- local function showsoube()
- print("----- Reactor -----")
- print("-- by Soube --")
- print()
- end
- local function showSources()
- for name, data in pairs(soube_sources) do
- term.setTextColor(colors.green)
- write(name)
- term.setTextColor(colors.white)
- write(' -- ')
- term.setTextColor(colors.lightBlue)
- write(data["desc"].."\n")
- term.setTextColor(colors.white)
- end
- end
- local function showInstalled()
- for name, data in pairs(soube_installed) do
- term.setTextColor(colors.green)
- write(name)
- term.setTextColor(colors.white)
- write(' -- ')
- term.setTextColor(colors.lightBlue)
- write('v.'..data["version"].."\n")
- term.setTextColor(colors.white)
- end
- end
- local function showHelp()
- print("soube help -- Zeigt dieses Hilfemenu an")
- print("soube install <programm> -- Installieren von Programmen")
- print("soube update <programm> -- Updaten von Programmen")
- print("soube remove <programm> -- Entfernen von Programmen")
- print("soube config <programm> -- Zum Teilkonfigurieren")
- end
- local function readInput()
- term.setTextColor(colors.yellow)
- write("\n>")
- term.setTextColor(colors.white)
- local input = read():lower()
- return input
- end
- local function checkInput(table, input)
- local selected = false
- for name, data in pairs(table) do
- if not selected then
- if input == name then
- selected = true
- else
- selected = false
- end
- end
- end
- return selected
- end
- local function checkInputNum(table, input, text)
- local exists = false
- for i = 1, #table do
- if input == table[i] then
- exists = true
- end
- end
- if exists == false then
- print(text)
- checkInputNum(table, input)
- else
- return input
- end
- end
- local function exit(text, err)
- if not err then err = false end
- if err then
- term.setTextColor(colors.red)
- else
- term.setTextColor(colors.green)
- end
- write(text.."\n")
- term.setTextColor(colors.white)
- error()
- end
- local function confirm()
- local input = read():lower()
- if input == "j" or input == "ja" then
- return true
- else
- return false
- end
- end
- local function loadInstall()
- if fs.exists(soube_installpath) then
- local file = fs.open(soube_installpath, "r")
- soube_installed = textutils.unserialize(file.readAll())
- file.close()
- end
- end
- local function saveInstall()
- local file = fs.open(soube_installpath, "w")
- file.write(textutils.serialize(soube_installed))
- file.close()
- end
- local function setInstallProg(table, program)
- soube_installed[program] = table
- saveInstall()
- end
- local function setInstall(program, key, val)
- soube_installed[program][key] = val
- saveInstall()
- end
- local function addInstall(table, program)
- soube_installed[program] = table
- saveInstall()
- end
- local function removeInstall(program)
- soube_installed = table.removeKey(soube_installed, program)
- saveInstall()
- end
- local function checkInstall(programm)
- if soube_installed[programm] ~= nil then
- return true
- end
- return false
- end
- local function startupInstall(program)
- if soube_sources[program] == nil then
- exit("Programm '"..program.."' existiert nicht!", true)
- elseif soube_installed[program] == nil then
- exit("Programm '"..program.."' ist nicht installiert!", true)
- end
- local startup = soube_sources[program]["startup"]
- if fs.exists('startup') then
- if fs.exists('startup-old') then
- fs.delete('startup-old')
- end
- fs.move('startup', 'startup-old')
- end
- local sfile = fs.open("startup", "w")
- sfile.write(startup)
- sfile.close()
- end
- local function checkSides(pType)
- local rSides = {}
- local nSides = 0
- for i = 1, #peripSides do
- if peripheral.getType(peripSides[i]) == pType then
- nSides = nSides + 1
- rSides[nSides] = peripSides[i]
- write(peripSides[i])
- if i ~= #peripSides then
- write(", ")
- end
- end
- end
- return rSides
- end
- local function writeFile(path, content)
- local file = fs.open(path, 'w')
- file.write(content)
- file.close()
- end
- local function writeFiles(files)
- for path, content in pairs(files) do
- writeFile(path, content)
- end
- end
- local function backupFile(path, name)
- if fs.exists(path..'/'..name) then
- fs.move(path..name, soube_backuppath..name)
- end
- end
- local function restoreFile(path, name)
- if fs.exists(soube_backuppath..'/'..name) then
- fs.move(soube_backuppath..name, path..name)
- end
- end
- local function downloadFile(name, pid, url)
- local download = http.get(url)
- local file
- if download then
- print("Fetching "..name.." ("..pid..")")
- file = download.readAll()
- download.close()
- return file
- else
- exit("Konnte "..name.." ("..pid..") nicht herunterladen!\nHerunterladen fehlgeschlagen!\n", true)
- end
- end
- local function install(program)
- local filelist = soube_sources[program]["files"]
- local path = soube_sources[program]["path"]
- local name = soube_sources[program]["name"]
- local files = {}
- if fs.exists(path) or checkInstall(program) then
- exit("Programm "..name.." ist bereits installiert!", true)
- else
- fs.makeDir(path)
- end
- print("Installiere "..name.."...")
- for __, data in pairs(filelist) do
- local url = pUrl..data["pid"]
- local lpath = path..'/'..data["name"]
- local download = downloadFile(data["name"], data["pid"], url)
- files[lpath] = download
- end
- writeFiles(files)
- addInstall(soube_sources[program], program)
- startupInstall(program)
- exit("Installation von "..name.." abgeschlossen!")
- end
- local function update(program)
- if soube_sources[program] == nil then
- exit("Programm '"..program.."' existiert nicht!", true)
- elseif soube_installed[program] == nil then
- exit("Programm '"..program.."' ist nicht installiert!", true)
- end
- local filelist = soube_sources[program]["files"]
- local path = soube_installed[program]["path"]
- local name = soube_installed[program]["name"]
- local cfgs = soube_sources[program]["cfgs"]
- local lversion = soube_installed[program]["version"]
- local sversion = soube_sources[program]["version"]
- local files = {}
- if lversion == sversion then
- exit(name.." ist bereits auf der neusten Version!")
- end
- print("Update "..name.."...")
- if #cfgs ~= 0 then
- print("Erstelle Backup von "..name.."...")
- for i=1, #cfgs do
- backupFile(path, cfgs[i])
- end
- term.setTextColor(colors.green)
- print("Backup wurde erstellt!")
- term.setTextColor(colors.white)
- end
- fs.delete(path)
- fs.makeDir(path)
- for __, data in pairs(filelist) do
- local url = pUrl..data["pid"]
- local lpath = path..'/'..data["name"]
- local download = downloadFile(data["name"], data["pid"], url)
- files[lpath] = download
- end
- writeFiles(files)
- if #cfgs ~= 0 then
- print("Stelle Backup von "..name.." wieder her...")
- for i=1, #cfgs do
- restoreFile(path, cfgs[i])
- end
- term.setTextColor(colors.green)
- print("Backup wurde wiederhergestellt!")
- term.setTextColor(colors.white)
- end
- setInstallProg(soube_sources[program], program)
- exit("Update von "..name.." abgeschlossen!")
- end
- local function remove(program)
- if soube_sources[program] == nil then
- exit("Programm '"..program.."' existiert nicht!", true)
- elseif soube_installed[program] == nil then
- exit("Programm '"..program.."' ist nicht installiert!", true)
- end
- local path = soube_installed[program]["path"]
- local name = soube_installed[program]["name"]
- print("Deinstalliere "..name.."...")
- if fs.exists(path) then
- fs.delete(path)
- end
- removeInstall(program)
- exit("Deinstallation von "..name.." abgeschlossen!")
- end
- local function config(program)
- if soube_sources[program] == nil then
- exit("Programm '"..program.."' existiert nicht!", true)
- elseif soube_installed[program] == nil then
- exit("Programm '"..program.."' ist nicht installiert!", true)
- end
- local path = soube_installed[program]["path"]
- local name = soube_installed[program]["name"]
- local needs = soube_installed[program]["needs"]
- local dataCfg = {}
- local cfg = {}
- print("Konfiguration von "..name.."...")
- if needs["monitor"] == true then
- print("Auf welcher Seite befindet sich der Monitor?")
- write("Moegliche Seiten sind ")
- local rSides = checkSides("monitor")
- if #rSides == 1 then
- cfg["monSide"] = rSides[1]
- print("Benutze Monitor "..rSides[1])
- elseif #rSides == 0 then
- exit("Kein Monitor vorhanden!", true)
- else
- local input = readInput()
- local exists = checkInputNum(rSides, input, "An der angegeben Seite ist kein Monitor angeschlossen!")
- cfg["monSide"] = exists
- end
- end
- if needs["redstone"] == true then
- print("Auf welcher Seite befindet sich das BundledCable?")
- term.setTextColor(colors.blue)
- print("Info: Es kann nicht geprueft werden, ob sich an der angegebenen Seite ein BundledCable befindet!")
- local input = readInput()
- cfg["redSide"] = input
- end
- if needs["modem"] == true then
- print("Auf welcher Seite befindet sich das Modem?")
- write("Moegliche Seiten sind ")
- local rSides = checkSides("modem")
- if #rSides == 1 then
- cfg["modSide"] = rSides[1]
- print("Benutze Modem "..rSides[1])
- elseif #rSides == 0 then
- exit("Kein Modem vorhanden!", true)
- else
- local input = readInput()
- local exists = checkInputNum(rSides, input, "An der angegeben Seite ist kein Modem angeschlossen!")
- cfg["modSide"] = exists
- end
- end
- if fs.exists(path..'/'..'cfg') then
- local rFile = fs.open(path..'/'..'cfg', "r")
- dataCfg = textutils.unserialize(rFile.readAll())
- rFile.close()
- end
- dataCfg["monSide"] = cfg["monSide"]
- dataCfg["redSide"] = cfg["redSide"]
- dataCfg["modSide"] = cfg["modSide"]
- local wFile = fs.open(path..'/'..'cfg', "w")
- wFile.write(textutils.serialize(dataCfg))
- wFile.close()
- exit("Konfiguration von "..name.." abgeschlossen!")
- end
- --showsoube()
- loadSources()
- loadInstall()
- if #tArgs <= 0 then
- showHelp()
- end
- if #tArgs >= 1 and tArgs[1] == "help" then
- showHelp()
- elseif #tArgs >= 1 and tArgs[1] == "install" then
- local installFound = false
- local input
- if #tArgs == 2 then
- input = tArgs[2]:lower()
- else
- print("Folgende Programme koennen installiert werden:")
- showSources()
- input = readInput()
- end
- installFound = checkInput(soube_sources, input)
- if installFound == false then
- if input == "" then
- exit("Es wurde kein Programm angegeben!", true)
- else
- exit("Es konnte kein Programm Names '"..input.."' gefunden werden!", true)
- end
- else
- install(input)
- end
- elseif #tArgs >= 1 and tArgs[1] == "remove" then
- local progFound = false
- local input
- if #tArgs == 2 then
- input = tArgs[2]:lower()
- else
- print("Folgende Programme koennen entfernt werden:")
- showInstalled()
- input = readInput()
- end
- progFound = checkInput(soube_installed, input)
- if progFound == false then
- if input == "" then
- exit("Es wurde kein Programm angegeben!", true)
- else
- exit("Es konnte kein Programm Names '"..input.."' gefunden werden!", true)
- end
- else
- remove(input)
- end
- elseif #tArgs >= 1 and tArgs[1] == "update" then
- local progFound = false
- local input
- if #tArgs == 2 then
- input = tArgs[2]:lower()
- else
- print("Folgende Programme koennen geupdatet werden:")
- showInstalled()
- input = readInput()
- end
- progFound = checkInput(soube_installed, input)
- if progFound == false then
- if input == "" then
- exit("Es wurde kein Programm angegeben!", true)
- else
- exit("Es konnte kein Programm Names '"..input.."' gefunden werden!", true)
- end
- else
- update(input)
- end
- elseif #tArgs >= 1 and tArgs[1] == "config" then
- local progFound = false
- local input
- if #tArgs == 2 then
- input = tArgs[2]:lower()
- else
- print("Folgende Programme koennen konfiguriert werden:")
- showInstalled()
- input = readInput()
- end
- progFound = checkInput(soube_installed, input)
- if progFound == false then
- if input == "" then
- exit("Es wurde kein Programm angegeben!", true)
- else
- exit("Es konnte kein Programm Names '"..input.."' gefunden werden!", true)
- end
- else
- config(input)
- end
- elseif #tArgs >= 1 then
- exit("Der Befehl "..tArgs[1].." wurde nicht gefunden!", true)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement