blob: f5f71ac258ac47ca26a2b8539a0f7fc3b4e85e29 [file] [log] [blame]
Václav Kubernátd1beedc2020-09-07 12:09:05 +02001set -eux
2
3if [[ $(dirname "$(dirname "$(realpath "$SYSREPO_REPOSITORY_PATH")")") != "@CMAKE_CURRENT_BINARY_DIR@" ]]; then
4 echo "\$SYSREPO_REPOSITORY_PATH is not inside the build dir! Aborting. ($SYSREPO_REPOSITORY_PATH)"
5 exit 1
6fi
7
8if [[ -z "$SYSREPO_SHM_PREFIX" ]]; then
9 echo '$SYSREPO_SHM_PREFIX is empty! Aborting.'
10 exit 1
11fi
12
13BACKEND="$1"
14shift
15if [[ "$BACKEND" = "netconf" ]]; then
16 # The `-f` argument is neccessary so that pkill matches the whole command
17 # line, including stuff set by `exec -a`. Otherwise it matches the name in
18 # /proc/{pid}/stat and that is usually limited to 15 characters, so
19 # netopeer2-server appears as netopeer2-serve
Václav Kubernátc331a312020-11-19 01:24:43 +010020 NETOPEER_PID="$(pgrep -f "${SYSREPO_SHM_PREFIX}_netopeer2-server")"
Václav Kubernátd1beedc2020-09-07 12:09:05 +020021 pkill -f "${SYSREPO_SHM_PREFIX}_netopeer2-server"
Václav Kubernátc331a312020-11-19 01:24:43 +010022
23 # Wait until netopeer actually exits, because I don't want to remove its repository/shm files while it is still
24 # running.
25 #
26 # One would think, that this is a job for the `wait` command, but that one unfortunately only works for child
27 # processes of the current shell. The `tail` command does implement this mechanism, so I can use that.
28 # https://stackoverflow.com/a/41613532
29 tail --pid="$NETOPEER_PID" -f /dev/null
30
Václav Kubernátd1beedc2020-09-07 12:09:05 +020031 rm "$NETOPEER_SOCKET"
32fi
33
34rm -r "$SYSREPO_REPOSITORY_PATH"
Jan Kundrát06519662021-01-07 15:39:23 +010035rm -rf "/dev/shm/$SYSREPO_SHM_PREFIX"*