From 9d3930649818b5747381951480e26af34424bcc6 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 26 Jan 2018 14:06:31 +0000 Subject: add mirrors.json script This accepts private.yaml from alpine mirrors repo as input and outputs a filtered mirrors.json. --- generate-mirrors-json.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 generate-mirrors-json.lua (limited to 'generate-mirrors-json.lua') 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)) -- cgit v1.2.3