2009-02-26 14:57:09 +00:00
|
|
|
#!/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.conf
|
2010-05-19 14:32:07 +00:00
|
|
|
SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface}
|
2009-02-26 14:57:09 +00:00
|
|
|
|
2010-05-19 14:32:07 +00:00
|
|
|
fix_context() {
|
2009-03-18 12:19:32 +00:00
|
|
|
if [ -x /sbin/restorecon ]; then
|
|
|
|
/sbin/restorecon ${1} >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-02-26 14:57:09 +00:00
|
|
|
save_config_file() {
|
|
|
|
if [ ! -d ${SAVEDIR} ]; then
|
|
|
|
mkdir -p ${SAVEDIR}
|
|
|
|
fi
|
|
|
|
|
2010-05-19 14:32:07 +00:00
|
|
|
if [ -e ${CONF} ]; then
|
|
|
|
# cp+rm instead of mv: preserve SELinux context
|
|
|
|
# rhbz#509240
|
|
|
|
# Do not rely on restorecon.
|
|
|
|
cp -c ${CONF} ${SAVECONF}
|
|
|
|
rm ${CONF}
|
2009-02-26 14:57:09 +00:00
|
|
|
else
|
2010-05-19 14:32:07 +00:00
|
|
|
echo > ${SAVECONF}
|
|
|
|
# Try restorecon
|
|
|
|
fix_context ${SAVECONF}
|
2009-02-26 14:57:09 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
nis_config() {
|
|
|
|
if [ ! "${PEERNIS}" = "no" ]; then
|
|
|
|
if [ -n "${new_nis_domain}" ]; then
|
|
|
|
domainname "${new_nis_domain}"
|
2010-05-19 14:32:07 +00:00
|
|
|
save_config_file
|
2009-02-26 14:57:09 +00:00
|
|
|
let contents=0
|
|
|
|
echo '# generated by /sbin/dhclient-script' > ${CONF}
|
2010-05-19 14:32:07 +00:00
|
|
|
fix_context ${CONF}
|
2009-02-26 14:57:09 +00:00
|
|
|
|
|
|
|
if [ -n "${new_nis_servers}" ]; then
|
|
|
|
for i in ${new_nis_servers} ; do
|
|
|
|
echo "domain ${new_nis_domain} server ${i}" >> ${CONF}
|
|
|
|
let contents=contents+1
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "domain ${new_nis_domain} broadcast" >> ${CONF}
|
|
|
|
let contents=contents+1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${contents} -gt 0 ]; then
|
2010-05-19 14:32:07 +00:00
|
|
|
service ypbind condrestart >/dev/null 2>&1
|
2009-02-26 14:57:09 +00:00
|
|
|
fi
|
|
|
|
elif [ -n "${new_nis_servers}" ]; then
|
2010-05-19 14:32:07 +00:00
|
|
|
save_config_file
|
2009-02-26 14:57:09 +00:00
|
|
|
echo '# generated by /sbin/dhclient-script' > ${CONF}
|
2010-05-19 14:32:07 +00:00
|
|
|
fix_context ${CONF}
|
2009-02-26 14:57:09 +00:00
|
|
|
let contents=0
|
|
|
|
|
|
|
|
for i in ${new_nis_servers} ; do
|
|
|
|
echo "ypserver ${i}" >> ${CONF}
|
|
|
|
let contents=contents+1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $contents -gt 0 ]; then
|
2010-05-19 14:32:07 +00:00
|
|
|
service ypbind condrestart >/dev/null 2>&1
|
2009-02-26 14:57:09 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
nis_restore() {
|
|
|
|
if [ ! "${PEERNIS}" = "no" ]; then
|
2010-05-19 14:32:07 +00:00
|
|
|
if [ -f ${SAVECONF} ]; then
|
2009-02-26 14:57:09 +00:00
|
|
|
rm -f ${CONF}
|
2010-05-19 14:32:07 +00:00
|
|
|
# cp+rm instead of mv: preserve SELinux context
|
|
|
|
# rhbz#509240
|
|
|
|
cp -c ${SAVECONF} ${CONF}
|
|
|
|
rm ${SAVECONF}
|
|
|
|
fix_context ${CONF} # Restorecon again to be sure.
|
|
|
|
service ypbind condrestart >/dev/null 2>&1
|
2009-02-26 14:57:09 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2010-05-19 14:32:07 +00:00
|
|
|
|
|
|
|
# Local Variables:
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# sh-basic-offset: 4
|
|
|
|
# show-trailing-whitespace: t
|
|
|
|
# End:
|