#!/bin/bash

: '
------------------------------------------------------------------------------
Script Purpose:
    This script is designed to automatically configure the CH9329 USB-to-serial
    device to operate at a baudrate of 115200. It is intended for users who need
    to update the communication speed from the default or previously set value.
    You only need to do it ONCE after you have soldered the CH9329 chip to your
    board.

Usage Instructions:
    1. Ensure both the host and remote sides of the CH9329 device are connected
       to their respective USB ports. (The host side connects to your PC, which
       should show up as /dev/ttyUSB0 or similar. The remote side connects to
       your target device, usually another headless computer, which should show
       up as a USB HID device with keyboard and mouse capabilities.)
    2. Power on the device before running this script.

Important Notes:
    - The CH9329 device typically defaults to a baudrate of 9600. However, if it
      has been configured previously, it may be set to a different baudrate.
    - Incorrect configuration or misuse of this script may damage the device or
      render it unusable. Proceed with caution and ensure you understand the
      implications of changing device settings.

WARNING:
    Use this script at your own risk. Double-check all connections and settings
    before execution to avoid potential hardware damage.
------------------------------------------------------------------------------
'

# Ask for baudrate with default 9600
read -p "Enter baudrate [9600]: " baudrate
baudrate=${baudrate:-9600}

# Ask for USB KVM device path with default /dev/ttyUSB0
read -p "Enter USB KVM device path [/dev/ttyUSB0]: " usbkvm
usbkvm=${usbkvm:-/dev/ttyUSB0}

# Run the command
sudo ./remdeskd -mode=cfgchip -baudrate="$baudrate" -usbkvm="$usbkvm"