Don't try to install bridge.4, install oldbridge.4
[dragonfly.git] / sbin / rcrun / rcrun.sh
CommitLineData
75326d0e
MD
1#!/bin/sh
2#
3# rcng command
4#
6d94234b 5# $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.4 2003/12/13 02:49:09 dillon Exp $
75326d0e
MD
6
7OS=`sysctl -n kern.ostype`
8
9dostart()
10{
11 arg=$1
12 shift
13
14 for i in $@; do
15 case X`varsym -s -q rcng_$i` in
16 Xrunning*)
17 echo "$i has already been started"
18 ;;
6d94234b
MD
19 Xconfigured*)
20 echo "$i has already been configured"
21 ;;
75326d0e
MD
22 *)
23 _return=0
24 for j in `rcorder -k $OS -o $i /etc/rc.d/*`; do
25 need=1
26 for k in `rcorder -p $j`; do
27 if [ $k = $i ]; then
28 need=0
29 else
30 state=`varsym -s -q rcng_$k`
31 case X$state in
6d94234b 32 Xrunning*|Xconfigured*|Xirrelevant*|Xdisabled*)
453375e0 33 ;;
75326d0e
MD
34 *)
35 echo "$i depends on $k, current state: $state"
36 _return=1
37 ;;
38 esac
39 fi
40 done
41 done
42 # $j contains the last dependancy, which we run
43 #
44 if [ X$j = X ]; then
45 echo "Unable to find keyword $i"
46 elif [ $_return = 0 ]; then
47 echo "Running $j $arg"
48 (cd /etc/rc.d; sh $j $arg)
453375e0
MD
49 case X`varsym -s -q rcng_$i` in
50 Xdisabled*)
51 echo "$i is disabled, enable in rc.conf first or use rcforce"
52 ;;
6d94234b
MD
53 Xfailed*)
54 echo "$i has failed to start"
55 ;;
56
453375e0 57 esac
75326d0e
MD
58 fi
59 ;;
60 esac
61 done
62}
63
64arg=$0
65case ${0##*/} in
66rcstart)
67 arg=start
68 ;;
69rcstop)
70 arg=stop
71 ;;
72rcrestart)
73 arg=restart
74 ;;
75rcvar)
76 arg=rcvar
77 ;;
78rcvars)
79 arg=rcvar
80 ;;
81rclist)
82 arg=list
83 ;;
84rcforce)
85 arg=forcestart
86 ;;
87rcfast)
88 arg=faststart
89 ;;
6d94234b
MD
90rcenable)
91 arg=enable
92 ;;
93rcdisable)
94 arg=disable
95 ;;
75326d0e
MD
96*)
97 arg=$1
98 shift
99 ;;
100esac
101
102case $arg in
103start)
104 dostart start $@
105 ;;
106forcestart)
107 dostart forcestart $@
108 ;;
109faststart)
110 dostart faststart $@
111 ;;
112stop)
113 for i in $@; do
114 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
115 if [ X$j = X ]; then
116 echo "Unable to find keyword $i"
117 else
118 (cd /etc/rc.d; sh $j stop)
119 fi
120 done
121 ;;
122restart)
123 for i in $@; do
124 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
125 if [ X$j = X ]; then
126 echo "Unable to find keyword $i"
127 else
128 (cd /etc/rc.d; sh $j restart)
129 fi
130 done
131 ;;
6d94234b
MD
132disable|enable)
133 if [ "$arg" = "enable" ]; then
134 mode=YES
135 else
136 mode=NO
137 fi
138 for i in $@; do
139 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
140 if [ X$j = X ]; then
141 echo "Unable to find provider id $i"
142 elif [ `varsym -s -q rcng_$i` = "$mode" ]; then
143 echo "$i is already $mode"
144 else
145 vars=`(cd /etc/rc.d; sh $j rcvar) 2>/dev/null | egrep '_enable' | sed -e 's/\\$//g' | sed -e 's/=.*//g'`
146 cp /etc/rc.conf /etc/rc.conf.bak
147 for k in $vars; do
148 rm -f /etc/rc.conf.$$
149 ( egrep -v "#rcrun ${k}" /etc/rc.conf; printf "${k}=${mode}\t#rcrun ${k}_enable\n" ) > /etc/rc.conf.$$
150 mv -f /etc/rc.conf.$$ /etc/rc.conf
151 echo "added/modified: ${k}=${mode}"
152 done
153 if [ $arg = enable ]; then
154 rcstart $i
155 else
156 rcstop $i
157 fi
158 fi
159 done
160 ;;
75326d0e
MD
161rcvar)
162 for i in $@; do
6d94234b 163 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
75326d0e 164 if [ X$j = X ]; then
6d94234b 165 echo "Unable to find provider id $i"
75326d0e
MD
166 else
167 (cd /etc/rc.d; sh $j rcvar)
168 fi
169 done
170 ;;
171list)
172 if [ X$@ = X ]; then
173 for i in `varsym -a -s | egrep '^rcng_'`; do
174 echo $i
175 done
176 else
177 for i in $@; do
178 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
179 done
180 fi
181 ;;
182*)
183 echo "$0 {start|stop|restart|rcvar|list|forcestart|faststart} <rcng_list>"
184 ;;
185esac
186