Subversion Repositories configs

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 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
33 - 24
SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface}
3 - 25
 
33 - 26
fix_context() {
3 - 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
 
33 - 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}
3 - 43
    else
33 - 44
        echo > ${SAVECONF}
45
        # Try restorecon
46
        fix_context ${SAVECONF}
3 - 47
    fi
48
}
49
 
50
nis_config() {
51
    if [ ! "${PEERNIS}" = "no" ]; then
52
        if [ -n "${new_nis_domain}" ]; then
53
            domainname "${new_nis_domain}"
33 - 54
            save_config_file
3 - 55
            let contents=0
56
            echo '# generated by /sbin/dhclient-script' > ${CONF}
33 - 57
            fix_context ${CONF}
3 - 58
 
59
            if [ -n "${new_nis_servers}" ]; then
60
                for i in ${new_nis_servers} ; do
61
                    echo "domain ${new_nis_domain} server ${i}" >> ${CONF}
62
                    let contents=contents+1
63
                done
64
            else
65
                echo "domain ${new_nis_domain} broadcast" >> ${CONF}
66
                let contents=contents+1
67
            fi
68
 
69
            if [ ${contents} -gt 0 ]; then
33 - 70
                service ypbind condrestart >/dev/null 2>&1
3 - 71
            fi
72
        elif [ -n "${new_nis_servers}" ]; then
33 - 73
            save_config_file
3 - 74
            echo '# generated by /sbin/dhclient-script' > ${CONF}
33 - 75
            fix_context ${CONF}
3 - 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
33 - 84
                service ypbind condrestart >/dev/null 2>&1
3 - 85
            fi
86
        fi
87
    fi
88
}
89
 
90
nis_restore() {
91
    if [ ! "${PEERNIS}" = "no" ]; then
33 - 92
        if [ -f ${SAVECONF} ]; then
3 - 93
            rm -f ${CONF}
33 - 94
            # cp+rm instead of mv: preserve SELinux context
95
            # rhbz#509240
96
            cp -c ${SAVECONF} ${CONF}
97
            rm ${SAVECONF}
98
            fix_context ${CONF} # Restorecon again to be sure.
99
            service ypbind condrestart >/dev/null 2>&1
3 - 100
        fi
101
    fi
102
}
33 - 103
 
104
# Local Variables:
105
# indent-tabs-mode: nil
106
# sh-basic-offset: 4
107
# show-trailing-whitespace: t
108
# End: