Advertisement
BruceWplays

Updater V3

Sep 11th, 2022 (edited)
863
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.  
  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 fs.isDir(udloc) == false then
  32.         fs.makeDir(udloc)
  33.     end
  34.     shell.run("cd", udloc)
  35.     if fs.exists(udloc.."/"..updateprogram.."new") then
  36.         shell.run("delete",updateprogram.."new")
  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.             printud()
  46.         end
  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 fs.exists(udloc.."/"..updateprogram) then
  53.             break
  54.         end
  55.     end
  56.     if fs.exists(udloc.."/"..updateprogram) then
  57.         if updateloop > 20 then
  58.             break
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement