From 6b973a2153feea618487b69861b424ac67ffbd4d Mon Sep 17 00:00:00 2001 From: theautomation Date: Wed, 21 Dec 2022 15:46:43 +0100 Subject: [PATCH] Add entrypoint sh --- deploy/container/Containerfile | 4 ++-- src/.gitkeep | 0 src/entrypoint.sh | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) delete mode 100644 src/.gitkeep create mode 100644 src/entrypoint.sh diff --git a/deploy/container/Containerfile b/deploy/container/Containerfile index 871ea2e..18b0d8a 100644 --- a/deploy/container/Containerfile +++ b/deploy/container/Containerfile @@ -54,6 +54,6 @@ HEALTHCHECK --interval=30s --retries=3 CMD curl --fail http://localhost:5232 || VOLUME /config /data EXPOSE 5232 -COPY docker-entrypoint.sh /usr/local/bin -ENTRYPOINT ["docker-entrypoint.sh"] +COPY ./src/entrypoint.sh /usr/local/bin +ENTRYPOINT ["entrypoint.sh"] CMD ["radicale", "--config", "/config/config"] \ No newline at end of file diff --git a/src/.gitkeep b/src/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/entrypoint.sh b/src/entrypoint.sh new file mode 100644 index 0000000..203431b --- /dev/null +++ b/src/entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -e + +# Change uid/gid of radicale if vars specified +if [ -n "$UID" ] || [ -n "$GID" ]; then + if [ ! "$UID" = "$(id radicale -u)" ] || [ ! "$GID" = "$(id radicale -g)" ]; then + # Fail on read-only container + if grep -e "\s/\s.*\sro[\s,]" /proc/mounts >/dev/null; then + echo "You specified custom UID/GID (UID: $UID, GID: $GID)." + echo "UID/GID can only be changed when not running the container with --read-only." + echo "Please see the README.md for how to proceed and for explanations." + exit 1 + fi + + if [ -n "$UID" ]; then + usermod -o -u "$UID" radicale + fi + + if [ -n "$GID" ]; then + groupmod -o -g "$GID" radicale + fi + fi +fi + +# If requested and running as root, mutate the ownership of bind-mounts +if [ "$(id -u)" = "0" ] && [ "$TAKE_FILE_OWNERSHIP" = "true" ]; then + chown -R radicale:radicale /data +fi + +# Run radicale as the "radicale" user or any other command if provided +if [ "$(id -u)" = "0" ] && [ "$1" = "radicale" ]; then + exec su-exec radicale "$@" +else + exec "$@" +fi