3 # $NetBSD: chkconfig.sh,v 1.2 2003/01/04 23:43:04 wiz Exp $
5 # Copyright (c) 2001 Zembu Labs, Inc.
8 # Author: Dan Mercer <dmercer@zembu.com>
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. All advertising materials mentioning features or use of this software
19 # must display the following acknowledgement:
20 # This product includes software developed by Zembu Labs, Inc.
21 # 4. Neither the name of Zembu Labs nor the names of its employees may
22 # be used to endorse or promote products derived from this software
23 # without specific prior written permission.
25 # THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
26 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
27 # RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
28 # CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 # chkconfig - configuration state checker
39 # This script is written to work with the NetBSD (1.5 and later) rc system.
40 # It is meant to provide the same functionality as found in IRIX chkconfig.
41 # This script has nothing to do with the abortion produced by RedHat that
44 # chkconfig makes use of the '-k' flag to rcorder. It will not work
45 # with versions of rcorder that do not support '-k'.
47 # Dan Mercer <dmercer@zembu.com>
53 # output $1 with 'on' or 'off' based on the return of checkyesno()
54 # Returns 0 for yes, 1 for no.
57 load_rc_config
${_name}
58 if checkyesno
${_name}; then
59 printf "\t%-15s\t\ton\n" ${_name}
62 printf "\t%-15s\t\toff\n" ${_name}
69 # Returns true if an executable named $1 exists
73 fqp
="/etc/rc.d/${_name}"
74 if [ -x "${fqp}" ]; then
77 usage
"${fqp} does not exist"
84 # Returns true if $1 appears to be a valid NetBSD
88 fqp
="/etc/rc.d/${_name}"
89 if ! grep -s '. /etc/rc.subr' ${fqp} > /dev
/null
2>&1; then
90 usage
"${fqp} does not appear to be a NetBSD rc script"
92 elif ! grep -s '# KEYWORD:' ${fqp} > /dev
/null
2>&1; then
93 if [ ${force} -ne 1 ]; then
94 usage
"${fqp} doesn't contain a KEYWORD directive. Use -f"
99 is_chkconfig
=`grep -s '# KEYWORD:' ${fqp}|grep -s ${KEYWORD}`
100 if [ "${is_chkconfig}" ]; then
103 if [ ${force} -ne 1 ]; then
104 usage
"${fqp} not under chkconfig control. Use -f"
115 # Adds the 'chkconfig' keyword to $1 if it is not
116 # there already, returning a 0. Otherwise exits
117 # with an appropriate usage error.
120 fqp
="/etc/rc.d/${_name}"
121 if is_valid
${_name}; then
122 usage
"${fqp} is already managed by chkconfig."
124 echo '# KEYWORD: chkconfig' >> ${fqp}
131 # Print a (hopefully) useful usage message and exit nonzero.
132 # We don't make use of err() from rc.subr because we
133 # don't want error messages going to syslog.
136 echo "Error: ${_err}"
137 echo "usage: $0 flag"
138 echo " $0 flag [ on | off ] "
139 echo " $0 [-f] flag [ on | off ]"
146 if [ ${force} -eq 1 ]; then
150 if is_valid
${_name}; then
151 output
="/etc/rc.conf.d/${_name}"
152 echo "${_name}=YES" > "${output}"
160 if [ ${force} -eq 1 ]; then
164 if is_valid
${_name}; then
165 output
="/etc/rc.conf.d/${_name}"
166 echo "${_name}=NO" > "${output}"
190 usage
"Invalid argument ${i}"
202 if [ ${force} -eq 1 ]; then
203 usage
"-f flag requires 'on' or 'off'"
205 if [ ! ${rcfile} ]; then
206 printf "\tService\t\t\tState\n"
207 printf "\t=======\t\t\t=====\n"
208 for i
in `(cd /etc/rc.d; rcorder -k ${KEYWORD} *)`; do
212 if exists
${rcfile} && is_valid
${rcfile}; then
216 usage
"Invalid rcfile: ${rcfile}"
222 if exists
${rcfile}; then
227 if exists
${rcfile}; then