rc.opnsense 835 Bytes
Newer Older
1 2 3
#!/bin/sh

# check which services to enable
4 5 6 7 8
if [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi
for RC_CONF in $(ls /etc/rc.conf.d); do
	. /etc/rc.conf.d/${RC_CONF}
9 10 11
done

# probe all deamons in /usr/local/etc/rc.d/
12 13 14 15 16
ls /usr/local/etc/rc.d/* | while read rc_filename; do
	# read rc scripts and parse name and rcvar variables
	_file=`basename $rc_filename`
	eval `/usr/bin/grep "name[[:blank:]]*=" $rc_filename | /usr/bin/head -n 1`
	eval `grep "rcvar[[:blank:]]*=" $rc_filename | /usr/bin/sed '/^$/d'`
17

18 19
	# check if service is enabled
	eval "is_enabled=\$"$rcvar""
20

21 22
	# start/stop service
	if [ "$is_enabled" == "YES" ]; then
23 24 25 26 27 28 29
		if [ "$1" == "start" ]; then
			pre_run_var="`basename $rc_filename`_opnsense_bootup_run"
			eval "pre_run=\$"$pre_run_var""
			if [ ! -z "$pre_run" ]; then
				eval "$pre_run"
			fi
		fi
30 31
		$rc_filename $1
	fi
32
done