#!/bin/sh /etc/rc.common
# Copyright (C) 2014 OpenWrt.org

NAME=upmpdcli
START=95

UPMPD_BIN=/usr/bin/${NAME}

USE_PROCD=1

append_arg() {
        local cfg="$1"
        local var="$2"
        local opt="$3"
        local def="$4"
        local val

        config_get val "$cfg" "$var"
        if [ -n "$val" ] || [ -n "$def" ]; then
		procd_append_param command "$opt" "${val:-$def}"
	fi
}

start_instance() {
       local cfg="$1"
       local interface

       procd_open_instance

       procd_set_param command "${UPMPD_BIN}"

#      config_get interface "$cfg" interface
#      procd_add_reload_interface_trigger $interface

       append_arg "$cfg" interface "-i"
       append_arg "$cfg" mpd_host "-h"
       append_arg "$cfg" mpd_port "-p"
       append_arg "$cfg" upmpd_port "-P"

       append_arg "$cfg" config "-c"
       append_arg "$cfg" friendly_name "-f"

       procd_close_instance
}

service_triggers() {
       procd_add_reload_trigger "${NAME}"
}

start_service() {
       config_load ${NAME}
       config_foreach start_instance ${NAME}
}
