diff --git a/divers/bind/mkzone b/divers/bind/mkzone index 33aee57..49782c3 100755 --- a/divers/bind/mkzone +++ b/divers/bind/mkzone @@ -1,14 +1,23 @@ -#!/bin/bash -set -u -set -e +#!/usr/bin/env bash + +set -Eeuo pipefail +trap cleanup SIGINT SIGTERM ERR EXIT + # cree les fichiers de configuration bind9 # - ficher de zone directe # - ficher de zone inverse # +version="1.1" zone="domaine.lan" +slave=0 +cleanup() { + trap - SIGINT SIGTERM ERR EXIT + # script cleanup here +} + initialize () { readonly zonenet="192.168.56" readonly zonerev="56.168.192.in-addr.arpa" @@ -31,17 +40,10 @@ readonly zonep="${zone}." readonly date=$(date +%Y%m%d00) } -if [[ $# != 1 ]] ; then - echo "usage : $0 " - exit 1 -fi -zone=$1 -initialize - - +mkconflocal () { +if [[ "${slave}" != 1 ]] ; then echo "Generation fichier named.conf.local ..." cat < "named.conf.local" - # fichier zone ${zone} # le $(date) @@ -52,11 +54,31 @@ zone "${zone}" { zone "${zonerev}" { type master; - file "/etc/bind/db.${zone}.rev"; # zone inverse +}; +EOT +else +echo "Generation fichier named.conf.local ..." +cat < "named.conf.local" +# fichier zone ${zone} +# le $(date) + +zone "${zone}" { + type slave; + file "/var/cache/bind/db.${zone}"; # zone directe + masters { ${nsip} ; }; +}; + +zone "${zonerev}" { + type slave; + file "/var/cache/bind/db.${zone}.rev"; # zone directe + masters { ${nsip} ; }; }; EOT +fi +} +mkzdirrect () { # fichier de zone directe echo "Generation fichier de zone directe db.${zone} ..." cat < "db.${zone}" @@ -86,7 +108,9 @@ ${nsname2} IN A ${nsip2} IN AAAA 2001:DB8:BEEF:100::22 EOT +} +mkzreverse () { echo "Generation fichier de zone inverse db.${zone}.rev ..." cat < "db.${zone}.rev" ; fichier zone inverse ${zone} @@ -109,6 +133,9 @@ ${nsiprev2} IN PTR ${nsname2}.${zone}. EOT +} + +mkresolv () { echo "Generation fichier /etc/resolv.conf ..." cat < "/etc/resolv.conf" @@ -118,5 +145,99 @@ domain ${zone} search ${zone} nameserver 127.0.0.1 EOT +} +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) +usage() { + cat <&2 -e "${1-}" +} + +die() { + local msg=$1 + local code=${2-1} # default exit status 1 + msg "$msg" + exit "$code" +} + +parse_params() { + # default values of variables set from params + flag=0 + param='' + + while :; do + case "${1-}" in + -h | --help) usage ;; + --no-color) NO_COLOR=1 ;; + -s | --slave) flag=1 ;; # example flag +# -p | --param) # example named parameter +# param="${2-}" +# shift +# ;; + -?*) die "Unknown option: $1" ;; + *) break ;; + esac + shift + done + + args=("$@") + + # check required params and arguments +# [[ -z "${param-}" ]] && die "Missing required parameter: param" + [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments" + + return 0 +} + +parse_params "$@" +setup_colors + +# script logic here + +#msg "${RED}Read parameters:${NOFORMAT}" +#msg "- flag: ${flag}" +#msg "- param: ${param}" +#msg "- arguments: ${args[*]-}" + +zone="${args[0]-}" +slave="${flag}" +initialize +if [[ ${flag} != 1 ]] ; then + mkconflocal + mkzdirect + mkzreverse + mkresolv +else + mkconflocal + mkresolv +fi +exit 0