start of plantsensor
This commit is contained in:
44
rust_can_sensor/bin/openocd
Executable file
44
rust_can_sensor/bin/openocd
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
CONTAINER_IMAGE="localhost/wch-dev-tools:latest"
|
||||
CONTAINER_TOOLS_BASEDIR="$(dirname "$(readlink -f "$0")")"
|
||||
|
||||
function _fatal {
|
||||
echo -e "\e[31mERROR\e[0m $(</dev/stdin)$*" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
declare -a PODMAN_ARGS=(
|
||||
"--rm" "-i" "--log-driver=none"
|
||||
"--network=host"
|
||||
"-v" "$PWD:$PWD:rw"
|
||||
"-w" "$PWD"
|
||||
)
|
||||
|
||||
for device in /dev/bus/usb/*/*; do
|
||||
if udevadm info "$device" | grep -q "ID_VENDOR=wch.cn" && \
|
||||
udevadm info "$device" | grep -q "ID_MODEL=WCH-Link"; then
|
||||
DEBUGGER_DEV_PATH="$device"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${DEBUGGER_DEV_PATH:-}" ]]; then
|
||||
echo "Could not find hardware debugger … Exiting!" 1>&2
|
||||
exit 1
|
||||
else
|
||||
# add jlink to podman device
|
||||
PODMAN_ARGS+=("--device=$DEBUGGER_DEV_PATH")
|
||||
fi
|
||||
|
||||
[[ -t 1 ]] && PODMAN_ARGS+=("-t")
|
||||
|
||||
if ! podman image exists "$CONTAINER_IMAGE"; then
|
||||
#attempt to build container
|
||||
"$CONTAINER_TOOLS_BASEDIR/build-wch-tools-container.sh" 1>&2 ||
|
||||
_fatal "faild to build local image, cannot continue! … please ensure you have an internet connection"
|
||||
fi
|
||||
|
||||
podman run "${PODMAN_ARGS[@]}" --entrypoint openocd "$CONTAINER_IMAGE" "$@"
|
Reference in New Issue
Block a user