diff options
Diffstat (limited to 'net-scripts/net.modules.d/system.sh')
-rw-r--r-- | net-scripts/net.modules.d/system.sh | 104 |
1 files changed, 37 insertions, 67 deletions
diff --git a/net-scripts/net.modules.d/system.sh b/net-scripts/net.modules.d/system.sh index 5d841d3..c32bb74 100644 --- a/net-scripts/net.modules.d/system.sh +++ b/net-scripts/net.modules.d/system.sh @@ -18,96 +18,66 @@ system_expose() { 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 + local iface="$1" ifvar="$(bash_variable "$1")" x= domain= search= + local buffer= + 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 + [[ -z ${!servers} && -z ${!domain} && -z ${!search} ]] && return 0 - for x in ${servers} ; do - echo "nameserver ${x}" >> "${tmpfile}" - done - - [[ -n ${search} ]] && echo "search ${search}" >> "${tmpfile}" + buffer="# Generated by net-scripts for interface ${iface}\n" + [[ -n ${!domain} ]] && buffer="${buffer}domain ${!domain}\n" + [[ -n ${!search} ]] && buffer="${buffer}search ${!search}\n" - system_dns_extra "${iface}" "${tmpfile}" + for x in ${!servers} ; do + buffer="${buffer}nameserver ${x}\n" + done - mv "${tmpfile}" "${conffile}" + # Support resolvconf if we have it. + if [[ -x /sbin/resolvconf ]] ; then + echo -e "${buffer}" | resolvconf -a "${iface}" + else + echo -e "${buffer}" > /etc/resolv.conf + chmod 644 /etc/resolv.conf + fi } system_ntp() { - local iface="$1" ifvar="$(bash_variable "$1")" x - local conffile="${statedir}/${iface}/ntp.conf" tmpfile="${conffile}.$$" - local -a servers + local iface="$1" ifvar="$(bash_variable "$1")" x= buffer= + 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}" + buffer="# Generated by net-scripts for interface ${iface}\n" + buffer="${buffer}restrict default noquery notrust nomodify\n" + buffer="${buffer}restrict 127.0.0.1\n" for x in ${!servers} ; do - echo "restrict ${x} nomodify notrap noquery" >> "${tmpfile}" - echo "server ${x}" >> "${tmpfile}" + buffer="${buffer}restrict ${x} nomodify notrap noquery\n" + buffer="${buffer}server ${x}\n" done - echo "driftfile /var/lib/ntp/ntp.drift" >> "${tmpfile}" - echo "logfile /var/log/ntp.log" >> "${tmpfile}" + buffer="${buffer}driftfile /var/lib/ntp/ntp.drift\n" + buffer="${buffer}logfile /var/log/ntp.log\n" - mv "${tmpfile}" "${conffile}" + echo -e "${buffer}" > /etc/ntp.conf + chmod 644 /etc/ntp.conf } system_nis() { - local iface="$1" ifvar="$(bash_variable "$1")" domain x - local conffile="${statedir}/${iface}/yp.conf" tmpfile="${conffile}.$$" - local -a servers + local iface="$1" ifvar="$(bash_variable "$1")" domain= x= buffer= + local -a servers=() servers="nis_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="nis_servers[@]" @@ -117,25 +87,25 @@ system_nis() { [[ -z ${!servers} && -z ${!domain} ]] && return 0 - echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" - chmod 644 "${tmpfile}" + buffer="# Generated by net-scripts for interface ${iface}\n" if [[ -n ${!domain} ]] ; then hostname -y "${!domain}" if [[ -n ${!servers} ]] ; then for x in ${!servers} ; do - echo "domain ${!domain} server ${x}" >> "${tmpfile}" + buffer="${buffer}domain ${!domain} server ${x}\n" done else - echo "domain ${!domain} broadcast" >> "${tmpfile}" + buffer="${buffer}domain ${!domain} broadcast\n" fi else for x in ${!servers} ; do - echo "ypserver ${x}" >> "${tmpfile}" + buffer="${buffer}ypserver ${x}\n" done fi - mv "${tmpfile}" "${conffile}" + echo -e "${buffer}" > /etc/yp.conf + chmod 644 /etc/yp.conf } # bool system_post_start(char *iface) @@ -152,4 +122,4 @@ system_pre_start() { return 0 } -# vim: set ft=sh ts=4 : +# vim: set ts=4 : |