2 ################################################################################
4 # Copyright 2020 highstreet technologies GmbH and others
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ################################################################################
19 if [ "$#" -ne 1 ]; then
20 echo "ID Parameter missing."
21 echo "Usage: $0 id/all
23 where id is the docker container id of the NTS Manager instance that we want to clean. Use 'all' if you want to clean all containers and all managers."
27 if [ "$1" = "all" ]; then
28 echo "Cleaning up all NTS simulated devices..."
30 mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager" --format "{{.ID}}" )
34 if [ ${#NTS_containers[@]} -gt 0 ]
37 for container in "${NTS_containers[@]}"
39 CONTAINERS="$CONTAINERS $container"
41 echo "Cleaning up containers: $CONTAINERS"
42 docker kill $CONTAINERS > /dev/null 2>&1
43 docker rm $CONTAINERS > /dev/null 2>&1
46 echo "Cleaning up all NTS Managers..."
48 mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS-manager" --format "{{.ID}}" )
52 if [ ${#NTS_containers[@]} -gt 0 ]
55 for container in "${NTS_containers[@]}"
57 CONTAINERS="$CONTAINERS $container"
59 echo "Cleaning up containers: $CONTAINERS"
60 docker kill $CONTAINERS > /dev/null 2>&1
61 docker rm $CONTAINERS > /dev/null 2>&1
65 echo "Cleaning up containers started by the NTS Manager $1..."
67 mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager=$1" --format "{{.ID}}" )
71 if [ ${#NTS_containers[@]} -gt 0 ]
74 for container in "${NTS_containers[@]}"
76 CONTAINERS="$CONTAINERS $container"
78 echo "Cleaning up containers: $CONTAINERS"
79 docker kill $CONTAINERS > /dev/null 2>&1
80 docker rm $CONTAINERS > /dev/null 2>&1
83 echo "Cleaning NTS Manager $1..."
84 docker kill $1 > /dev/null 2>&1
85 docker rm $1 > /dev/null 2>&1
88 echo "All cleaned up!"