Advertisement
Guest User

Untitled

a guest
May 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. local args = {}
  2.  
  3. local quiet = args[1] == "-q"
  4.  
  5. local r = http.get("https://api.github.com/repos/MultHub/Aurora/git/refs/heads/master")
  6. local c = r.readAll():gsub("\"[a-z]+\":", function(match) return match:sub(2, #match - 2) .. "=" end)
  7. r.close()
  8.  
  9. local latestSha = textutils.unserialize(c).object.sha
  10.  
  11. local currentSha = ""
  12. local f = fs.open(".aurora/currentSha", "r")
  13. if f then
  14. currentSha = f.readAll()
  15. f.close()
  16. end
  17.  
  18. local extraScripts = {
  19. "https://raw.github.com/MultHub/Aurora-apps/master/appsInstaller.lua",
  20. }
  21.  
  22. local function httpGet(url, save)
  23. if not url then
  24. error("not enough arguments, expected 1 or 2", 2)
  25. end
  26. local remote = http.get(url)
  27. if not remote then
  28. return false
  29. end
  30. local text = remote.readAll()
  31. remote.close()
  32. if save then
  33. local file = fs.open(save, "w")
  34. file.write(text)
  35. file.close()
  36. return true
  37. end
  38. return text
  39. end
  40.  
  41. if currentSha == latestSha then
  42. if not quiet then
  43. print("Aurora running latest version, delete .aurora/currentSha to force")
  44. sleep(1)
  45. end
  46. else
  47. local files = {
  48. ["startup"] = "startup"
  49. }
  50. local aurorasrc = {
  51. "apis/argparser",
  52. "apis/base64",
  53. "apis/img",
  54. "apis/sha",
  55. "apis/xml",
  56. "sdk/bin/lua-preproc",
  57. "sdk/init",
  58. "aFile",
  59. "appbrowser",
  60. "aUtil",
  61. "credits",
  62. "credplay",
  63. "firstBoot",
  64. "floppyinstall",
  65. "init",
  66. "menuItems",
  67. "settingsUI",
  68. "ui",
  69. "wallpaper",
  70. "update",
  71. "pager",
  72. "help.txt",
  73. "vfs",
  74. }
  75.  
  76. for i, v in ipairs(aurorasrc) do
  77. files["aurorasrc/" .. v] = ".aurora/" .. v
  78. end
  79.  
  80. local githubUser = "MultHub"
  81. local githubRepo = "Aurora"
  82. local githubBranch = "master"
  83.  
  84. local installerName = "Aurora Updater"
  85.  
  86. local function clear()
  87. term.clear()
  88. term.setCursorPos(1, 1)
  89. end
  90.  
  91. local function get(user, repo, bran, path, save)
  92. if not user or not repo or not bran or not path then
  93. error("not enough arguments, expected 4 or 5", 2)
  94. end
  95. local url = "https://raw.github.com/" .. user .. "/" .. repo .. "/" .. bran .. "/" .. path
  96. local text = httpGet(url)
  97. if save then
  98. local file = fs.open(save, "w")
  99. file.write(text)
  100. file.close()
  101. return true
  102. end
  103. return text
  104. end
  105.  
  106. local function getFile(file, target)
  107. return get(githubUser, githubRepo, githubBranch, file, target)
  108. end
  109.  
  110. local fileCount = 0
  111. for _ in pairs(files) do
  112. fileCount = fileCount + 1
  113. end
  114. local filesDownloaded = 0
  115.  
  116. local w, h = term.getSize()
  117.  
  118. for k, v in pairs(files) do
  119. if not quiet then
  120. term.setTextColor(colors.black)
  121. term.setBackgroundColor(colors.white)
  122. clear()
  123. term.setCursorPos(2, 2)
  124. print(installerName)
  125. term.setCursorPos(2, 4)
  126. print("File: " .. v)
  127. term.setCursorPos(2, h - 1)
  128. print(tostring(math.floor(filesDownloaded / fileCount * 100)) .. "% - " .. tostring(filesDownloaded + 1) .. "/" .. tostring(fileCount))
  129. end
  130. local ok = k:sub(1, 4) == "ext:" and httpGet(k:sub(5), v) or getFile(k, v)
  131. if not ok and not quiet then
  132. if term.isColor() then
  133. term.setTextColor(colors.red)
  134. end
  135. term.setCursorPos(2, 6)
  136. print("Error getting file:")
  137. term.setCursorPos(2, 7)
  138. print(k)
  139. sleep(1)
  140. end
  141. filesDownloaded = filesDownloaded + 1
  142. end
  143. if not fs.exists("apps") then
  144. fs.makeDir("apps")
  145. end
  146.  
  147. if not quiet then
  148. term.setTextColor(colors.white)
  149. term.setBackgroundColor(colors.black)
  150. clear()
  151. end
  152.  
  153. local f = fs.open(".aurora/currentSha", "w")
  154. f.write(latestSha)
  155. f.close()
  156. end
  157.  
  158. for i, v in ipairs(extraScripts) do
  159. if not quiet then write(v .. ": ") end
  160. local str = httpGet(v)
  161. if not str then
  162. if not quiet then
  163. print("download error")
  164. end
  165. else
  166. local fn, err = loadstring(str, fs.getName(v))
  167. if not fn then
  168. if not quiet then
  169. printError("script error\n " .. err)
  170. end
  171. else
  172. local o, e = pcall(setfenv(fn, getfenv()))
  173. if not quiet then
  174. if not o then
  175. printError("script error\n " .. e)
  176. else
  177. print("ok")
  178. end
  179. end
  180. end
  181. end
  182. end
  183.  
  184. if quiet then
  185. return
  186. end
  187. sleep(1)
  188. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement