2024-11-21 16:03:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Extract the Docker image version from the CircleCI config file
|
|
|
|
DOCKER_IMAGE=$(grep -oP '^\s*-?\s*image:\s*\K(tlaurion/heads-dev-env:[^\s]+)' .circleci/config.yml | head -n 1)
|
|
|
|
|
|
|
|
# Check if the Docker image was found
|
|
|
|
if [ -z "$DOCKER_IMAGE" ]; then
|
2024-11-21 21:54:08 +00:00
|
|
|
echo "Error: Docker image not found in .circleci/config.yml"
|
|
|
|
exit 1
|
2024-11-21 16:03:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Inform the user about the versioned CircleCI Docker image being used
|
|
|
|
echo "Using CircleCI Docker image: $DOCKER_IMAGE"
|
|
|
|
|
|
|
|
# Function to display usage information
|
|
|
|
usage() {
|
2024-11-21 21:54:08 +00:00
|
|
|
echo "Usage: $0 [OPTIONS] -- [COMMAND]"
|
|
|
|
echo "Options:"
|
|
|
|
echo " CPUS=N Set the number of CPUs"
|
|
|
|
echo " V=1 Enable verbose mode"
|
|
|
|
echo "Command:"
|
|
|
|
echo " The command to run inside the Docker container, e.g., make BOARD=BOARD_NAME"
|
2024-11-21 16:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to kill GPG toolstack related processes using USB devices
|
|
|
|
kill_usb_processes() {
|
2024-11-21 21:54:08 +00:00
|
|
|
# check if scdaemon or pcscd processes are using USB devices
|
|
|
|
if [ -d /dev/bus/usb ]; then
|
|
|
|
if sudo lsof /dev/bus/usb/00*/0* 2>/dev/null | awk 'NR>1 {print $2}' | xargs -r ps -p | grep -E 'scdaemon|pcscd' >/dev/null; then
|
|
|
|
echo "Killing GPG toolstack related processes using USB devices..."
|
|
|
|
sudo lsof /dev/bus/usb/00*/0* 2>/dev/null | awk 'NR>1 {print $2}' | xargs -r ps -p | grep -E 'scdaemon|pcscd' | awk '{print $1}' | xargs -r sudo kill -9
|
|
|
|
fi
|
|
|
|
fi
|
2024-11-21 16:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Handle Ctrl-C (SIGINT) to exit gracefully
|
|
|
|
trap "echo 'Script interrupted. Exiting...'; exit 1" SIGINT
|
|
|
|
|
|
|
|
# Check if --help or -h is provided
|
|
|
|
for arg in "$@"; do
|
2024-11-21 21:54:08 +00:00
|
|
|
if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-11-21 16:03:31 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Kill processes using USB devices
|
|
|
|
kill_usb_processes
|
|
|
|
|
|
|
|
# Inform the user about entering the Docker container
|
|
|
|
echo "----"
|
|
|
|
echo "Usage reminder: The minimal command is 'make BOARD=XYZ', where additional options, including 'V=1' or 'CPUS=N' are optional."
|
|
|
|
echo "For more advanced QEMU testing options, refer to targets/qemu.md and boards/qemu-*/*.config."
|
2024-11-21 21:54:08 +00:00
|
|
|
echo
|
|
|
|
echo "Type exit within docker image to get back to host if launched interactively!"
|
2024-11-21 16:03:31 +00:00
|
|
|
echo "----"
|
2024-11-21 21:54:08 +00:00
|
|
|
echo
|
2024-11-21 16:03:31 +00:00
|
|
|
|
|
|
|
# Execute the docker run command with the provided parameters
|
2024-11-21 21:54:08 +00:00
|
|
|
if [ -d "/dev/bus/usb" ]; then
|
|
|
|
echo "--->Launching container with access to host's USB buses (some USB devices were connected to host)..."
|
|
|
|
docker run --device=/dev/bus/usb:/dev/bus/usb -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) $DOCKER_IMAGE -- "$@"
|
|
|
|
else
|
|
|
|
echo "--->Launching container without access to host's USB buses (no USB devices was connected to host)..."
|
|
|
|
docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) $DOCKER_IMAGE -- "$@"
|
|
|
|
fi
|