bind: improve reload script
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2670|2|2668|2|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/442//ansiblelint">Evolix » ansible-roles » unstable #442</a>
gitea/ansible-roles/pipeline/head This commit looks good

This commit is contained in:
William Hirigoyen 2023-12-27 15:01:56 +01:00
parent 1ac497282c
commit 41897f4c62
3 changed files with 55 additions and 14 deletions

37
bind/files/bind-reload-zone.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
#
# Script utilitaire pour tester et recharger facilement une zone dans Bind
#
usage() {
echo "Usage: bind-reload-zone <DOMAIN>"
echo " bind-reload-zone -h|--help"
}
if [ $# -ne 1 ] ; then
usage
exit 1
fi
while :; do
case $1 in
-h|--help)
usage
exit 0
;;
*)
zone=$1
break
;;
esac
shift
done
if ! [ -f "/etc/bind/db.${zone}" ]; then
>&2 echo "Error: zone for ${zone} not found."
usage
exit 1
fi
named-checkzone "${zone}" /etc/bind/db."${zone}" && rndc reload "${zone}"

View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
_bind_reload_zone_dynamic_completion() {
local cur;
cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=();
COMPREPLY=( $( compgen -W '$(grep -v -h '"'"'//'"'"' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep -v arpa | awk '"'"'{gsub(/"/, "", $2); print $2}'"'"' | sort | uniq)' -- $cur ) );
# reverse ipv4 :
#grep -v -h '//' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep -v ip6 | awk '{gsub(/"/, "", $2); gsub(/.in-addr.arpa/, "", $2); print $2}' | sort | uniq | awk -F'.' '{ for (i=NF; i>1; i--) printf("%s.",$i); print $1 }'
# reveres ipv6 : je bloque sur l'inversion 4 par 4
#grep -v -h '//' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep ip6 | awk '{gsub(/"/, "", $2); gsub(/.ip6.arpa/, "", $2); print $2}' | sort | uniq | awk -F'.' '{ for (i=NF; i>1; i--) { if ($i % 4 == 0) printf("%s.",$i); else printf("%s",$i); } print $1 }'
}
complete -F _bind_reload_zone_dynamic_completion bind-reload-zone

View file

@ -1,14 +0,0 @@
#!/bin/bash
#
# Script utilitaire pour tester et recharger facilement un domaine dans Bind
# Usage : reload-zone <DOMAINE>
#
# TODO:
# - renommer le script (par ex bind-safe-reload)
# - vérifier le serial
# - ajouter un -h --help
# - prendre en charge plusieurs zones (ou aucune)
# - ajouter le script dans le role bind
named-checkzone "$1" /etc/bind/db."$1" && rndc reload "$1"