Home | History | Annotate | Line # | Download | only in rc.d
envsys revision 1.1
      1 #!/bin/sh
      2 #
      3 # $NetBSD: envsys,v 1.1 2007/07/01 08:01:29 xtraeme Exp $
      4 #
      5 
      6 # PROVIDE: envsys
      7 # REQUIRE: LOGIN DAEMON
      8 
      9 $_rc_subr_loaded . /etc/rc.subr
     10 
     11 name="envsys"
     12 rcvar=${name}
     13 required_files="/etc/envsys.conf"
     14 start_cmd="do_envsys start"
     15 stop_cmd="do_envsys stop"
     16 envsys_bin="/usr/sbin/envstat"
     17 
     18 do_envsys()
     19 {
     20 	IFS=":"
     21 	if [ "$1" = "start" ]; then
     22 		TARGET="Starting"
     23 	else
     24 		TARGET="Stopping"
     25 	fi
     26 
     27 	while read -r device sensname target value; do
     28 		case "${device}" in
     29 		\#*|"")
     30 			continue
     31 			;;
     32 		esac
     33 
     34 		case "${value}" in
     35 		*degF)
     36 			add_arg="-f"
     37 			;;
     38 		esac
     39 
     40 		[ -z ${device} ] && err_msg="missing device"
     41 		[ -z ${target} ] && err_msg="missing target"
     42 		[ -z ${value} ] && err_msg="missing value"
     43 
     44 		if [ -n "${err_msg}" ]; then
     45 			echo "${name}: invalid entry (${err_msg})."
     46 			return 1
     47 		fi
     48 
     49 		if [ "$1" = "start" ]; then
     50 			${envsys_bin} \
     51 			    ${add_arg} \
     52 			    -d ${device} \
     53 			    -s "${sensname}" \
     54 			    -m ${target}=${value%%degF}
     55 		else
     56 			${envsys_bin} \
     57 			    ${add_arg} \
     58 			    -d ${device} \
     59 			    -s "${sensname}" \
     60 			    -m ${target}=remove
     61 		fi
     62 
     63 		# reinitialize the var
     64 		add_arg=
     65 	done < ${required_files}
     66 
     67 	echo "$TARGET sensors monitoring."
     68 }
     69 
     70 load_rc_config ${name}
     71 run_rc_command "$1"
     72