#!/bin/sh
set -eu

package=/opt/cuefleet-client/deb
command=${1:---help}
if [ "$#" -gt 0 ]; then shift; fi

case "$command" in
    setup) exec /bin/sh "$package/setup.sh" "$@" ;;
    start) exec /bin/sh "$package/start.sh" "$@" ;;
    set-password)
        [ "$#" -eq 0 ] || { echo 'Usage: cuefleet set-password' >&2; exit 2; }
        exec /bin/sh "$package/setup.sh" --set-password
        ;;
    -h|--help|help)
        printf '%s\n' 'CueFleet Linux WebUI' \
            '  cuefleet setup --help          Configure HTTPS, window lock and IP allowlist' \
            '  cuefleet setup --show          Show current settings' \
            '  cuefleet start [--port PORT]   Start WebUI in the foreground (default port: 19425)'
        ;;
    *) printf 'Unknown command: %s\n' "$command" >&2; exit 2 ;;
esac
