Advertisement
BruceWplays

Updater V4

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