You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB
Bash

#!/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" "<port>" " <port>$http_port</port>"
inject_line "/etc/avahi/services/https.service" "<port>" " <port>$https_port</port>"
inject_line "/etc/avahi/services/http.service" "<name>" " <name>$PRODUCT_NAME</name>"
inject_line "/etc/avahi/services/https.service" "<name>" " <name>$PRODUCT_NAME</name>"
inject_line "/etc/avahi/services/http.service" "<txt-record>vendorUrl=" " <txt-record>vendorUrl=$VENDOR_URL</txt-record>"
inject_line "/etc/avahi/services/https.service" "<txt-record>vendorUrl=" " <txt-record>vendorUrl=$VENDOR_URL</txt-record>"
[ -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
}