#!/bin/sh # is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu. # Using required /etc/lsb-release file, instead of optional lsb_release command. is_lsb_ubuntu () { awk ' (match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line id = substr($0, RLENGTH + 1) # Save its value } END { # Examine last DISTRIB_ID value to see if Ubuntu indicated if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) { exit 0 # Ubuntu } exit 1 # Not Ubuntu } ' /etc/lsb-release >/dev/null 2>&1 # Routine exit status is exit status of the last command -- the awk script. # # Note: if /etc/lsb-release does not exist, the exit status indicates # failure (not Ubuntu), which is the correct outcome. } DIRECTORY=/var/named # check for SLES grep -s -q sles /etc/os-release IS_SLES=$? if [ -f /etc/SuSE-release ] || [ $IS_SLES -eq 0 ]; then DIRECTORY=/var/lib/named fi FILE=/etc/named.conf if ( is_lsb_ubuntu ); then FILE=/etc/bind/named.conf fi #unalias cp if [ -f $FILE ]; then cp -f $FILE ${FILE}.ORIG fi if [ ! -d $DIRECTORY ]; then mkdir $DIRECTORY fi echo "options { directory \"$DIRECTORY\"; dump-file \"$DIRECTORY/data/cache_dump.db\"; statistics-file \"$DIRECTORY/data/named_stats.txt\"; memstatistics-file \"$DIRECTORY/data/named_mem_stats.txt\"; recursion yes; forward only; forwarders {" >$FILE for i in $(grep "^nameserver" /etc/resolv.conf | awk '{print $2}') do echo " $i;" done >>$FILE echo " };" >>$FILE # Natural version compare against version of bind. version_ge() { if [ -z "$1" ] || [ -z "$2" ]; then return 1 fi # "sort --version-sort" sorts versions in ascending order. [ "$(printf '%s\n' "$1" "$2" | sort --version-sort | tail -n1)" = "$1" ] } BIND_VERSION=$(/usr/sbin/named -v | cut -d" " -f2 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1) if version_ge "$BIND_VERSION" "9.16.6"; then if ! version_ge "$BIND_VERSION" "9.18.0"; then echo " dnssec-enable no;" >>$FILE fi echo " dnssec-validation no;" >>$FILE fi echo "};" >>$FILE