#!/bin/sh

PORT="${1:-6969}"

case "${PORT}" in
    ''|*[!0-9]*)
        echo "ERROR: invalid port: ${PORT}" >&2; exit 1 ;;
esac

echo "Starting command server on port $PORT..."

while true; do
    socat TCP-LISTEN:${PORT},reuseaddr,fork EXEC:/sbin/cmddisp.sh,stderr
done
