Advertisement
Alakazard12

OSRunner Installer

Mar 16th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local git = "https://raw.github.com/MudkipTheEpic/ComputerCraft/master"
  2.  
  3. local InstallFiles = {
  4.     {"APIs/osrunner", "APIs/osrunner"};
  5.     {"APIs/zip", "APIs/zip"};
  6.     {"Resources/logo", "Resources/logo"};
  7.     {"Resources/main", "Resources/main"};
  8.     {"Boot/startup", "Boot/startup"};
  9. }
  10.  
  11. local Directories = {
  12.     "APIs";
  13.     "Resources";
  14.     "Boot";
  15. }
  16.  
  17. local Version = "1.1"
  18.  
  19. if not http then
  20.     print("You must have http enabled to install OSRunner")
  21.     return
  22. end
  23.  
  24. local function Download(Link)
  25.     if not http then return false end
  26.     local Res = http.get(Link)
  27.     if not Res then return false end
  28.     local ToR = Res.readAll()
  29.     Res.close()
  30.     return ToR
  31. end
  32.  
  33. local Vers = Download(git .. "/CurrentVersion/installer")
  34. if Vers ~= Version then
  35.     local Update = Download(git .. "/installer")
  36.     local Fo = fs.open(shell.getRunningProgram(), "w")
  37.     Fo.write(Update)
  38.     Fo.close()
  39.     shell.run(shell.getRunningProgram())
  40.     return
  41. end
  42.  
  43. for i,v in pairs(Directories) do
  44.     if fs.exists(v) then
  45.         fs.delete(v)
  46.     end
  47.     fs.makeDir(v)
  48. end
  49.  
  50. for i,v in pairs(InstallFiles) do
  51.     if fs.exists(v[2]) then
  52.         fs.delete(v[2])
  53.     end
  54.     local Res = Download(git .. "/" .. v[1])
  55.     if Res == false then
  56.         print("Unable to download")
  57.         return
  58.     end
  59.     local Fo = fs.open(v[2], "w")
  60.     Fo.write(Res)
  61.     Fo.close()
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement