diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index de69eef2..d7a2859a 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -142,7 +142,8 @@ RUN set -ex; \ chmod +x /usr/src/nextcloud/occ; \ apk del --no-network .fetch-deps -COPY *.sh upgrade.exclude / +COPY entrypoint.sh cron.sh upgrade.exclude / +COPY occ occ-cron /usr/local/bin/ COPY config/* /usr/src/nextcloud/config/ ENTRYPOINT ["/entrypoint.sh"] diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index 8b66dd34..9b39b0df 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -151,7 +151,8 @@ RUN set -ex; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \ rm -rf /var/lib/apt/lists/* -COPY *.sh upgrade.exclude / +COPY entrypoint.sh cron.sh upgrade.exclude / +COPY occ occ-cron /usr/local/bin/ COPY config/* /usr/src/nextcloud/config/ ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-occ-cron.sh b/docker-occ-cron.sh new file mode 100755 index 00000000..9a4c5846 --- /dev/null +++ b/docker-occ-cron.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu + +if [ "$(occ status 2> /dev/null | sed -ne 's/^ - installed: \(.*\)$/\1/p')" != "true" ]; then + echo "Nextcloud is not installed - cronjobs are not available" >&2 + exit 1 +fi + +[ -e /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: No such file or directory" >&2 ; exit 1 ; } +[ -f /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: Not a file" >&2 ; exit 1 ; } + +RUN_AS="$(stat -c %U /var/www/html/cron.php)" +[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ-cron\`: Failed to determine www-data user" >&2 ; exit 1 ; } + +if [ "$(id -u)" == 0 ]; then + exec su -p "$RUN_AS" -s /bin/sh -c 'php -f /var/www/html/cron.php' -- '/bin/sh' +else + exec php -f /var/www/html/cron.php +fi diff --git a/docker-occ.sh b/docker-occ.sh new file mode 100755 index 00000000..64c6d82c --- /dev/null +++ b/docker-occ.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu + +[ -e /var/www/html/occ ] || { echo "Unable to run \`occ\`: No such file or directory" >&2 ; exit 1 ; } +[ -f /var/www/html/occ ] || { echo "Unable to run \`occ\`: Not a file" >&2 ; exit 1 ; } + +RUN_AS="$(stat -c %U /var/www/html/occ)" +[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ\`: Failed to determine www-data user" >&2 ; exit 1 ; } + +if [ "$(id -u)" == 0 ]; then + exec su -p "$RUN_AS" -s /bin/sh -c 'exec php -f /var/www/html/occ -- "$@"' -- '/bin/sh' "$@" +else + exec php -f /var/www/html/occ -- "$@" +fi diff --git a/update.sh b/update.sh index bc35ce19..c2852200 100755 --- a/update.sh +++ b/update.sh @@ -128,9 +128,10 @@ function create_variant() { ' "$dir/Dockerfile" # Copy the shell scripts - for name in entrypoint cron; do - cp "docker-$name.sh" "$dir/$name.sh" - done + cp "docker-entrypoint.sh" "$dir/entrypoint.sh" + cp "docker-cron.sh" "$dir/cron.sh" + cp "docker-occ.sh" "$dir/occ" + cp "docker-occ-cron.sh" "$dir/occ-cron" # Copy the upgrade.exclude cp upgrade.exclude "$dir/"