turtle5204

DeltaOS unstable installer

Aug 9th, 2014
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. local stStr = "Installing DeltaOS..."
  4. local w,h = term.getSize()
  5. local amd = 0
  6.  
  7. local function drawLine(y, col, txt)
  8.  local w,h = term.getSize()
  9.  paintutils.drawLine( 1, y, w, y, col )
  10.  term.setCursorPos( w/2-txt:len()/2, y )
  11.  write(txt)
  12. end
  13.  
  14. local function draw(ab)
  15. term.setBackgroundColor(colors.white)
  16. term.setTextColor(colors.black)
  17. term.clear()
  18. term.setCursorPos(w/2-stStr:len()/2, 2)
  19. write(stStr)
  20. if ab == true then
  21.  term.setCursorPos(w/2-string.len("OneOS detected")/2, 3)
  22.  write("OneOS Detected")
  23. end
  24.  
  25. end
  26.  
  27.  
  28. if OneOS then
  29.  draw(ab)
  30.  drawLine(5, colors.blue, "Install with Sandbox")
  31.  drawLine(7, colors.blue, "Install and Override sandbox")
  32.  while true do
  33.   local _, button, x, y = os.pullEvent("mouse_click")
  34.  if y == 5 then
  35.   break
  36.  elseif y == 7 then
  37.   fs = OneOS.FS
  38.   break
  39.  end
  40.  end
  41. end
  42.  
  43.  
  44. if fs.getDir(shell.getRunningProgram()) ~= "" and fs.getDir(shell.getRunningProgram()) ~= "rom/programs/http" then
  45.  fs.move(shell.getRunningProgram(), "/")
  46. end
  47.  
  48.  
  49.  
  50.  
  51.  
  52. draw()
  53. --[[ /gitget
  54. GitHub downloading utility for CC.
  55. Developed by apemanzilla.
  56.  
  57. If you want to use this as an automated installer, please see lines 13 and 23.
  58.  
  59. This requires ElvishJerricco's JSON parsing API.
  60. Direct link: http://pastebin.com/raw.php?i=4nRg9CHU
  61. ]]--
  62.  
  63.  
  64.  
  65.  
  66. --Remove the line above this and change the lines below to use automated mode.
  67. local automated = true                                                  -- Don't touch!
  68. local hide_progress = true                                              -- If true, will not list out files as they are downloaded
  69. args[1] = "FlareHAX0R"                                                 -- Github username
  70. args[2] = "DeltaOS"                                                               -- Github repo name
  71. args[3] = nil                                                                   -- Branch - defaults to "master"
  72. args[4] = "/"                                                                -- Path - defaults to root ("/")
  73. local pre_dl = " "  -- Command(s) to run before download starts.
  74. local post_dl = "os.reboot()"   -- Command(s) to run after download completes.
  75. --Remove the line below this and change the lines below to use automated mode.
  76.  
  77. args[3] = args[3] or "master"
  78. args[4] = args[4] or ""
  79.  
  80. if not automated and #args < 2 then
  81.         print("Usage:\n"..shell.getRunningProgram().." <user> <repo> [branch=master] [path=/]") error()
  82. end
  83.  
  84. local function save(data,file)
  85.         local file = shell.resolve(file)
  86.         if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  87.                 if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  88.                 fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  89.         end
  90.         local f = fs.open(file,"w")
  91.         f.write(data)
  92.         f.close()
  93. end
  94.  
  95. local function download(url, file)
  96.         save(http.get(url).readAll(),file)
  97. end
  98.  
  99. if not json then
  100.         --print("Downloading JSON api...\n(Credits to ElvishJerricco!)")
  101.         download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  102.         os.loadAPI("json")
  103. end
  104.  
  105. if pre_dl then loadstring(pre_dl)() else print("Downloading files from github....") end
  106. local data = json.decode(http.get("https://api.github.com/repos/"..args[1].."/"..args[2].."/git/trees/"..args[3].."?recursive=1").readAll())
  107. if data.message and data.message == "Not found" then error("Invalid repository",2) else
  108.     for k,v in pairs(data.tree) do
  109.         -- Make directories
  110.         if v.type == "tree" then
  111.             fs.makeDir(fs.combine(args[4],v.path))
  112.             if not hide_progress then
  113.                 print(v.path)
  114.             end
  115.         end
  116.     end
  117.     for k,v in pairs(data.tree) do
  118.         -- Download files
  119.         if v.type == "blob" then
  120.             download("https://raw.github.com/"..args[1].."/"..args[2].."/"..args[3].."/"..v.path,fs.combine(args[4],v.path))
  121.             amd = amd+1
  122.    term.setCursorPos(w/2-string.len(tostring(amd))/2, 5)
  123.    term.clearLine()
  124.    term.setCursorPos(w/2-string.len(tostring(amd).." files downloaded")/2, 5)
  125.    write(tostring(amd).." files downloaded")
  126.    if not hide_progress then
  127.                 print(v.path)
  128.             end
  129.         end
  130.     end
  131. end
  132. if post_dl then loadstring(post_dl)() end
Advertisement
Add Comment
Please, Sign In to add comment