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