ACC SHELL

Path : /usr/share/bind/
File Upload :
Current File : //usr/share/bind/createNamedConfInclude

#!/bin/sh
#
# Copyright (c) 2003 SuSE Linux AG Nuernberg, Germany.
# All rights reserved.
#
# Authors: Lars Mueller <lmuelle@suse.de>
#


#
# check if we are started as root
# only one of UID and USER must be set correctly
#
if test "$UID" != 0 -a "$USER" != root; then
    echo "You must be root to start $0."
    exit 1
fi

BASENAME=$( basename $0)
NAMED_CHECKCONF_BIN="/usr/sbin/named-checkconf"

function warnMessage()
{
	tput bold
	echo -en "Warning: "
	tput sgr0
	echo -e $1
}

function errorMessage()
{
	tput bold
	echo -en "Error: "
	tput sgr0
	echo -e $1
}

#
# load special SuSEconfig functions
#
if [ ! -f "/lib/YaST/SuSEconfig.functions" ]; then
	errorMessage 'Can not find /lib/YaST/SuSEconfig.functions!\nThis should not happen.  Exiting.'
	exit 1
fi
MD5DIR="/var/adm/SuSEconfig/md5"
. /lib/YaST/SuSEconfig.functions

#
# check for named settings
#
if [ ! -f /etc/sysconfig/named ]; then
	errorMessage "No /etc/sysconfig/named found!  Exiting."
	exit 1
fi
. /etc/sysconfig/named

# Check for NAMED_CONF_META_INCLUDE_FILE or set it to our default if we
# make use of this script.
if [ -z "${NAMED_CONF_META_INCLUDE_FILE}" ]; then
	for script in ${NAMED_INITIALIZE_SCRIPTS}; do
		if [ "${script}" = "${BASENAME}" -o \
		"${script}" = "/usr/share/bind/createNamedConfInclude" ]; then
			NAMED_CONF_META_INCLUDE_FILE="/etc/named.conf.include"
			break
		fi
	done
	# If NAMED_CONF_META_INCLUDE_FILE is still empty skip silent.
	test -z "${NAMED_CONF_META_INCLUDE_FILE}" && exit 0
fi

NEW_NAMEDCONFINCLUDE_FILE="${NAMED_CONF_META_INCLUDE_FILE}.SuSEconfig"
if [ -f "${NAMED_CONF_META_INCLUDE_FILE}" -a \
	! -f "${NEW_NAMEDCONFINCLUDE_FILE}" ]; then
	touch "${NEW_NAMEDCONFINCLUDE_FILE}"
	chmod --reference="${NAMED_CONF_META_INCLUDE_FILE}" "${NEW_NAMEDCONFINCLUDE_FILE}"
	chown --reference="${NAMED_CONF_META_INCLUDE_FILE}" "${NEW_NAMEDCONFINCLUDE_FILE}"
fi
#
# find the next unused file descriptor
#
declare -i fd=3
while [ -t ${fd} ]; do
	fd=$(( ${fd} + 1 ))
done
eval "exec ${fd}> \"${NEW_NAMEDCONFINCLUDE_FILE}\""

DATE=$( LANG=POSIX date)
cat << EOF >&${fd}
#
# This file is autogenerated by /usr/share/bind/createNamedConfInclude
# on ${DATE}.  Don't edit it manually.
#
# Add additional configuration files which should be added to /etc/named.conf
# by this mechanism to NAMED_CONF_INCLUDE_FILES in /etc/sysconfig/named.  This
# is possible with the YaST sysconfig or any other editor.
#
# See /usr/share/doc/packages/bind/README.SUSE section
# createNamedConfInclude for more details.
#

EOF

INCLUDE_LINES=$( grep -e '^[[:space:]]*include' "/etc/named.conf" | cut -f 2 -d '"')
includeUsed="no"
for file in ${NAMED_CONF_INCLUDE_FILES}; do
	# prepend the default include directory if the filename is relative
	test "${file:0:1}" = "/" || file="/etc/named.d/${file}"
	if [ ! -f "${file}" ]; then
		warnMessage "File, ${file} to include not found!  Skipping."
		continue
#	elif ! ${NAMED_CHECKCONF_BIN} "${file}"; then
#		warnMessage "${file} is no valid named configuration part.  Skipping."
#		continue
	fi
	# FIXME Is the file readable by user 'named'?
	echo "include \"${file}\";" >&${fd}
	includeUsed="yes"
done
eval "exec ${fd}<&-"

#
# only replace "${NAMED_CONF_META_INCLUDE_FILE}" if we need it
#
if [ "${includeUsed}" = 'yes' ]; then
	test ! -f "${NAMED_CONF_META_INCLUDE_FILE}" && SET_PERMISSIONS="yes"
	VERBOSE="false"
	check_md5_and_move "${NAMED_CONF_META_INCLUDE_FILE}"
else
	rm -f "${NEW_NAMEDCONFINCLUDE_FILE}"
	touch "${NAMED_CONF_META_INCLUDE_FILE}"
	SET_PERMISSIONS="yes"
fi

if [ "yes" = "${SET_PERMISSIONS}" ]; then
	chown root:named "${NAMED_CONF_META_INCLUDE_FILE}"
	chmod 0644 "${NAMED_CONF_META_INCLUDE_FILE}"
fi

exit 0


ACC SHELL 2018