Subversion Repositories configs

Rev

Rev 34 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
CONF=/etc/yp.conf
34 - 24
SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface}
4 - 25
 
34 - 26
fix_context() {
4 - 27
    if [ -x /sbin/restorecon ]; then
28
        /sbin/restorecon ${1} >/dev/null 2>&1
29
    fi
30
}
31
 
32
save_config_file() {
33
    if [ ! -d ${SAVEDIR} ]; then
34
        mkdir -p ${SAVEDIR}
35
    fi
36
 
34 - 37
    if [ -e ${CONF} ]; then
38
        # cp+rm instead of mv: preserve SELinux context
39
        # rhbz#509240
40
        # Do not rely on restorecon.
41
        cp -c ${CONF} ${SAVECONF}
42
        rm ${CONF}
4 - 43
    else
34 - 44
        echo > ${SAVECONF}
45
        # Try restorecon
46
        fix_context ${SAVECONF}
4 - 47
    fi
48
}
49
 
50
nis_config() {
51
    if [ ! "${PEERNIS}" = "no" ]; then
52
        if [ -n "${new_nis_domain}" ]; then
53
            domainname "${new_nis_domain}"
34 - 54
            save_config_file
4 - 55
            echo '# generated by /sbin/dhclient-script' > ${CONF}
34 - 56
            fix_context ${CONF}
4 - 57
 
58
            if [ -n "${new_nis_servers}" ]; then
59
                for i in ${new_nis_servers} ; do
60
                    echo "domain ${new_nis_domain} server ${i}" >> ${CONF}
61
                done
62
            else
63
                echo "domain ${new_nis_domain} broadcast" >> ${CONF}
64
            fi
65
 
66
        elif [ -n "${new_nis_servers}" ]; then
34 - 67
            save_config_file
4 - 68
            echo '# generated by /sbin/dhclient-script' > ${CONF}
34 - 69
            fix_context ${CONF}
4 - 70
 
71
            for i in ${new_nis_servers} ; do
72
                echo "ypserver ${i}" >> ${CONF}
73
            done
74
 
75
        fi
58 - 76
 
77
        # domainname or servers changed, restart ypbind
78
        if [ "${old_nis_domain}" != "${new_nis_domain}" ] \
79
            || [ "${old_nis_servers}" != "${new_nis_servers}" ]
80
        then
81
            service ypbind condrestart >/dev/null 2>&1
82
        fi
4 - 83
    fi
84
}
85
 
86
nis_restore() {
87
    if [ ! "${PEERNIS}" = "no" ]; then
34 - 88
        if [ -f ${SAVECONF} ]; then
4 - 89
            rm -f ${CONF}
34 - 90
            # cp+rm instead of mv: preserve SELinux context
91
            # rhbz#509240
92
            cp -c ${SAVECONF} ${CONF}
93
            rm ${SAVECONF}
94
            fix_context ${CONF} # Restorecon again to be sure.
95
            service ypbind condrestart >/dev/null 2>&1
4 - 96
        fi
97
    fi
98
}
34 - 99
 
100
# Local Variables:
101
# indent-tabs-mode: nil
102
# sh-basic-offset: 4
103
# show-trailing-whitespace: t
104
# End: