From 8f000cebfdae7e8484da6f637bb1f5ea476ab16a Mon Sep 17 00:00:00 2001 From: TNE Date: Sat, 26 Nov 2022 07:14:43 +0100 Subject: [PATCH] Improve chaotic-management container --- docker-compose-tunnels.yml | 18 ++++++++++++++++-- docker-compose.yml | 16 +++++++++++++++- run | 8 -------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/docker-compose-tunnels.yml b/docker-compose-tunnels.yml index 4fd0d75..3bdb31d 100644 --- a/docker-compose-tunnels.yml +++ b/docker-compose-tunnels.yml @@ -31,7 +31,21 @@ services: container_name: chaotic-management restart: ${RESTART:-unless-stopped} image: nginx - entrypoint: "/bin/sh -c 'trap exit TERM; sleep 10; while :; do curl -X POST -H \"X-API-Key: ${SYNCTHING_API_KEY:-XYZ}\" http://syncthing:8384/rest/db/revert?folder=jhcrt-m2dra; sleep 1h & wait $${!}; done;'" + volumes: + - './data:/data' + entrypoint: + - /bin/sh + - -c + - | + trap exit TERM; + sleep 10; + while :; do + apikey="$(grep -oPm 1 '(?<=\).*(?=\)' /data/syncthing/config.xml)" + curl -X POST -H "X-API-Key: $$apikey" http://syncthing:8384/rest/db/revert?folder=jhcrt-m2dra; + sed -i -r '/)|\1ZDHVMSP-EW4TMWX-DBH2W4P-HV5A6OY-BBEFABO-QTENANJ-RJ6GKNX-6KCG7QY\2|' /data/syncthing/config.xml + sleep 1h & + wait $${!}; + done; cloudflared: image: erisamoe/cloudflared:latest @@ -41,4 +55,4 @@ services: - './data/cloudflared/etc:/etc/cloudflared' - './data/cloudflared/home:/root' - './preset/passwd:/etc/passwd' - restart: ${RESTART:-unless-stopped} \ No newline at end of file + restart: ${RESTART:-unless-stopped} diff --git a/docker-compose.yml b/docker-compose.yml index 296769f..06fd7f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,21 @@ services: container_name: chaotic-management restart: ${RESTART:-unless-stopped} image: nginx - entrypoint: "/bin/sh -c 'trap exit TERM; sleep 10; while :; do curl -X POST -H \"X-API-Key: ${SYNCTHING_API_KEY:-XYZ}\" http://syncthing:8384/rest/db/revert?folder=jhcrt-m2dra; sleep 1h & wait $${!}; done;'" + volumes: + - './data:/data' + entrypoint: + - /bin/sh + - -c + - | + trap exit TERM; + sleep 10; + while :; do + apikey="$(grep -oPm 1 '(?<=\).*(?=\)' /data/syncthing/config.xml)" + curl -X POST -H "X-API-Key: $$apikey" http://syncthing:8384/rest/db/revert?folder=jhcrt-m2dra; + sed -i -r '/)|\1ZDHVMSP-EW4TMWX-DBH2W4P-HV5A6OY-BBEFABO-QTENANJ-RJ6GKNX-6KCG7QY\2|' /data/syncthing/config.xml + sleep 1h & + wait $${!}; + done; certbot: image: certbot/certbot:${LETSENCRYPT_TAG:-latest} diff --git a/run b/run index 589f956..c5f848c 100755 --- a/run +++ b/run @@ -25,11 +25,6 @@ fi source .env -if [[ ! -v SYNCTHING_API_KEY ]]; then - SYNCTHING_API_KEY="$(tr -dc A-Za-z0-9 > ./.env -fi - if [ "$USE_TUNNELS" != "true" ]; then if [ ! -e ./data/letsencrypt/etc/renewal/chaotic.conf ]; then docker run -p 80:80 -p 443:443 --rm -v "$PWD/data/letsencrypt/etc:/etc/letsencrypt" -v "$PWD/data/letsencrypt/var:/var/lib/letsencrypt" certbot/certbot:${LETSENCRYPT_TAG:-latest} certonly --standalone --non-interactive --agree-tos --cert-name chaotic -n -m "$EMAIL" -d "$DOMAIN_NAME" @@ -58,9 +53,6 @@ if [ ! -e ./data/syncthing/config.xml ]; then chown -R 1000:1000 ./data/syncthing fi -sed -i -r '/)|\1ZDHVMSP-EW4TMWX-DBH2W4P-HV5A6OY-BBEFABO-QTENANJ-RJ6GKNX-6KCG7QY\2|' ./data/syncthing/config.xml -sed -i -r "s|().*()|\1$SYNCTHING_API_KEY\2|" ./data/syncthing/config.xml - if [ "$USE_TUNNELS" != "true" ]; then docker-compose -f docker-compose.yml up ${COMPOSEFLAGS-"-d"} else