Advertisement
Nothy

Axiom installer

May 20th, 2016
6,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. --Copyright 2016 Linus Ramneborg
  2. --All rights reserved.
  3.  
  4. local TermWidth, TermHeight = term.getSize()
  5. local tArgs = {...}
  6. local bgcolor = colors.white
  7. local progBarC = colors.gray
  8. local progBarFillC = colors.cyan
  9. if not color then
  10. progBarFillC = colors.lightGray
  11. end
  12. local version = os.version()
  13. if version == "CraftOS 1.5" then
  14. error("Axiom is not compatible with "..version.."!")
  15. end
  16. local textC = colors.black
  17. local width = 25
  18. local pocket_width = 10
  19. local productName = "Axiom"
  20. local minimal = false
  21. local indev = false
  22. local repair = false
  23.  
  24.  
  25. for k,v in ipairs(tArgs) do
  26. if v == "minimal" then
  27. minimal = true
  28. end
  29. if v == "nightly" then
  30. indev = true
  31. end
  32. if v == "-rep" then
  33. repair = true
  34. end
  35. end
  36. local urls = {
  37. "https://www.dropbox.com/s/a7fp2jo6tgm7xsy/startup?dl=1",
  38. "https://www.dropbox.com/s/7mzhcfe53dm2rq5/sys.axs?dl=1",
  39. "https://www.dropbox.com/s/t40vz4gvmyrcjv4/background.axg?dl=1",
  40. "https://www.dropbox.com/s/wi4n0j98d82256f/AX.nfp?dl=1",
  41. "https://www.dropbox.com/s/cjahddofwhja8og/axiom.axg?dl=1",
  42. "https://www.dropbox.com/s/osz72e1rnvt5opl/nature.axg?dl=1",
  43. "https://www.dropbox.com/s/9byakcx77k03yji/setting?dl=1",
  44. "https://www.dropbox.com/s/a5kxzjl6122uti2/edge?dl=1",
  45. "https://www.dropbox.com/s/p3kgkzhe27vr9lj/encryption?dl=1",
  46. "https://www.dropbox.com/s/ynyrs22t1hh2mry/settings?dl=1",
  47. "https://www.dropbox.com/s/nd608k6k4boeqtx/button?dl=1",
  48. "https://www.pastebin.com/raw/vyAZc6tj",
  49. "https://www.dropbox.com/s/pe72iyt94jfs9tv/settings?dl=1",
  50. "https://www.dropbox.com/s/hqdf140odxdcr2g/sysinfo?dl=1",
  51. "https://www.dropbox.com/s/3vn6wqy765v3wv1/explorer?dl=1",
  52.  
  53. }
  54. local files = {
  55. "startup",
  56. "Axiom/sys.axs",
  57. "Axiom/images/default.axg",
  58. "Axiom/images/AX.nfp",
  59. "Axiom/images/axiom.axg",
  60. "Axiom/images/nature.axg",
  61. "Axiom/libraries/setting",
  62. "Axiom/libraries/edge",
  63. "Axiom/libraries/encryption",
  64. "Axiom/settings.0",
  65. "Axiom/libraries/button",
  66. "home/prg/luaide.app",
  67. "Axiom/programs/settings.app",
  68. "Axiom/programs/store.app",
  69. "Axiom/programs/explorer.app",
  70. }
  71. if #files ~= #urls then
  72. error("Invalid package, url:file ratio is "..#urls..":"..#files..", or "..(#urls/#files))
  73. end
  74. if fs.getFreeSpace("/") <= 300000 then
  75. error("Not enough free space! At least 300kb (300 000 bytes) is required! And you have "..fs.getFreeSpace("/").." bytes available.")
  76. end
  77. local start = ((52 / 2) - (width / 2))-1
  78. local pocket_start = ((26/2 ) - (pocket_width / 2))
  79. local pocket_end = ((26/2 ) + (pocket_width / 2))
  80. local End = ((52 / 2) + (width / 2))-1
  81. function download(url, file)
  82. fdl = http.get(url)
  83. if fdl == nil then
  84. print("Could not connect")
  85. return false
  86. else
  87. f = fs.open(file,"w")
  88. f.write(fdl.readAll())
  89. f.close()
  90. end
  91. return true
  92. end
  93. function makedir(dir)
  94. print("makedir: "..dir)
  95. sleep(0.1)
  96. fs.makeDir(dir)
  97. end
  98. function pocket_gui()
  99. edge.render(1,1,TermWidth,TermHeight,bgcolor,bgcolor,"",textC,false)
  100. term.setTextColor(textC)
  101. term.setBackgroundColor(colors.white)
  102. edge.cprint("Installing Axiom Nano",(TermHeight/2)-3)
  103. edge.xprint("0%",pocket_start,(TermHeight/2),textC)
  104. edge.render(pocket_start,(TermHeight/2)+1,pocket_end,(TermHeight/2)+1,progBarC,bgcolor,"",textC,false)
  105. sleep(1)
  106. end
  107. function gui()
  108. edge.render(1,1,TermWidth,TermHeight,bgcolor,bgcolor,"",textC,false)
  109. sleep(1)
  110. local t = ""
  111. if indev then
  112. t = "nightly,"..t
  113. end
  114. if minimal then
  115. t = "indev,"..t
  116. end
  117. term.setBackgroundColor(colors.white)
  118. edge.render(10,5,39,15,colors.white,colors.white,"",colors.black,false)
  119. edge.xprint("0%",start,(TermHeight/2),textC)
  120. edge.render(start,(TermHeight/2)+1,End,(TermHeight/2)+1,progBarC,bgcolor,"",textC,false)
  121. term.setTextColor(textC)
  122. term.setBackgroundColor(colors.white)
  123. if not repair then
  124. if indev then
  125. edge.cprint("Installing Axiom Nightly",(TermHeight/2)-3)
  126. else
  127. edge.cprint("Installing Axiom",(TermHeight/2)-3)
  128. end
  129.  
  130. else
  131. edge.cprint("Repairing Axiom",(TermHeight/2)-3)
  132. end
  133. sleep(1)
  134. end
  135. function round(num, idp)
  136. local mult = 10^(idp or 0)
  137. return math.floor(num * mult + 0.5) / mult
  138. end
  139. print("Downloading dependencies")
  140. if download(urls[8],files[8]) then
  141. print("Dependencies OK")
  142. sleep(0.1)
  143. end
  144. if pocket and tArgs[1] == "nightly" then
  145. if download("https://www.dropbox.com/s/68i2l7m9ol51wd7/sys-pocket.axs?dl=1","Axiom/sys-pocket.axs") then
  146. print("Ready to install Axiom for Pocket Computer")
  147. sleep(0.1)
  148. end
  149. end
  150. print("Preparing for install")
  151. os.loadAPI("Axiom/libraries/edge")
  152. makedir("Axiom/libraries")
  153. makedir("Axiom/images")
  154. makedir("Axiom/programs")
  155. makedir("home/prg/")
  156. makedir("home/Documents")
  157. makedir("home/User-Programs")
  158. makedir("users")
  159. makedir("users/apis")
  160. makedir("users/program-files")
  161. makedir("home/Desktop")
  162. local url_len = #urls
  163. local file_len = #files
  164. local count = 0
  165. local xPos = start
  166. local pocket_pos = pocket_start
  167. local xIncrement = width/file_len
  168. local pocket_increment = pocket_width / file_len
  169. term.setBackgroundColor(bgcolor)
  170. edge.render(1,1,52,19, bgcolor, bgcolor, "", colors.black)
  171. term.setTextColor(colors.gray)
  172. if not minimal or not indev then
  173. edge.cprint("Pick a version to install!", 6)
  174. edge.render(11,8,41, 8, colors.lightBlue, bgcolor, " Latest", colors.black)
  175. edge.render(11,11,41, 11, colors.lightBlue, bgcolor, " Nightly", colors.black)
  176. while(true) do
  177. local e,b,x,y = os.pullEvent()
  178. if e == "mouse_click" then
  179. if x >= 11 and x <= 41 and y == 8 then
  180. edge.render(11,8,41, 8, colors.blue, bgcolor, " Latest", colors.black)
  181. end
  182. if x >= 11 and x <= 41 and y == 11 then
  183. indev = true
  184. edge.render(11, 11,41, 11, colors.blue, bgcolor, " Nightly", colors.black)
  185.  
  186. end
  187. end
  188. if e == "mouse_up" then
  189. if x >= 11 and x <= 41 and y == 8 then
  190. edge.render(11,8,41, 8, colors.lightBlue, bgcolor, " Latest", colors.black)
  191. break
  192. end
  193. if x >= 11 and x <= 41 and y == 11 then
  194. indev = true
  195. edge.render(11, 11,41, 11, colors.lightBlue, bgcolor, " Nightly", colors.black)
  196. break
  197.  
  198. end
  199. end
  200. end
  201. end
  202.  
  203. if not pocket then
  204. gui()
  205. else
  206. pocket_gui()
  207. end
  208. for k,v in ipairs(urls) do
  209. local f = (k / file_len) * 100
  210. xPos = (xPos + xIncrement)
  211. pocket_pos = (pocket_pos + pocket_increment)
  212. if not pocket then
  213. term.setBackgroundColor(colors.white)
  214. term.setTextColor(textC)
  215. edge.xprint(" ",start,(TermHeight/2),textC)
  216. edge.xprint(round(f,1).."%",start,(TermHeight/2),textC)
  217. edge.render(start,(TermHeight/2)+1,xPos,(TermHeight/2)+1,progBarFillC,bgcolor,"",textC,false)
  218. edge.xprint(" ",start,(TermHeight/2+2),colors.lightGray)
  219. edge.xprint(files[k],start,(TermHeight/2+2),colors.lightGray)
  220. end
  221. if pocket then
  222. term.setBackgroundColor(colors.white)
  223. term.setTextColor(textC)
  224. edge.xprint(" ",pocket_start,(TermHeight/2),textC)
  225. edge.xprint(round(f,1).."%",pocket_start,(TermHeight/2),textC)
  226. edge.render(pocket_start,(TermHeight/2)+1,pocket_pos,(TermHeight/2)+1,progBarFillC,bgcolor,"",textC,false)
  227.  
  228. end
  229. if k == 8 then
  230.  
  231. else
  232. if not fs.exists(files[k]) then
  233. if minimal and k >= 4 and k <= 6 or minimal and k >= 13 and k <= 14 then
  234. edge.xprint(files[k].." ignored",start,(TermHeight/2+2),colors.lightGray)
  235. sleep(0.1)
  236. else
  237. download(urls[k],files[k])
  238. end
  239. else
  240. sleep(0.1)
  241. end
  242. end
  243. end
  244. term.setTextColor(textC)
  245. sleep(2)
  246. if tArgs[1] == "-serv2016" then
  247. download("https://www.dropbox.com/s/67dycd81yukawnc/sys-server.axs?dl=1","Axiom/sys.axs")
  248. print("Server installed.")
  249. end
  250. if indev then
  251. if pocket then
  252.  
  253. else
  254. fs.delete("Axiom/sys.axs")
  255. print("Installing experimental core")
  256. download("https://www.dropbox.com/s/5v2amjjmw08n9yz/sys-latest.axs?dl=1","Axiom/sys.axs")
  257. term.clear()
  258. shell.run("clear")
  259. fs.makeDir("firstBoot")
  260. end
  261. else
  262. shell.run("Axiom/sys.axs")
  263. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement