#!/bin/bash

set -e
set -u

usage() {
    echo "Usage: $0 {start|stop|status}" >&2
}

if [ $# -eq 0 ]; then
    echo "Error: No command provided." >&2
    usage
    exit 1
fi

source "/etc/lwr/static-config/lwr-usb-gadget-configurator/common-values"
source "/etc/lwr/static-config/lwr-usb-gadget-configurator/hid-common-values"

start() {
    ln -s "${HID_FUNCTION_DIR}" "${CONFIGURATION_1_DIR}/"
}

stop() {
    rm "${CONFIGURATION_1_DIR}/${HID_FUNCTION_NAME}"
}

status() {
    return # Do not report status
}

case "$1" in
    start|stop|status)
        "$@"
        ;;
    *)
        echo "Error: Unknown command '$1'." >&2
        usage
        exit 1
        ;;
esac
