From: Marek Vavrusa Date: Fri, 22 Jan 2016 07:48:58 +0000 (-0800) Subject: scripts: kresd-query.lua (new) X-Git-Tag: v1.0.0-beta3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b81be10ed76c30a3afa329c6f26f8fb5bce8f93d;p=thirdparty%2Fknot-resolver.git scripts: kresd-query.lua (new) this is a boilerplate for a CLI utility to resolve names and execute script on query response in another words, "a jq for resolver answers" this is a scaffolding for alternative tools like 'host' or a plug-in part for scripting around it. it basically starts a kresd instance, but doesn't bind to any interface or read configuration, then a query + callback is sent to kresd standard input, and it quits after the execution --- diff --git a/scripts/kresd-query.lua b/scripts/kresd-query.lua new file mode 100755 index 000000000..d4e57d761 --- /dev/null +++ b/scripts/kresd-query.lua @@ -0,0 +1,61 @@ +#!/usr/bin/env luajit +cli_bin = 'kresd -q -c -' +-- Work around OS X stripping dyld variables +libdir = os.getenv('DYLD_LIBRARY_PATH') +if libdir then + cli_bin = string.format('DYLD_LIBRARY_PATH="%s" %s', libdir, cli_bin) +end +cli_cmd = [[echo ' +option("ALWAYS_CUT", true) +%s +return resolve("%s", kres.type.%s, kres.class.%s, 0, +function (pkt, req) + pkt = kres.pkt_t(pkt) + req = kres.request_t(req) + pcall(function () %s end) + quit() +end)']] +-- Parse CLI arguments +local function help() + name = 'kresd-query.lua' + print(string.format('Usage: %s [-t type] [-c class] [-C config]