Blame SOURCES/nis.sh

6c4d24
#!/bin/bash
6c4d24
#
6c4d24
# nis.sh: dhclient-script plugin for NIS settings,
6c4d24
#         place in /etc/dhcp/dhclient.d and 'chmod +x nis.sh' to enable
6c4d24
#
6c4d24
# Copyright (C) 2008 Red Hat, Inc.
6c4d24
#
6c4d24
# This program is free software; you can redistribute it and/or modify
6c4d24
# it under the terms of the GNU General Public License as published by
6c4d24
# the Free Software Foundation; either version 2 of the License, or
6c4d24
# (at your option) any later version.
6c4d24
#
6c4d24
# This program is distributed in the hope that it will be useful,
6c4d24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6c4d24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6c4d24
# GNU General Public License for more details.
6c4d24
#
6c4d24
# You should have received a copy of the GNU General Public License
6c4d24
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
6c4d24
#
6c4d24
# Author(s): David Cantrell <dcantrell@redhat.com>
6c4d24
6c4d24
CONF=/etc/yp.conf
6c4d24
SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface}
6c4d24
6c4d24
fix_context() {
6c4d24
    if [ -x /sbin/restorecon ]; then
6c4d24
        /sbin/restorecon ${1} >/dev/null 2>&1
6c4d24
    fi
6c4d24
}
6c4d24
6c4d24
save_config_file() {
6c4d24
    if [ ! -d ${SAVEDIR} ]; then
6c4d24
        mkdir -p ${SAVEDIR}
6c4d24
    fi
6c4d24
6c4d24
    if [ -e ${CONF} ]; then
6c4d24
        # cp+rm instead of mv: preserve SELinux context
6c4d24
        # rhbz#509240
6c4d24
        # Do not rely on restorecon.
6c4d24
        cp -c ${CONF} ${SAVECONF}
6c4d24
        rm ${CONF}
6c4d24
    else
6c4d24
        echo > ${SAVECONF}
6c4d24
        # Try restorecon
6c4d24
        fix_context ${SAVECONF}
6c4d24
    fi
6c4d24
}
6c4d24
6c4d24
nis_config() {
6c4d24
    if [ ! "${PEERNIS}" = "no" ]; then
6c4d24
        if [ -n "${new_nis_domain}" ]; then
6c4d24
            domainname "${new_nis_domain}"
6c4d24
            save_config_file
6c4d24
            echo '# generated by /sbin/dhclient-script' > ${CONF}
6c4d24
            fix_context ${CONF}
6c4d24
6c4d24
            if [ -n "${new_nis_servers}" ]; then
6c4d24
                for i in ${new_nis_servers} ; do
6c4d24
                    echo "domain ${new_nis_domain} server ${i}" >> ${CONF}
6c4d24
                done
6c4d24
            else
6c4d24
                echo "domain ${new_nis_domain} broadcast" >> ${CONF}
6c4d24
            fi
6c4d24
6c4d24
        elif [ -n "${new_nis_servers}" ]; then
6c4d24
            save_config_file
6c4d24
            echo '# generated by /sbin/dhclient-script' > ${CONF}
6c4d24
            fix_context ${CONF}
6c4d24
6c4d24
            for i in ${new_nis_servers} ; do
6c4d24
                echo "ypserver ${i}" >> ${CONF}
6c4d24
            done
6c4d24
6c4d24
        fi
6c4d24
6c4d24
		# dimainname or servers changed, restart ypbind
6c4d24
		if [ "${old_nis_domain}" != "${new_nis_domain}" ] \
6c4d24
			|| [ "${old_nis_servers}" != "${new_nis_servers}" ] 
6c4d24
		then
6c4d24
                service ypbind condrestart >/dev/null 2>&1
6c4d24
		fi
6c4d24
    fi
6c4d24
}
6c4d24
6c4d24
nis_restore() {
6c4d24
    if [ ! "${PEERNIS}" = "no" ]; then
6c4d24
        if [ -f ${SAVECONF} ]; then
6c4d24
            rm -f ${CONF}
6c4d24
            # cp+rm instead of mv: preserve SELinux context
6c4d24
            # rhbz#509240
6c4d24
            cp -c ${SAVECONF} ${CONF}
6c4d24
            rm ${SAVECONF}
6c4d24
            fix_context ${CONF} # Restorecon again to be sure.
6c4d24
            service ypbind condrestart >/dev/null 2>&1
6c4d24
        fi
6c4d24
    fi
6c4d24
}
6c4d24
6c4d24
# Local Variables:
6c4d24
# indent-tabs-mode: nil
6c4d24
# sh-basic-offset: 4
6c4d24
# show-trailing-whitespace: t
6c4d24
# End: