#!/bin/sh /etc/rc.common

START=80
USE_PROCD=1

usbipd_instance() {
    local config="$1"
    local enable
    local port
    local ipv4
    local ipv6
    
    config_get_bool enable "$config" enable 1
    [ "${enable}" = "0" ] && return 1

    config_get port "$config" port
    config_get_bool ipv4 "$config" ipv4 1
    config_get_bool ipv6 "$config" ipv6 1
    
    procd_open_instance usbipd
    procd_set_param command /usr/sbin/usbipd
    [ -n "${port}" ] && procd_append_param command -t${port}
    [ "${ipv4}" = "1" ] && procd_append_param command --ipv4 
    [ "${ipv6}" = "1" ] && procd_append_param command --ipv6 
    procd_close_instance
}

start_service() {
    config_load usbipd
    config_foreach usbipd_instance server
}
