#!/bin/sh /etc/rc.common # Copyright (C) 2006 OpenWrt.org START=99 USE_PROCD=1 BIN=avahi-daemon DEFAULT=/etc/default/$BIN OPTIONS="-s" RUN_D=/var/run/$BIN PRODUCT_NAME="$(uci_get customization info product_name)" VENDOR_URL="$(uci_get customization info vendor_url)" inject_line() { local filename="$1" local grepkey="$2" local inject="$3" local old_line=$(cat "$filename" | grep "$grepkey") sed -i -e 's~'"$old_line"'~'"$inject"'~' "$filename" } start_service() { config_load avahi config_get disabled config disabled if [ "$disabled" = "1" ]; then return 0 fi config_load uhttpd config_get http_port main listen_http config_get https_port main listen_https hostname=$(uci_get system.'@system[0]'.hostname) http_port=$(echo ${http_port##*:}) https_port=$(echo ${https_port##*:}) inject_line "/etc/avahi/services/http.service" "" " $http_port" inject_line "/etc/avahi/services/https.service" "" " $https_port" inject_line "/etc/avahi/services/http.service" "" " $PRODUCT_NAME" inject_line "/etc/avahi/services/https.service" "" " $PRODUCT_NAME" inject_line "/etc/avahi/services/http.service" "vendorUrl=" " vendorUrl=$VENDOR_URL" inject_line "/etc/avahi/services/https.service" "vendorUrl=" " vendorUrl=$VENDOR_URL" [ -f $DEFAULT ] && . $DEFAULT mkdir -p $RUN_D #inject hostname in config sed "/host-name=/s_.*_host-name=${hostname}_" /etc/avahi/avahi-daemon.conf >$RUN_D/avahi-daemon.conf procd_open_instance procd_set_param command $BIN $OPTIONS -f $RUN_D/avahi-daemon.conf procd_set_param respawn procd_set_param file $RUN_D/avahi-daemon.conf procd_close_instance } service_triggers() { procd_add_reload_trigger avahi uhttpd system }