Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash## nis.sh: dhclient-script plugin for NIS settings,# place in /etc/dhcp/dhclient.d and 'chmod +x nis.sh' to enable## Copyright (C) 2008 Red Hat, Inc.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.## Author(s): David Cantrell <dcantrell@redhat.com>#CONF=/etc/yp.conffixContext() {if [ -x /sbin/restorecon ]; then/sbin/restorecon ${1} >/dev/null 2>&1fi}save_config_file() {origfile="${1}"savefile="${SAVEDIR}/${origfile##*/}.predhclient.${interface}"if [ ! -d ${SAVEDIR} ]; thenmkdir -p ${SAVEDIR}fiif [ -e ${origfile} ]; thenmv ${origfile} ${savefile}elseecho > ${savefile}fifixContext ${savefile}}nis_config() {if [ ! "${PEERNIS}" = "no" ]; thenif [ -n "${new_nis_domain}" ]; thendomainname "${new_nis_domain}"save_config_file ${CONF}let contents=0echo '# generated by /sbin/dhclient-script' > ${CONF}if [ -n "${new_nis_servers}" ]; thenfor i in ${new_nis_servers} ; doecho "domain ${new_nis_domain} server ${i}" >> ${CONF}let contents=contents+1doneelseecho "domain ${new_nis_domain} broadcast" >> ${CONF}let contents=contents+1fiif [ ${contents} -gt 0 ]; thenif [ -x /etc/rc.d/init.d/ypbind ] &&[ -r /var/run/ypbind.pid ]; thenservice ypbind restart >/dev/null 2>&1fifielif [ -n "${new_nis_servers}" ]; thensave_config_file ${CONF}echo '# generated by /sbin/dhclient-script' > ${CONF}let contents=0for i in ${new_nis_servers} ; doecho "ypserver ${i}" >> ${CONF}let contents=contents+1doneif [ $contents -gt 0 ]; thenif [ -x /etc/rc.d/init.d/ypbind ] &&[ -r /var/run/ypbind.pid ]; thenservice ypbind restart >/dev/null 2>&1fifififi}nis_restore() {if [ ! "${PEERNIS}" = "no" ]; thenif [ -f ${SAVEDIR}/${CONF}.predhclient.${interface} ]; thenrm -f ${CONF}mv -f ${SAVEDIR}/${CONF}.predhclient.${interface} ${CONF}fixContext /etc/yp.confif [ -x /etc/rc.d/init.d/ypbind ] && [ -r /var/run/ypbind.pid ]; thenservice ypbind restart >/dev/null 2>&1fififi}