From 9fb5ac222c143f1b1fb72f4d3abdca83ca53ca1a Mon Sep 17 00:00:00 2001 From: RouxAntoine Date: Wed, 2 Aug 2023 22:06:27 +0200 Subject: [PATCH] feature: password templating --- Dockerfile | 4 ++-- docker-entrypoint.sh | 9 +++++++-- server-config.json => server-config.tpl.json | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) rename server-config.json => server-config.tpl.json (75%) diff --git a/Dockerfile b/Dockerfile index f6e63d2..7ea49ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN addgroup -S $GROUP --gid $GID && \ --ingroup "$GROUP" \ --uid "$UID" \ "$USER" && \ - apk add --no-cache libc6-compat gpg + apk add --no-cache libc6-compat envsubst USER $USER @@ -41,7 +41,7 @@ RUN mkdir /perkeep/data && \ mkdir /perkeep/config COPY --chown=$USER:$GROUP --chmod=750 --from=builder /go/bin/* /usr/local/bin/ -COPY --chown=$USER:$GROUP --chmod=750 server-config.json /perkeep/config/server-config-custom.json +COPY --chown=$USER:$GROUP --chmod=750 server-config.tpl.json /perkeep/config/server-config-custom.tpl.json COPY --chown=$USER:$GROUP --chmod=750 docker-entrypoint.sh /docker-entrypoint.sh VOLUME /perkeep/data diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index ef2495c..30058f1 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,11 +1,16 @@ #!/bin/sh +if [ "T$PASSWORD" == "T" ]; +then + return 1; +fi + if [ ! -f /perkeep/config/identity-secring.gpg ]; then pk put init -newkey mv perkeep/.config/perkeep/identity-secring.gpg /perkeep/config/ - IDENTITY=$(sed -n -e '/identity/ s/.*:.*"\(.*\)".*/\1/p' /perkeep/.config/perkeep/client-config.json | tee /dev/tty) - sed -i -e "s/TO_REPLACE/$IDENTITY/g" /perkeep/config/server-config-custom.json + export IDENTITY=$(sed -n -e '/identity/ s/.*:.*"\(.*\)".*/\1/p' /perkeep/.config/perkeep/client-config.json | tee /dev/tty) + envsubst < /perkeep/config/server-config-custom.tpl.json > /perkeep/config/server-config-custom.json rm -r /perkeep/.config fi diff --git a/server-config.json b/server-config.tpl.json similarity index 75% rename from server-config.json rename to server-config.tpl.json index c31bd7c..6aa2a18 100644 --- a/server-config.json +++ b/server-config.tpl.json @@ -1,8 +1,8 @@ { - "auth": "localhost", + "auth": "userpass:antoine:$PASSWORD:+localhost", "listen": "0.0.0.0:3179", "camliNetIP": "", - "identity": "TO_REPLACE", + "identity": "$IDENTITY", "identitySecretRing": "/perkeep/config/identity-secring.gpg", "blobPath": "/perkeep/data/blobs", "packRelated": true,