| 4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# nis.sh: dhclient-script plugin for NIS settings,
|
|
|
4 |
# place in /etc/dhcp/dhclient.d and 'chmod +x nis.sh' to enable
|
|
|
5 |
#
|
|
|
6 |
# Copyright (C) 2008 Red Hat, Inc.
|
|
|
7 |
#
|
|
|
8 |
# This program is free software; you can redistribute it and/or modify
|
|
|
9 |
# it under the terms of the GNU General Public License as published by
|
|
|
10 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
11 |
# (at your option) any later version.
|
|
|
12 |
#
|
|
|
13 |
# This program is distributed in the hope that it will be useful,
|
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
# GNU General Public License for more details.
|
|
|
17 |
#
|
|
|
18 |
# You should have received a copy of the GNU General Public License
|
|
|
19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
#
|
|
|
21 |
# Author(s): David Cantrell <dcantrell@redhat.com>
|
|
|
22 |
#
|
|
|
23 |
|
|
|
24 |
CONF=/etc/yp.conf
|
|
|
25 |
|
|
|
26 |
fixContext() {
|
|
|
27 |
if [ -x /sbin/restorecon ]; then
|
|
|
28 |
/sbin/restorecon ${1} >/dev/null 2>&1
|
|
|
29 |
fi
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
save_config_file() {
|
|
|
33 |
origfile="${1}"
|
|
|
34 |
savefile="${SAVEDIR}/${origfile##*/}.predhclient.${interface}"
|
|
|
35 |
|
|
|
36 |
if [ ! -d ${SAVEDIR} ]; then
|
|
|
37 |
mkdir -p ${SAVEDIR}
|
|
|
38 |
fi
|
|
|
39 |
|
|
|
40 |
if [ -e ${origfile} ]; then
|
|
|
41 |
mv ${origfile} ${savefile}
|
|
|
42 |
else
|
|
|
43 |
echo > ${savefile}
|
|
|
44 |
fi
|
|
|
45 |
|
|
|
46 |
fixContext ${savefile}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
nis_config() {
|
|
|
50 |
if [ ! "${PEERNIS}" = "no" ]; then
|
|
|
51 |
if [ -n "${new_nis_domain}" ]; then
|
|
|
52 |
domainname "${new_nis_domain}"
|
|
|
53 |
save_config_file ${CONF}
|
|
|
54 |
let contents=0
|
|
|
55 |
echo '# generated by /sbin/dhclient-script' > ${CONF}
|
|
|
56 |
|
|
|
57 |
if [ -n "${new_nis_servers}" ]; then
|
|
|
58 |
for i in ${new_nis_servers} ; do
|
|
|
59 |
echo "domain ${new_nis_domain} server ${i}" >> ${CONF}
|
|
|
60 |
let contents=contents+1
|
|
|
61 |
done
|
|
|
62 |
else
|
|
|
63 |
echo "domain ${new_nis_domain} broadcast" >> ${CONF}
|
|
|
64 |
let contents=contents+1
|
|
|
65 |
fi
|
|
|
66 |
|
|
|
67 |
if [ ${contents} -gt 0 ]; then
|
|
|
68 |
if [ -x /etc/rc.d/init.d/ypbind ] &&
|
|
|
69 |
[ -r /var/run/ypbind.pid ]; then
|
|
|
70 |
service ypbind restart >/dev/null 2>&1
|
|
|
71 |
fi
|
|
|
72 |
fi
|
|
|
73 |
elif [ -n "${new_nis_servers}" ]; then
|
|
|
74 |
save_config_file ${CONF}
|
|
|
75 |
echo '# generated by /sbin/dhclient-script' > ${CONF}
|
|
|
76 |
let contents=0
|
|
|
77 |
|
|
|
78 |
for i in ${new_nis_servers} ; do
|
|
|
79 |
echo "ypserver ${i}" >> ${CONF}
|
|
|
80 |
let contents=contents+1
|
|
|
81 |
done
|
|
|
82 |
|
|
|
83 |
if [ $contents -gt 0 ]; then
|
|
|
84 |
if [ -x /etc/rc.d/init.d/ypbind ] &&
|
|
|
85 |
[ -r /var/run/ypbind.pid ]; then
|
|
|
86 |
service ypbind restart >/dev/null 2>&1
|
|
|
87 |
fi
|
|
|
88 |
fi
|
|
|
89 |
fi
|
|
|
90 |
fi
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
nis_restore() {
|
|
|
94 |
if [ ! "${PEERNIS}" = "no" ]; then
|
|
|
95 |
if [ -f ${SAVEDIR}/${CONF}.predhclient.${interface} ]; then
|
|
|
96 |
rm -f ${CONF}
|
|
|
97 |
mv -f ${SAVEDIR}/${CONF}.predhclient.${interface} ${CONF}
|
|
|
98 |
fixContext /etc/yp.conf
|
|
|
99 |
if [ -x /etc/rc.d/init.d/ypbind ] && [ -r /var/run/ypbind.pid ]; then
|
|
|
100 |
service ypbind restart >/dev/null 2>&1
|
|
|
101 |
fi
|
|
|
102 |
fi
|
|
|
103 |
fi
|
|
|
104 |
}
|