Blame SOURCES/nis.sh

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