#!/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"

start() {
    # Create USB configuration directory, which will create other vital files and directories
    mkdir -p "${CONFIGURATION_1_DIR}"
    mkdir -p "${CONFIGURATION_1_STRINGS_DIR}"
    echo "Configuration 1" > "${CONFIGURATION_1_STRINGS_DIR}/configuration"
}

stop() {
    rmdir "${CONFIGURATION_1_STRINGS_DIR}"
    rmdir "${CONFIGURATION_1_DIR}"
}

status() {
    return # Do not report status
}

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