Miscellaneous OpenComputers stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.2KB

  1. local serial = require "serialization"
  2. local tArgs = {...}
  3. local src, dest = tArgs[1], tArgs[2].."/"
  4. local _OSVERSION = _OSVERSION or ""
  5. local function normalisePath(path)
  6. local pt = {}
  7. for seg in path:gmatch("[^/]+") do
  8. pt[#pt+1] = seg
  9. end
  10. pre = ""
  11. if path:sub(1,1) == "/" then
  12. pre = "/"
  13. end
  14. return pre .. table.concat(pt, "/")
  15. end
  16. local function wget(src,dest)
  17. dest=normalisePath(dest)
  18. local fstr = "wget '%s' -qO '%s'"
  19. local command = string.format(fstr,src,dest)
  20. print(command)
  21. return os.execute(command)
  22. end
  23. local dirs = {}
  24. local function mkdir(path)
  25. path=normalisePath(path)
  26. if dirs[path] then return true end
  27. local fstr = "mkdir -p '%s'"
  28. if _OSVERSION:sub(1,6) == "OpenOS" then
  29. fstr = "mkdir '%s'"
  30. end
  31. local command = string.format(fstr,path)
  32. print(command)
  33. dirs[path] = true
  34. return os.execute(command)
  35. end
  36. local function parsecfg(path)
  37. path=normalisePath(path)
  38. local f = io.open(path,"rb")
  39. if not f then error("unable to open "..tostring(path).." for parsing") end
  40. local rt = serial.unserialize(f:read("*a"))
  41. f:close()
  42. if type(rt) ~= "table" then error("unable to parse "..tostring(path)) end
  43. return rt
  44. end
  45. local function writecfg(t,path)
  46. path=normalisePath(path)
  47. local f = io.open(path, "wb")
  48. if not f then error("unable to open "..tostring(path).." for writing") end
  49. f:write(serial.serialize(t))
  50. f:close()
  51. end
  52. local pathpre = src:match("(.+/).+/.+")
  53. print(pathpre)
  54. mkdir(dest.."/master/")
  55. local pcfgname = os.tmpname()
  56. wget(src,pcfgname)
  57. local programs = parsecfg(pcfgname)
  58. os.execute("rm '"..pcfgname.."'")
  59. local dlfiles = {}
  60. for k,v in pairs(programs) do
  61. if v.files then
  62. for l,m in pairs(v.files) do
  63. dlfiles[#dlfiles+1] = l
  64. end
  65. end
  66. end
  67. for k,v in pairs(dlfiles) do
  68. local path,fn = v:match("(.+)/(.+)")
  69. if v:sub(1,4) ~= "http" then
  70. mkdir(dest..path)
  71. wget(pathpre..v,dest..v)
  72. else
  73. mkdir(dest.."/external")
  74. wget(v,dest.."/external/"..fn)
  75. end
  76. end
  77. -- merge programs.cfg with existing if applicable
  78. local w, oprograms = pcall(parsecfg, dest.."/master/programs.cfg")
  79. if w then
  80. for k,v in pairs(oprograms) do
  81. programs[k] = programs[k] or v
  82. end
  83. end
  84. writecfg(programs, dest.."/master/programs.cfg")
  85. wget("https://git.shadowkat.net/izaya/OC-misc/raw/branch/master/repo-installer/repoinstaller.lua", dest.."/.install")