Advertisement
BruceWplays

Updater V5

Feb 14th, 2023 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. updateloop = 0
  2. updateargs = {...}
  3. --udlstbl = {"updateprogram", "pastelink", "udloc", "startupls", "strtprg"}
  4.  
  5. updateprogram = updateargs[1]
  6. pastelink = updateargs[2]
  7. udloc = updateargs[3]
  8. startupls = updateargs[4]
  9. strtprg = updateargs[5]
  10. os.loadAPI("AndysPrograms/api/pastebin_silent/ps")
  11. if errhnd ~= 1 then
  12.     function printud()
  13.         -- term.clear()
  14.         -- term.setCursorPos(1,1)
  15.         -- print("Updating...")
  16.     end
  17.     printud()
  18.     local _, countsl = string.gsub(udloc,"/","")
  19.     countslw = countsl + 1
  20.     for i=1,countslw do
  21.         --shell.run("cd", "//")
  22.         --printud()
  23.     end
  24.     --shell.run("cd", "//")
  25.     numprogargs = 6
  26.     if #updateargs > 5 then
  27.         progargs = {}
  28.         for i=numprogargs,#updateargs do
  29.             table.insert(progargs, updateargs[i])
  30.         end
  31.     end
  32.     while true do
  33.         if errhnd ~= 1 then
  34.             if fs.isDir(udloc) == false then
  35.                 fs.makeDir(udloc)
  36.             end
  37.             --shell.run("cd", udloc)
  38.             if fs.exists(udloc.."/"..updateprogram.."new") then
  39.                 fs.delete(udloc.."/"..updateprogram.."new")
  40.                 --shell.run("delete",updateprogram.."new")
  41.                 --printud()
  42.             end
  43.             ps.get({pastelink,updateprogram.."new",udloc})
  44.             --shell.run("AndysPrograms/api/pastebin_silent/ps","get",pastelink,updateprogram.."new")
  45.             printud()
  46.             --print(udloc.."/"..updateprogram.."new")
  47.             if fs.exists(udloc.."/"..updateprogram.."new") then
  48.                 if fs.exists(udloc.."/"..updateprogram.."old") then
  49.                     fs.delete(udloc.."/"..updateprogram.."old")
  50.                     --printud()
  51.                 end
  52.                 if fs.exists(udloc.."/"..updateprogram) then
  53.                     fs.move(udloc.."/"..updateprogram,udloc.."/"..updateprogram.."old")
  54.                     -- shell.run("rename",updateprogram,updateprogram.."old")
  55.                     -- printud()
  56.                 end
  57.                 -- shell.run("rename",updateprogram.."new",updateprogram)
  58.                 fs.move(udloc.."/"..updateprogram.."new",udloc.."/"..updateprogram)
  59.                 if fs.exists(udloc.."/"..updateprogram) then
  60.                     break
  61.                 end
  62.             end
  63.             if fs.exists(udloc.."/"..updateprogram) then
  64.                 if updateloop > 20 then
  65.                     break
  66.                 end
  67.             end
  68.             if fs.exists(udloc.."/"..updateprogram.."old") then
  69.                 if updateloop > 30 then
  70.                     --shell.run("rename",updateprogram.."old",updateprogram)
  71.                     fs.move(udloc.."/"..updateprogram.."old",udloc.."/"..updateprogram)
  72.                     if fs.exists(udloc.."/"..updateprogram) then
  73.                         break
  74.                     end
  75.                 end
  76.             end
  77.             updateloop = updateloop + 1
  78.             sleep(0)
  79.         end
  80.     end
  81.     if errhnd ~= 1 then
  82.         sleep(0)
  83.         countslw = countsl + 1
  84.         for i=1,countslw do
  85.             --shell.run("cd", "..")
  86.             --printud()
  87.         end
  88.         --print(startupls)
  89.         --sleep(10)
  90.         if startupls ~= "none" and startupls ~= nil then
  91.             local stu = fs.open("startup.lua", "w")
  92.             stu.write(startupls)
  93.             stu.close()
  94.         end
  95.         if strtprg == nil and strtprg == "no" and strtprg == "none" then
  96.         else
  97.  
  98.         --if progargs ~= nil then
  99.         --    shell.run(udloc.."/"..updateprogram.." "..unpack(progargs))
  100.         --else
  101.         --    shell.run(udloc.."/"..updateprogram)
  102.         --end
  103.         end
  104.     end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement