Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get gxCvryX5 updater
- local arg1, arg2, arg3 = ...
- function saveTable(filePathIn, tableIn)
- local file = fs.open(filePathIn,"w")
- file.write(textutils.serialize(tableIn))
- file.close()
- end
- function loadTable(filePathIn)
- local file = fs.open(filePathIn,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- local sPath = "UpdaterData.save"
- local programs = {
- updater = "gxCvryX5"
- }
- if not fs.exists(sPath) then
- saveTable(sPath, programs)
- end
- programs = loadTable(sPath)
- local function install(fileName)
- if not programs[fileName] then
- print("no file with name ", fileName)
- return
- end
- if fs.exists(fileName) then
- fs.delete(fileName)
- end
- shell.run("pastebin", "get", programs[fileName], fileName)
- end
- local function updateAll()
- for i,v in pairs(programs) do
- if fs.exists(i) then
- print("Updating program \""..tostring(i).."\" "..tostring(v))
- install(i)
- print()
- else
- print("Installing program \""..tostring(i).."\" "..tostring(v))
- install(i)
- print()
- end
- end
- end
- print()
- if arg1 == "install" then
- install(arg2)
- elseif arg1 == "list" then
- for i,v in pairs(programs) do
- print("\""..tostring(i).."\"", v)
- end
- elseif arg1 == "add" then
- local input1, input2
- if not arg2 then
- print("Please type the name of the program.")
- input1 = read()
- else
- input1 = tostring(arg2)
- end
- if not arg3 then
- print("Please type the pastebin id of the program.")
- input2 = read()
- else
- input2 = tostring(arg3)
- end
- if input1 and input2 then
- print("Adding new program \""..input1.."\" "..input2.. " to installer.")
- programs[input1] = input2
- else
- print("Failed to add new program \""..tostring(input1).."\" "..tostring(input2))
- end
- elseif arg1 == "remove" then
- print("Please type the name of the program.")
- input1 = read()
- if input1 then
- if (programs[input1]) then
- print("Removing \""..input1.."\" from the installer and uninstalling it.")
- if fs.exists(input1) then
- fs.delete(input1)
- end
- programs[input1] = nil
- else
- print("No program named \""..input1.."\" installed in the updater.")
- end
- else
- print("Failed. Input must not be nil")
- end
- else
- print("Updating Everything...")
- updateAll()
- end
- saveTable(sPath, programs)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement