# Exit immediately if a command exits with a non-zero status set -e # Function to display help message show_help() { echo "Usage: $0 [options] -h -r " echo echo "Required:" echo " -h, --host Local host IP address" echo " -r, --remote Remote host IP address" echo echo "Optional:" echo " -u, --user Remote username (default: root)" echo " -p, --port Python server port (default: 8000)" echo " --help Display this help message" echo echo "Example:" echo " $0 -h 192.168.0.13 -r 192.168.0.17" echo " $0 -h 192.168.0.13 -r 192.168.0.17 -u admin -p 8080" exit 0 } # Default values PYTHON_PORT=8000 REMOTE_USER="root" REMOTE_PATH="/userdata/jetkvm/bin" # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in -h|--host) HOST_IP="$2" shift 2 ;; -r|--remote) REMOTE_HOST="$2" shift 2 ;; -u|--user) REMOTE_USER="$2" shift 2 ;; -p|--port) PYTHON_PORT="$2" shift 2 ;; --help) show_help exit 0 ;; *) echo "Unknown option: $1" show_help exit 1 ;; esac done # Verify required parameters if [ -z "$HOST_IP" ] || [ -z "$REMOTE_HOST" ]; then echo "Error: Host IP and Remote IP are required parameters" show_help fi # Build the development version on the host make frontend make build_dev # Change directory to the binary output directory cd bin # Start a Python HTTP server in the background to serve files python3 -m http.server "$PYTHON_PORT" & PYTHON_SERVER_PID=$! # Ensure that the Python server is terminated if the script exits unexpectedly trap "echo 'Terminating Python server...'; kill $PYTHON_SERVER_PID" EXIT # Deploy and run the application on the remote host ssh "${REMOTE_USER}@${REMOTE_HOST}" ash <