Advertisement
Alakazard12

Installer

Jan 30th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. --[[
  2.   COS (Cat Operating System)
  3.   Made by: MasterDisasterHD, Sxw1212,
  4.   Thib0704, and Alakazard12
  5.  
  6.   File: install.lua
  7.   Authors: Sxw1212
  8.  
  9.   Copyright COSTeam 2014
  10. ]]--
  11.  
  12. print("CatOS installer v2.1")
  13.  
  14. local baseURL
  15. if _G.COS and _G.COS.devMode then
  16.         baseURL = "https://github.com/ComputerCraftTeam/COS/raw/master/"
  17. else
  18.         baseURL = "https://github.com/ComputerCraftTeam/COS/raw/stable/"
  19. end
  20.  
  21. if _G.COS and not _G.COS.devMode then
  22.         local version = http.get("https://github.com/ComputerCraftTeam/COS/raw/stable/extra/version")
  23.         if not version then
  24.                 print("Failed to get version")
  25.                 return
  26.         end
  27.        
  28.         if version.readAll() == os.version() then
  29.                 print("Cat OS up-to-date")
  30.                 return
  31.         end
  32. end
  33.  
  34. local function get(url, file)
  35.         local wh = http.get(url)
  36.         if wh then
  37.                 local fh = fs.open(file, "w")
  38.                 fh.write(wh.readAll())
  39.                 fh.close()
  40.         else
  41.                 print("Unable to fetch " .. file)
  42.         end
  43. end
  44.  
  45. local todelete = {
  46.     "sys/bin", "sys/api", "sys/apps", "sys/assets"
  47. }
  48.  
  49. local files = {
  50.         ["startup"] = baseURL .. "extra/boot.lua",
  51.         ["sys/"] = {
  52.                 ["cfg/"] = {
  53.                         ["version"] = baseURL .. "extra/version"
  54.                 },
  55.                 ["bin/"] = {
  56.                         ["update"] = baseURL .. "bin/update.lua",
  57.                         ["COS"] = baseURL .. "bin/cos.lua",
  58.                         ["springboard"] = baseURL .. "bin/springboard.lua",
  59.                         ["devmode"] = baseURL .. "bin/devmode.lua",
  60.                         ["compile"] = baseURL .. "bin/compile.lua",
  61.                         ["migrate"] = baseURL .. "bin/migrate.lua",
  62.                         ["run"] = baseURL .. "bin/run.lua",
  63.                         ["wget"] = baseURL .. "bin/wget.lua"
  64.                 },
  65.                 ["api/"] = {
  66.                         ["nova"] = baseURL .. "api/nova.lua",
  67.                         ["crypt"] = baseURL .. "api/crypt.lua",
  68.                         ["utils"] = baseURL .. "api/utils.lua"
  69.                 },
  70.                 ["apps/"] = {
  71.                         ["CatStore.app"] = baseURL .. "apps/CatStore.app"
  72.                 },
  73.                 ["assets/"] = {
  74.                         ["springboard/"] = {
  75.                                     ["background.cpf"] = baseURL .. "assets/springboard/background.cpf"
  76.                           }
  77.             },
  78.             ["logs/"] = {
  79.                
  80.             }
  81.         },
  82.       ["home/"] = {
  83.                ["apps/"] = {
  84.          
  85.                 }
  86.         },
  87.        [".RUN_ENV"] = {
  88.        
  89.         }
  90. }
  91.  
  92. local toget = {}
  93.  
  94. local function map(list, path)
  95.         for k, v in pairs(list) do
  96.                 if type(v) == "table" then
  97.                         fs.makeDir(path .. k)
  98.                         map(v, path .. k)
  99.                 else
  100.                         local file = {
  101.                                 ["url"] = v,
  102.                                 ["loc"] = path .. k
  103.                         }
  104.                         table.insert(toget, file)
  105.                 end
  106.         end
  107. end
  108.  
  109. map(files, "/")
  110.  
  111. for k, v in pairs(todelete) do
  112.     fs.delete(v)
  113. end
  114.  
  115. local c = 0
  116. local x, y = term.getCursorPos()
  117. for k, v in pairs(toget) do
  118.         term.clearLine()
  119.         term.setCursorPos(x, y)
  120.         write((#toget - c) .. " files to fetch")
  121.         c = c + 1
  122.         get(v.url, v.loc)
  123. end
  124.  
  125. if not _G.COS then
  126.     -- First Time install
  127.     local fh = fs.open("/sys/cfg/filestructure", "w")
  128.     fh.write("2")
  129.     fh.close()
  130. end
  131.  
  132. print("")
  133. print("Cat OS Updated")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement