blob: 7b7bfa8270e84e28ac9576f039d6df1fcf31d5c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/usr/bin/lua5.3
---
-- convert private yaml to a public json mirror file
-- dependencies:
-- lua5.3-cjson
-- lua5.3-lyaml
-- lua5.3-penlight
local json = require("cjson")
local yaml = require("lyaml")
local pfile = require("pl.file")
local input = assert(arg[1], "Please provide input yaml as first argument!")
local output = assert(arg[2], "Please provide output directory as second argument!")
local mirrors = yaml.load(pfile.read(input))
local public_keys = { "name", "location", "bandwidth", "urls" }
local res = {}
local txt = {}
for k,m in ipairs(mirrors) do
res[k] = {}
for _,pk in ipairs(public_keys) do
res[k][pk] = m[pk]
if pk == "urls" then
for _,url in pairs(m.urls) do
if url:find("http://") then
table.insert(txt, url)
end
end
end
end
end
pfile.write(output.."/mirrors.json", json.encode(res))
pfile.write(output.."/mirrors.txt", table.concat(txt, "\n"))
|