SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function udprog(updateprogram, pastelink, udloc, updatefunargs, startupls) |
| 1 | + | |
| 2 | updateargs = {...}
| |
| 3 | - | --fupdateargs = {...}
|
| 3 | + | --udlstbl = {"updateprogram", "pastelink", "udloc", "startupls", "strtprg"}
|
| 4 | - | updateargs = updatefunargs |
| 4 | + | |
| 5 | - | os.loadAPI("/rom/programs/shell.lua")
|
| 5 | + | updateprogram = updateargs[1] |
| 6 | pastelink = updateargs[2] | |
| 7 | udloc = updateargs[3] | |
| 8 | startupls = updateargs[4] | |
| 9 | strtprg = updateargs[5] | |
| 10 | - | shell.shell.run("cd", udloc)
|
| 10 | + | |
| 11 | function printud() | |
| 12 | term.clear() | |
| 13 | - | if fs.exists(updateprogram.."new") then |
| 13 | + | term.setCursorPos(1,1) |
| 14 | - | shell.shell.run("delete",updateprogram.."new")
|
| 14 | + | print("Updating...")
|
| 15 | end | |
| 16 | - | shell.shell.run("pastebin","get",pastelink,updateprogram.."new")
|
| 16 | + | printud() |
| 17 | - | if fs.exists(updateprogram.."new") then |
| 17 | + | |
| 18 | - | if fs.exists(updateprogram.."old") then |
| 18 | + | countslw = countsl + 1 |
| 19 | - | shell.shell.run("delete",updateprogram.."old")
|
| 19 | + | for i=1,countslw do |
| 20 | shell.run("cd", "..")
| |
| 21 | - | if fs.exists("Farm") then
|
| 21 | + | printud() |
| 22 | - | shell.shell.run("rename",updateprogram,updateprogram.."old")
|
| 22 | + | |
| 23 | numprogargs = 6 | |
| 24 | - | shell.shell.run("rename",updateprogram.."new",updateprogram)
|
| 24 | + | if #updateargs > 5 then |
| 25 | - | if fs.exists(updateprogram) then |
| 25 | + | progargs = {}
|
| 26 | for i=numprogargs,#updateargs do | |
| 27 | table.insert(progargs, updateargs[i]) | |
| 28 | end | |
| 29 | - | if fs.exists(updateprogram) then |
| 29 | + | |
| 30 | while true do | |
| 31 | if fs.isDir(udloc) == false then | |
| 32 | fs.makeDir(udloc) | |
| 33 | end | |
| 34 | - | if fs.exists(updateprogram.."old") then |
| 34 | + | shell.run("cd", udloc)
|
| 35 | if fs.exists(udloc.."/"..updateprogram.."new") then | |
| 36 | - | shell.shell.run("rename",updateprogram.."old",updateprogram)
|
| 36 | + | shell.run("delete",updateprogram.."new")
|
| 37 | - | if fs.exists(updateprogram) then |
| 37 | + | printud() |
| 38 | end | |
| 39 | shell.run("pastebin","get",pastelink,updateprogram.."new")
| |
| 40 | printud() | |
| 41 | --print(udloc.."/"..updateprogram.."new") | |
| 42 | if fs.exists(udloc.."/"..updateprogram.."new") then | |
| 43 | if fs.exists(udloc.."/"..updateprogram.."old") then | |
| 44 | shell.run("delete",updateprogram.."old")
| |
| 45 | - | countsl = countsl + 1 |
| 45 | + | printud() |
| 46 | end | |
| 47 | - | if startupls ~= "none" or startupls ~= nil then |
| 47 | + | if fs.exists(udloc.."/"..updateprogram) then |
| 48 | shell.run("rename",updateprogram,updateprogram.."old")
| |
| 49 | printud() | |
| 50 | end | |
| 51 | shell.run("rename",updateprogram.."new",updateprogram)
| |
| 52 | - | if updatefunargs ~= nil or updatefunargs ~= "none" then |
| 52 | + | if fs.exists(udloc.."/"..updateprogram) then |
| 53 | - | shell.shell.run(updateprogram .. "," .. unpack(updateargs)) |
| 53 | + | |
| 54 | end | |
| 55 | - | shell.shell.run(updateprogram) |
| 55 | + | |
| 56 | if fs.exists(udloc.."/"..updateprogram) then | |
| 57 | - | for i=1,countsl do |
| 57 | + | |
| 58 | - | shell.shell.run("cd", "..")
|
| 58 | + | |
| 59 | end | |
| 60 | end | |
| 61 | if fs.exists(udloc.."/"..updateprogram.."old") then | |
| 62 | if updateloop > 30 then | |
| 63 | shell.run("rename",updateprogram.."old",updateprogram)
| |
| 64 | if fs.exists(udloc.."/"..updateprogram) then | |
| 65 | break | |
| 66 | end | |
| 67 | end | |
| 68 | end | |
| 69 | updateloop = updateloop + 1 | |
| 70 | sleep(0) | |
| 71 | end | |
| 72 | sleep(0) | |
| 73 | countslw = countsl + 1 | |
| 74 | for i=1,countslw do | |
| 75 | shell.run("cd", "..")
| |
| 76 | printud() | |
| 77 | end | |
| 78 | --print(startupls) | |
| 79 | --sleep(10) | |
| 80 | if startupls ~= "none" and startupls ~= nil then | |
| 81 | local stu = fs.open("startup.lua", "w")
| |
| 82 | stu.write(startupls) | |
| 83 | stu.close() | |
| 84 | end | |
| 85 | if strtprg == nil and strtprg == "no" and strtprg == "none" then | |
| 86 | else | |
| 87 | ||
| 88 | if progargs ~= nil then | |
| 89 | shell.run(udloc.."/"..updateprogram.." "..unpack(progargs)) | |
| 90 | else | |
| 91 | shell.run(udloc.."/"..updateprogram) | |
| 92 | end | |
| 93 | end |