Advertisement
BruceWplays

Updater V2

Sep 10th, 2022 (edited)
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function udprog(updateprogram, pastelink, udloc, updatefunargs, startupls)
  2. updateloop = 0
  3. --fupdateargs = {...}
  4. updateargs = updatefunargs
  5. os.loadAPI("/rom/programs/shell.lua")
  6. while true do
  7.     if fs.isDir(udloc) == false then
  8.         fs.makeDir(udloc)
  9.     end
  10.     shell.shell.run("cd", udloc)
  11.  
  12.  
  13.     if fs.exists(updateprogram.."new") then
  14.         shell.shell.run("delete",updateprogram.."new")
  15.     end
  16.     shell.shell.run("pastebin","get",pastelink,updateprogram.."new")
  17.     if fs.exists(updateprogram.."new") then
  18.         if fs.exists(updateprogram.."old") then
  19.             shell.shell.run("delete",updateprogram.."old")
  20.         end
  21.         if fs.exists("Farm") then
  22.             shell.shell.run("rename",updateprogram,updateprogram.."old")
  23.         end
  24.         shell.shell.run("rename",updateprogram.."new",updateprogram)
  25.         if fs.exists(updateprogram) then
  26.             break
  27.         end
  28.     end
  29.     if fs.exists(updateprogram) then
  30.         if updateloop > 20 then
  31.             break
  32.         end
  33.     end
  34.     if fs.exists(updateprogram.."old") then
  35.         if updateloop > 30 then
  36.             shell.shell.run("rename",updateprogram.."old",updateprogram)
  37.             if fs.exists(updateprogram) then
  38.                 break
  39.             end
  40.         end
  41.     end
  42.     updateloop = updateloop + 1
  43. end
  44. local _, countsl = string.gsub(udloc,"/","")
  45. countsl = countsl + 1
  46.  
  47. if startupls ~= "none" or startupls ~= nil then
  48.     local stu = fs.open("startup.lua", "w")
  49.     stu.write(startupls)
  50.     stu.close()
  51. end
  52. if updatefunargs ~= nil or updatefunargs ~= "none" then
  53.     shell.shell.run(updateprogram .. "," .. unpack(updateargs))
  54. else
  55.     shell.shell.run(updateprogram)
  56. end
  57. for i=1,countsl do
  58.     shell.shell.run("cd", "..")
  59. end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement