From 8df80fcd8f6e2d5f4c7f61f904305bc804875005 Mon Sep 17 00:00:00 2001 From: knoflook Date: Mon, 7 Mar 2022 13:46:56 +0100 Subject: [PATCH] make sure there's only one container --- plugin.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin.sh b/plugin.sh index 3140700..1743335 100755 --- a/plugin.sh +++ b/plugin.sh @@ -41,6 +41,13 @@ run_docker_cp() { return 1 fi + NEWL=$(echo "$CONTAINER" | grep -c '$') + if [[ $NEWL != 1 ]]; then + echo "There are $NEWL containers running with the name $PLUGIN_SERVICE. I don't know which one should i copy your files to. Check your containers and stop the unnecessary ones, then restart this script." + echo -e "Containers digests: \n$CONTAINER" + return 1 + fi + CD="" if [ -n "$PLUGIN_CHDIR" ]; then CD="-C $PLUGIN_CHDIR" @@ -49,7 +56,7 @@ run_docker_cp() { echo "Copying $PLUGIN_SOURCE" # shellcheck disable=SC2086 tar cf - $CD $PLUGIN_SOURCE | docker -H "$REMOTE_DOCKER_HOST" cp - $CONTAINER:$PLUGIN_DEST - + echo "--- start exec ---" if [ -n "$PLUGIN_EXEC" ]; then docker -H "$REMOTE_DOCKER_HOST" exec "$CONTAINER" sh -c "mkdir -p /root/.ssh && echo \"$PLUGIN_DEPLOY_KEY\" > /root/.ssh/id_rsa && chmod -R 600 /root/.ssh && $PLUGIN_EXEC"