Index: head/libexec/rc/rc.d/btpand =================================================================== --- head/libexec/rc/rc.d/btpand (nonexistent) +++ head/libexec/rc/rc.d/btpand (working copy) @@ -0,0 +1,144 @@ +#! /bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: btpand +# REQUIRE: FILESYSTEMS NETWORKING +# REQUIRE: netif bluetooth +# BEFORE: +# KEYWORD: shutdown + +. /etc/rc.subr +. /etc/network.subr + +name="btpand" +desc="Bluetooth PAN daemon" +rcvar="btpand_enable" +start_precmd="btpand_start_precmd" +stop_postcmd="btpand_stop_postcmd" +required_modules="" +required_vars="" + +load_rc_config "${name}" + +: ${btpand_enable="NO"} +: ${btpand_tapif="tap0"} +: ${btpand_device=""} +: ${btpand_service="PANU"} +: ${btpand_remote=""} + +command="/usr/sbin/${name}" +pidfile="/var/run/${btpand_tapif}.pid" + +btpand_start_precmd () +{ + local - + # tap(4): to keep configured addresses when btpand stopped + ${IFCONFIG_CMD} ${btpand_tapif} link0 +} + +btpand_stop_postcmd () +{ + local - + if [ -f "${pidfile}" ] ; then + rm -f -- "${pidfile}" + fi +} + +btpand_setup_flags () +{ + if ! ifexists ${btpand_tapif} ; then + warn + return 1 + fi + btpand_flags="${btpand_flags:-}${btpand_tapif:+ -i ${btpand_tapif}}" + + btpand_flags="${btpand_flags:-}${btpand_device:+ -d ${btpand_device}}" + + case "${btpand_service}" in # ( + [Nn][Aa][Pp]) + btpand_flags="${btpand_flags:-}${btpand_service:+ -s NAP}" + ;; # ( + [Gg][Nn]) + btpand_flags="${btpand_flags:-}${btpand_service:+ -s GN}" + ;; # ( + [Pp][Aa][Nn][Uu]) + btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}" + ;; # ( + *) + warn "unsupported PAN service. use PANU." + btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}" + ;; + esac + + # PANU client + btpand_flags="${btpand_flags:-}${btpand_remote:+ -a ${btpand_remote}}" +} + +btpand_run_rc_command_profile () +{ + local - + local command command_args pidfile rcvar + local _rc_restart_done + local btpand_flags + local btpand_tapif btpand_device btpand_service + local profile _return + + profile="$1" + shift 1 + + eval "rcvar=\"btpand_${profile}_enable\"" + eval "btpand_flags=\"\${btpand_${profile}_flags:-${btpand_flags}}\"" + eval "btpand_tapif=\"\${btpand_${profile}_tapif:-${btpand_tapif}}\"" + eval "btpand_device=\"\${btpand_${profile}_device:-${btpand_device}}\"" + eval "btpand_service=\"\${btpand_${profile}_service:-${btpand_service}}\"" + eval "btpand_remote=\"\${btpand_${profile}_remote:-${btpand_remote}}\"" + eval "pidfile=\"/var/run/${btpand_tapif}.pid\"" + eval "_rc_restart_done=\"\${_rc_restart_done_btpand_${profile}:-false}\"" + + if ! btpand_setup_flags ; then + return 1 + fi + + run_rc_command ${1+"$@"} + _return="${?}" + + eval "_rc_restart_done_btpand_${profile}=\"\${_rc_restart_done:-false}\"" + + return "${_return}" +} + +if [ -n "${btpand_profiles}" ] ; then + btpand_rc_arg="$1" + if [ ${#} -gt 0 ] ; then + shift 1 + fi + + btpand_profiles="$(echo ${btpand_profiles})" + btpand_run_profiles="" + if [ -n "$*" ] ; then + for profile + do + case " ${btpand_profiles} " in # ( + *" ${profile} "*) + btpand_run_profiles="${btpand_run_profiles:+${btpand_run_profiles} }${profile}" + ;; + esac + done + else + btpand_run_profiles="${btpand_profiles}" + fi + + for profile in ${btpand_run_profiles} + do + echo "===> btpand profile: ${profile}" + btpand_run_rc_command_profile "${profile}" "${btpand_rc_arg}" + done +else + if ! btpand_setup_flags ; then + return 1 + fi + + run_rc_command ${1+"$@"} +fi Property changes on: head/libexec/rc/rc.d/btpand ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property