diff options
author | Carlo Landmeter <clandmeter@alpinelinux.org> | 2018-01-26 14:06:31 +0000 |
---|---|---|
committer | Carlo Landmeter <clandmeter@alpinelinux.org> | 2018-01-26 14:06:31 +0000 |
commit | 9d3930649818b5747381951480e26af34424bcc6 (patch) | |
tree | e67984838e8460fc024b65ba819c38b8d1c087c5 /generate-mirrors-json.lua | |
parent | cedc084bb831f21325da66f36cefafcb8b4dfed3 (diff) | |
download | alpine-mirror-status-9d3930649818b5747381951480e26af34424bcc6.tar.bz2 alpine-mirror-status-9d3930649818b5747381951480e26af34424bcc6.tar.xz |
add mirrors.json script
This accepts private.yaml from alpine mirrors repo as input
and outputs a filtered mirrors.json.
Diffstat (limited to 'generate-mirrors-json.lua')
-rwxr-xr-x | generate-mirrors-json.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/generate-mirrors-json.lua b/generate-mirrors-json.lua new file mode 100755 index 0000000..5813a31 --- /dev/null +++ b/generate-mirrors-json.lua @@ -0,0 +1,29 @@ +#!/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 json as second argument!") + +local mirrors = yaml.load(pfile.read(input)) +local public_keys = { "name", "location", "bandwidth", "urls" } + +local res = {} + +for k,m in ipairs(mirrors) do + res[k] = {} + for _,pk in ipairs(public_keys) do + res[k][pk] = m[pk] + end +end + +pfile.write(output, json.encode(res)) |