#!/bin/bash # Copyright (c) 2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # void system_depend(void) # # Sets up the dependancies for the module system_depend() { after interface before dhcp variables dns_servers dns_domain dns_options dns_search dns_sortlist \ ntp_servers nis_domain nis_servers } system_dns_extra() { local iface="$1" ifvar="$(bash_variable "$1")" out="$2" x sortlist local -a options x="dns_options_${ifvar}[@]" options=( "${!x}" ) [[ -z ${options} ]] && options=( "${dns_options[@]}" ) for x in "${options[@]}" ; do echo "options ${x}" >> "${out}" done sortlist="dns_sortlist_${ifvar}" [[ -z ${!sortlist} ]] && sortlist="dns_sortlist" [[ -n ${!sortlist} ]] && echo "sortlist ${!sortlist}" >> "${out}" } system_dns() { local iface="$1" ifvar="$(bash_variable "$1")" x domain search local conffile="${statedir}/${iface}/resolv.conf" tmpfile="${conffile}.$$" local -a servers servers="dns_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="dns_servers[@]" servers="${!servers}" domain="dns_domain_${ifvar}" [[ -z ${!domain} ]] && domain="dns_domain" domain="${!domain}" search="dns_search_${ifvar}" [[ -z ${!search} ]] && search="dns_search" search="${!search}" [[ -z ${servers} && -z ${domain} && -z ${search} ]] && return 0 echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" chmod 644 "${tmpfile}" if [[ -n ${domain} ]] ; then # Strip leading and trailing spaces domain="${domain# *}" domain="${domain%* }" if [[ ${domain} == *" "* ]] ; then [[ -z ${search} ]] && search="${domain}" domain="${domain%% *}" fi echo "domain ${domain}" >> "${tmpfile}" fi for x in ${servers} ; do echo "nameserver ${x}" >> "${tmpfile}" done [[ -n ${search} ]] && echo "search ${search}" >> "${tmpfile}" system_dns_extra "${iface}" "${tmpfile}" mv "${tmpfile}" "${conffile}" } system_ntp() { local iface="$1" ifvar="$(bash_variable "$1")" x local conffile="${statedir}/${iface}/ntp.conf" tmpfile="${conffile}.$$" local -a servers servers="ntp_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="ntp_servers[@]" [[ -z ${!servers} ]] && return 0 echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" chmod 644 "${tmpfile}" echo "restrict default noquery notrust nomodify" >> "${tmpfile}" echo "restrict 127.0.0.1" >> "${tmpfile}" for x in ${!servers} ; do echo "restrict ${x} nomodify notrap noquery" >> "${tmpfile}" echo "server ${x}" >> "${tmpfile}" done echo "driftfile /var/lib/ntp/ntp.drift" >> "${tmpfile}" echo "logfile /var/log/ntp.log" >> "${tmpfile}" mv "${tmpfile}" "${conffile}" } system_nis() { local iface="$1" ifvar="$(bash_variable "$1")" domain x local conffile="${statedir}/${iface}/yp.conf" tmpfile="${conffile}.$$" local -a servers servers="nis_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="nis_servers[@]" domain="nis_domain_${ifvar}" [[ -z ${!domain} ]] && domain="nis_domain" [[ -z ${!servers} && -z ${!domain} ]] && return 0 echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" chmod 644 "${tmpfile}" if [[ -n ${!domain} ]] ; then hostname -y "${!domain}" if [[ -n ${!servers} ]] ; then for x in ${!servers} ; do echo "domain ${!domain} server ${x}" >> "${tmpfile}" done else echo "domain ${!domain} broadcast" >> "${tmpfile}" fi else for x in ${!servers} ; do echo "ypserver ${x}" >> "${tmpfile}" done fi mv "${tmpfile}" "${conffile}" } # bool system_post_start(char *iface) # # Configures the host system for dns, ntp and nis information # Always returns 0 system_pre_start() { local iface="$1" system_dns "${iface}" system_ntp "${iface}" system_nis "${iface}" return 0 } # vim:ts=4