-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathocdocker
executable file
·38 lines (30 loc) · 1.08 KB
/
ocdocker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
###
# 启动docker里默认的ocd,docker必须提前建好且在运行
# 这个操作会杀掉其他ocd程序
# 参数1(可选):
# -t 在docker里运行bash,而不是ocd
# -k 只杀掉所有ocd,不启动自己的
###
DOCKER_PS_LINE=$(sudo docker ps | awk '{print $1" "$2" "$NF}' | grep ' riscv')
DOCKER_CONTAINER=$(echo "${DOCKER_PS_LINE}" | awk '{print $1}')
if [ -z "${DOCKER_CONTAINER}" ]; then
echo "Error: container not started.">&2
exit 1
fi
echo "Running docker: $DOCKER_PS_LINE"
USING="$(detect_other_using)"
if [ -n "${USING}" ] ; then
echo -e "用户 \e[38;5;14m${USING}\e[0m 近2分钟还在使用设备,先让他退出。"
exit 1
fi
SCRIPT=(-c "killall -sigkill -q openocd ; openocd -f /home/openocd.cfg $*")
if echo "$*" | grep -q -- "-t" ; then
SCRIPT=(--login -i)
fi
if echo "$*" | grep -q -- "-k" ; then
SCRIPT=(-c "killall -sigkill -q openocd")
fi
NAME_REF="$(echo ${DOCKER_PS_LINE} | awk '{print $NF}')"
set -x
sudo docker exec -e "CURRENT_USER=$USER" -e "NAME=${NAME_REF}" -it "${DOCKER_CONTAINER}" /bin/bash "${SCRIPT[@]}"