Skip to content
Snippets Groups Projects
Commit 1d64069b authored by jurgenhaas's avatar jurgenhaas
Browse files

#84 Allow to delete multiple projects at once

parent 9fc5baf0
No related branches found
Tags v2.3.0
No related merge requests found
#!/bin/bash
function removecontainer() {
docker container ls --all -q -f name=^${PROJECT}_ > /tmp/reset.lst
docker container ls --all -q -f name=^${PROJECT}_ >/tmp/reset.lst
IDS=$(cat /tmp/reset.lst)
if [[ ! -n ${IDS} ]]; then
echo "No containers to be removed."
return
fi
echo "Deleting containers ..."
for CONTAINERID in `cat /tmp/reset.lst`; do
for CONTAINERID in $(cat /tmp/reset.lst); do
docker rm -f $CONTAINERID
done
rm /tmp/reset.lst
......@@ -25,21 +25,34 @@ function removenetwork() {
if [[ -f "docker-compose.yml" ]]; then
sed -i -e "/- ${PROJECT}$/d" docker-compose.yml
sed -i -e "/^ ${PROJECT}:$/{N;d;}" docker-compose.yml
docker-compose stop
docker rm -f traefik_traefik_1
docker network rm traefik_${PROJECT}
docker-compose --project-name traefik up -d
NETWORKS="${NETWORKS} traefik_${PROJECT}"
fi
}
function rebuildtraefik() {
cd ${HOME}/.traefik || return
if [[ -f "docker-compose.yml" ]]; then
docker-compose --project-name traefik up -d --remove-orphans
fi
if [[ "$NETWORKS" == "" ]]; then
return
fi
docker network rm ${NETWORKS}
}
if [[ -n $1 ]]; then
PROJECT=$1
NETWORKS=""
while [[ -n $1 ]]; do
PROJECT=$1
read -p "Are you sure you want to remove the project ${PROJECT} with all containers and network? Type YES to confirm: " CONFIRM
if [[ "$CONFIRM" == YES ]]; then
removecontainer
removenetwork
fi
shift
done
rebuildtraefik
else
echo "Please provide the project name you want to delete."
exit
fi
read -p "Are you sure you want to remove the project ${PROJECT} with all containers and network? Type YES to confirm: " CONFIRM
if [[ "$CONFIRM" == YES ]]; then
removecontainer
removenetwork
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment