-
Notifications
You must be signed in to change notification settings - Fork 0
/
knot-tsig-export.bash
47 lines (42 loc) · 1.19 KB
/
knot-tsig-export.bash
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
39
40
41
42
43
44
45
46
#
### Copyright © 2024 Christopher Bock <[email protected]>
### SPDX-License-Identifier: MIT
###
#
# Get tsig-keys for use with nsupdate / oneline(-y)
# Also helps if you imported old bind keys and didn't create the
# commented(#) oneline key entries.
knot-tsig-oneline() {
if ! ((${#1})); then
knotc conf-read key.id
else
ID="$1"
ALGO=$(knotc conf-read "key[$ID].algorithm"|awk '{print$3}');
SECRET=$(knotc conf-read "key[$ID].secret"|awk '{print$3}') ;
printf '# %s:%s:%s\n' "$ALGO" "$ID" "$SECRET";
fi
}
knot-tsig-nsupdate() {
if ! ((${#1})); then
knotc conf-read key.id
else
ID="$1"
ALGO=$(knotc conf-read "key[$ID].algorithm"|awk '{print$3}');
SECRET=$(knotc conf-read "key[$ID].secret"|awk '{print$3}') ;
printf 'key "%s" {\n\talgorithm %s;\n\tsecret "%s";\n};\n' "$ID" "$ALGO" "$SECRET";
fi
}
_knot_keys() {
_knot_keys="${_knot_keys:=$(knotc conf-read key.id|awk '{print$3}')}"
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $COMP_CWORD in
1)
COMPREPLY=($(compgen -W "${_knot_keys}" -- ${cur}))
compopt +o nospace
;;
esac
return 0
}
complete -F _knot_keys knot-tsig-nsupdate knot-tsig-oneline