diff --git a/full/znc-build-modules.sh b/full/30-build-modules.sh old mode 100755 new mode 100644 similarity index 85% rename from full/znc-build-modules.sh rename to full/30-build-modules.sh index ea87d1b..cebead5 --- a/full/znc-build-modules.sh +++ b/full/30-build-modules.sh @@ -1,8 +1,7 @@ -#!/bin/sh - # Build modules from source. + if [ -d "${DATADIR}/modules" ]; then - cd "${DATADIR}/modules" || exit 11 + pushd "${DATADIR}/modules" || exit 11 # Find module sources. modules=$(find . -name "*.cpp") @@ -12,5 +11,7 @@ if [ -d "${DATADIR}/modules" ]; then echo "Building modules $modules..." /opt/znc/bin/znc-buildmod $modules || exit 12 fi + + popd fi diff --git a/full/Dockerfile b/full/Dockerfile index 7f45ffb..ef594c0 100644 --- a/full/Dockerfile +++ b/full/Dockerfile @@ -8,4 +8,5 @@ RUN set -x \ libressl-dev \ perl \ python3 -COPY znc-build-modules.sh / + +COPY 30-build-modules.sh /startup-sequence/ diff --git a/slim/00-try-sh.sh b/slim/00-try-sh.sh new file mode 100644 index 0000000..6fef0ec --- /dev/null +++ b/slim/00-try-sh.sh @@ -0,0 +1,6 @@ +# "docker run -ti znc sh" should work, according to +# https://github.com/docker-library/official-images + +if [ "${1:0:1}" != '-' ]; then + exec "$@" +fi diff --git a/slim/01-options.sh b/slim/01-options.sh new file mode 100644 index 0000000..a2b505e --- /dev/null +++ b/slim/01-options.sh @@ -0,0 +1,3 @@ +# Might be overriden in some later file, when using "FROM znc" + +DATADIR="/znc-data" diff --git a/slim/50-chown.sh b/slim/50-chown.sh new file mode 100644 index 0000000..15b5206 --- /dev/null +++ b/slim/50-chown.sh @@ -0,0 +1,5 @@ +# Make sure $DATADIR is owned by znc user. This affects ownership of the +# mounted directory on the host machine too. + +chown -R znc:znc "$DATADIR" || exit 1 +chmod 700 "$DATADIR" || exit 2 diff --git a/slim/99-launch.sh b/slim/99-launch.sh new file mode 100644 index 0000000..e76c449 --- /dev/null +++ b/slim/99-launch.sh @@ -0,0 +1,5 @@ +# ZNC itself responds to SIGTERM, and reaps its children, but whatever was +# started via *shell module is not guaranteed to reap their children. +# That's why using tini. + +exec /sbin/tini -- su-exec znc:znc /opt/znc/bin/znc --foreground --datadir "$DATADIR" "$@" diff --git a/slim/Dockerfile b/slim/Dockerfile index 23b0581..4cd9b57 100644 --- a/slim/Dockerfile +++ b/slim/Dockerfile @@ -45,8 +45,12 @@ RUN set -x \ && apk del build-dependencies \ && cd / && rm -rf /znc-src -COPY docker-entrypoint.sh / +COPY entrypoint.sh / +COPY 00-try-sh.sh /startup-sequence/ +COPY 01-options.sh /startup-sequence/ +COPY 50-chown.sh /startup-sequence/ +COPY 99-launch.sh /startup-sequence/ VOLUME /znc-data -ENTRYPOINT ["/docker-entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/slim/docker-entrypoint.sh b/slim/docker-entrypoint.sh deleted file mode 100755 index ad0f581..0000000 --- a/slim/docker-entrypoint.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# "docker run -ti znc sh" should work, according to -# https://github.com/docker-library/official-images -if [ "${1:0:1}" != '-' ]; then - exec "$@" -fi - -# Options. -DATADIR="/znc-data" - -# This file is added by znc:full image -if [ -r /znc-build-modules.sh ]; then - source /znc-build-modules.sh || exit 3 -fi - -cd / - -# Make sure $DATADIR is owned by znc user. This affects ownership of the -# mounted directory on the host machine too. -chown -R znc:znc "$DATADIR" || exit 1 -chmod 700 "$DATADIR" || exit 2 - -# ZNC itself responds to SIGTERM, and reaps its children, but whatever was -# started via *shell module is not guaranteed to reap their children. -# That's why using tini. -exec /sbin/tini -- su-exec znc:znc /opt/znc/bin/znc --foreground --datadir "$DATADIR" "$@" diff --git a/slim/entrypoint.sh b/slim/entrypoint.sh new file mode 100755 index 0000000..872111e --- /dev/null +++ b/slim/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +for f in /startup-sequence/*; do + source "$f" || exit 1 +done