opt -s : pour serveur slave

This commit is contained in:
phil 2023-01-28 21:26:34 +01:00
parent ad18fb502e
commit 16c177fa5b

View File

@ -1,14 +1,23 @@
#!/bin/bash #!/usr/bin/env bash
set -u
set -e set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
# cree les fichiers de configuration bind9 # cree les fichiers de configuration bind9
# - ficher de zone directe # - ficher de zone directe
# - ficher de zone inverse # - ficher de zone inverse
# #
version="1.1"
zone="domaine.lan" zone="domaine.lan"
slave=0
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
initialize () { initialize () {
readonly zonenet="192.168.56" readonly zonenet="192.168.56"
readonly zonerev="56.168.192.in-addr.arpa" readonly zonerev="56.168.192.in-addr.arpa"
@ -31,17 +40,10 @@ readonly zonep="${zone}."
readonly date=$(date +%Y%m%d00) readonly date=$(date +%Y%m%d00)
} }
if [[ $# != 1 ]] ; then mkconflocal () {
echo "usage : $0 <dns-zone>" if [[ "${slave}" != 1 ]] ; then
exit 1
fi
zone=$1
initialize
echo "Generation fichier named.conf.local ..." echo "Generation fichier named.conf.local ..."
cat <<EOT > "named.conf.local" cat <<EOT > "named.conf.local"
# fichier zone ${zone} # fichier zone ${zone}
# le $(date) # le $(date)
@ -52,11 +54,31 @@ zone "${zone}" {
zone "${zonerev}" { zone "${zonerev}" {
type master; type master;
file "/etc/bind/db.${zone}.rev"; # zone inverse };
EOT
else
echo "Generation fichier named.conf.local ..."
cat <<EOT > "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 EOT
fi
}
mkzdirrect () {
# fichier de zone directe # fichier de zone directe
echo "Generation fichier de zone directe db.${zone} ..." echo "Generation fichier de zone directe db.${zone} ..."
cat <<EOT > "db.${zone}" cat <<EOT > "db.${zone}"
@ -86,7 +108,9 @@ ${nsname2} IN A ${nsip2}
IN AAAA 2001:DB8:BEEF:100::22 IN AAAA 2001:DB8:BEEF:100::22
EOT EOT
}
mkzreverse () {
echo "Generation fichier de zone inverse db.${zone}.rev ..." echo "Generation fichier de zone inverse db.${zone}.rev ..."
cat <<EOT > "db.${zone}.rev" cat <<EOT > "db.${zone}.rev"
; fichier zone inverse ${zone} ; fichier zone inverse ${zone}
@ -109,6 +133,9 @@ ${nsiprev2} IN PTR ${nsname2}.${zone}.
EOT EOT
}
mkresolv () {
echo "Generation fichier /etc/resolv.conf ..." echo "Generation fichier /etc/resolv.conf ..."
cat <<EOT > "/etc/resolv.conf" cat <<EOT > "/etc/resolv.conf"
@ -118,5 +145,99 @@ domain ${zone}
search ${zone} search ${zone}
nameserver 127.0.0.1 nameserver 127.0.0.1
EOT EOT
}
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF # remove the space between << and EOF, this is due to web plugin issue
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value zone [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-s, --slave Some flag description
-p, --param Some param description
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
msg() {
echo >&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