Skip to content

Commit da1c4fe

Browse files
committed
Run update.sh
Signed-off-by: Daniel Rudolf <[email protected]>
1 parent fe86b46 commit da1c4fe

36 files changed

+423
-153
lines changed

27/apache/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -ex; \
1515
rm -rf /var/lib/apt/lists/*; \
1616
\
1717
mkdir -p /var/spool/cron/crontabs; \
18-
echo '*/5 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
18+
echo '*/5 * * * * occ-cron' > /var/spool/cron/crontabs/www-data
1919

2020
# install the PHP extensions we need
2121
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
@@ -167,7 +167,8 @@ RUN set -ex; \
167167
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
168168
rm -rf /var/lib/apt/lists/*
169169

170-
COPY *.sh upgrade.exclude /
170+
COPY entrypoint.sh cron.sh upgrade.exclude /
171+
COPY occ occ-cron /usr/local/bin/
171172
COPY config/* /usr/src/nextcloud/config/
172173

173174
ENTRYPOINT ["/entrypoint.sh"]

27/apache/entrypoint.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ directory_empty() {
1111
[ -z "$(ls -A "$1/")" ]
1212
}
1313

14-
run_as() {
15-
if [ "$(id -u)" = 0 ]; then
16-
su -p "$user" -s /bin/sh -c "$1"
17-
else
18-
sh -c "$1"
19-
fi
20-
}
21-
2214
# Execute all executable files in a given directory in alphanumeric order
2315
run_path() {
2416
local hook_folder_path="/docker-entrypoint-hooks.d/$1"
@@ -40,7 +32,11 @@ run_path() {
4032

4133
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
4234

43-
run_as "${script_file_path}" || return_code="$?"
35+
if [ "$(id -u)" = 0 ]; then
36+
su -p "$user" -s /bin/sh "${script_file_path}" || return_code="$?"
37+
else
38+
"${script_file_path}" || return_code="$?"
39+
fi
4440

4541
if [ "${return_code}" -ne "0" ]; then
4642
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
@@ -163,7 +159,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
163159
exit 1
164160
fi
165161
echo "Upgrading nextcloud from $installed_version ..."
166-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
162+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
167163
fi
168164
if [ "$(id -u)" = 0 ]; then
169165
rsync_options="-rlDog --chown $user:$group"
@@ -225,7 +221,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
225221
echo "Starting nextcloud installation"
226222
max_retries=10
227223
try=0
228-
until [ "$try" -gt "$max_retries" ] || run_as "php /var/www/html/occ maintenance:install $install_options"
224+
until [ "$try" -gt "$max_retries" ] || eval "occ maintenance:install $install_options"
229225
do
230226
echo "Retrying install..."
231227
try=$((try+1))
@@ -240,7 +236,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
240236
NC_TRUSTED_DOMAIN_IDX=1
241237
for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
242238
DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
243-
run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN"
239+
occ config:system:set trusted_domains "$NC_TRUSTED_DOMAIN_IDX" --value="$DOMAIN"
244240
NC_TRUSTED_DOMAIN_IDX=$((NC_TRUSTED_DOMAIN_IDX+1))
245241
done
246242
fi
@@ -257,9 +253,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
257253
else
258254
run_path pre-upgrade
259255

260-
run_as 'php /var/www/html/occ upgrade'
256+
occ upgrade
261257

262-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
258+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
263259
echo "The following apps have been disabled:"
264260
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
265261
rm -f /tmp/list_before /tmp/list_after
@@ -272,7 +268,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
272268

273269
# Update htaccess after init if requested
274270
if [ -n "${NEXTCLOUD_INIT_HTACCESS+x}" ] && [ "$installed_version" != "0.0.0.0" ]; then
275-
run_as 'php /var/www/html/occ maintenance:update:htaccess'
271+
occ maintenance:update:htaccess
276272
fi
277273
) 9> /var/www/html/nextcloud-init-sync.lock
278274

27/apache/occ

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
[ -e /var/www/html/occ ] || { echo "Unable to run \`occ\`: No such file or directory" >&2 ; exit 1 ; }
5+
[ -f /var/www/html/occ ] || { echo "Unable to run \`occ\`: Not a file" >&2 ; exit 1 ; }
6+
7+
RUN_AS="$(stat -c %U /var/www/html/occ)"
8+
[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ\`: Failed to determine www-data user" >&2 ; exit 1 ; }
9+
10+
if [ "$(id -u)" = 0 ]; then
11+
exec su -p "$RUN_AS" -s /bin/sh -c 'exec php -f /var/www/html/occ -- "$@"' -- '/bin/sh' "$@"
12+
else
13+
exec php -f /var/www/html/occ -- "$@"
14+
fi

27/apache/occ-cron

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
if [ "$(occ status 2> /dev/null | sed -ne 's/^ - installed: \(.*\)$/\1/p')" != "true" ]; then
5+
echo "Nextcloud is not installed - cronjobs are not available" >&2
6+
exit 1
7+
fi
8+
9+
[ -e /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: No such file or directory" >&2 ; exit 1 ; }
10+
[ -f /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: Not a file" >&2 ; exit 1 ; }
11+
12+
RUN_AS="$(stat -c %U /var/www/html/cron.php)"
13+
[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ-cron\`: Failed to determine www-data user" >&2 ; exit 1 ; }
14+
15+
if [ "$(id -u)" = 0 ]; then
16+
exec su -p "$RUN_AS" -s /bin/sh -c 'exec php -f /var/www/html/cron.php' -- '/bin/sh'
17+
else
18+
exec php -f /var/www/html/cron.php
19+
fi

27/fpm-alpine/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN set -ex; \
1717
; \
1818
\
1919
rm /var/spool/cron/crontabs/root; \
20-
echo '*/5 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
20+
echo '*/5 * * * * occ-cron' > /var/spool/cron/crontabs/www-data
2121

2222
# install the PHP extensions we need
2323
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
@@ -143,7 +143,8 @@ RUN set -ex; \
143143
chmod +x /usr/src/nextcloud/occ; \
144144
apk del --no-network .fetch-deps
145145

146-
COPY *.sh upgrade.exclude /
146+
COPY entrypoint.sh cron.sh upgrade.exclude /
147+
COPY occ occ-cron /usr/local/bin/
147148
COPY config/* /usr/src/nextcloud/config/
148149

149150
ENTRYPOINT ["/entrypoint.sh"]

27/fpm-alpine/entrypoint.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ directory_empty() {
1111
[ -z "$(ls -A "$1/")" ]
1212
}
1313

14-
run_as() {
15-
if [ "$(id -u)" = 0 ]; then
16-
su -p "$user" -s /bin/sh -c "$1"
17-
else
18-
sh -c "$1"
19-
fi
20-
}
21-
2214
# Execute all executable files in a given directory in alphanumeric order
2315
run_path() {
2416
local hook_folder_path="/docker-entrypoint-hooks.d/$1"
@@ -40,7 +32,11 @@ run_path() {
4032

4133
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
4234

43-
run_as "${script_file_path}" || return_code="$?"
35+
if [ "$(id -u)" = 0 ]; then
36+
su -p "$user" -s /bin/sh "${script_file_path}" || return_code="$?"
37+
else
38+
"${script_file_path}" || return_code="$?"
39+
fi
4440

4541
if [ "${return_code}" -ne "0" ]; then
4642
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
@@ -163,7 +159,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
163159
exit 1
164160
fi
165161
echo "Upgrading nextcloud from $installed_version ..."
166-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
162+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
167163
fi
168164
if [ "$(id -u)" = 0 ]; then
169165
rsync_options="-rlDog --chown $user:$group"
@@ -225,7 +221,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
225221
echo "Starting nextcloud installation"
226222
max_retries=10
227223
try=0
228-
until [ "$try" -gt "$max_retries" ] || run_as "php /var/www/html/occ maintenance:install $install_options"
224+
until [ "$try" -gt "$max_retries" ] || eval "occ maintenance:install $install_options"
229225
do
230226
echo "Retrying install..."
231227
try=$((try+1))
@@ -240,7 +236,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
240236
NC_TRUSTED_DOMAIN_IDX=1
241237
for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
242238
DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
243-
run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN"
239+
occ config:system:set trusted_domains "$NC_TRUSTED_DOMAIN_IDX" --value="$DOMAIN"
244240
NC_TRUSTED_DOMAIN_IDX=$((NC_TRUSTED_DOMAIN_IDX+1))
245241
done
246242
fi
@@ -257,9 +253,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
257253
else
258254
run_path pre-upgrade
259255

260-
run_as 'php /var/www/html/occ upgrade'
256+
occ upgrade
261257

262-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
258+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
263259
echo "The following apps have been disabled:"
264260
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
265261
rm -f /tmp/list_before /tmp/list_after
@@ -272,7 +268,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
272268

273269
# Update htaccess after init if requested
274270
if [ -n "${NEXTCLOUD_INIT_HTACCESS+x}" ] && [ "$installed_version" != "0.0.0.0" ]; then
275-
run_as 'php /var/www/html/occ maintenance:update:htaccess'
271+
occ maintenance:update:htaccess
276272
fi
277273
) 9> /var/www/html/nextcloud-init-sync.lock
278274

27/fpm-alpine/occ

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
[ -e /var/www/html/occ ] || { echo "Unable to run \`occ\`: No such file or directory" >&2 ; exit 1 ; }
5+
[ -f /var/www/html/occ ] || { echo "Unable to run \`occ\`: Not a file" >&2 ; exit 1 ; }
6+
7+
RUN_AS="$(stat -c %U /var/www/html/occ)"
8+
[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ\`: Failed to determine www-data user" >&2 ; exit 1 ; }
9+
10+
if [ "$(id -u)" = 0 ]; then
11+
exec su -p "$RUN_AS" -s /bin/sh -c 'exec php -f /var/www/html/occ -- "$@"' -- '/bin/sh' "$@"
12+
else
13+
exec php -f /var/www/html/occ -- "$@"
14+
fi

27/fpm-alpine/occ-cron

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
if [ "$(occ status 2> /dev/null | sed -ne 's/^ - installed: \(.*\)$/\1/p')" != "true" ]; then
5+
echo "Nextcloud is not installed - cronjobs are not available" >&2
6+
exit 1
7+
fi
8+
9+
[ -e /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: No such file or directory" >&2 ; exit 1 ; }
10+
[ -f /var/www/html/cron.php ] || { echo "Unable to run \`occ-cron\`: Not a file" >&2 ; exit 1 ; }
11+
12+
RUN_AS="$(stat -c %U /var/www/html/cron.php)"
13+
[ -n "$RUN_AS" ] && [ "$RUN_AS" != "UNKNOWN" ] || { echo "Unable to run \`occ-cron\`: Failed to determine www-data user" >&2 ; exit 1 ; }
14+
15+
if [ "$(id -u)" = 0 ]; then
16+
exec su -p "$RUN_AS" -s /bin/sh -c 'exec php -f /var/www/html/cron.php' -- '/bin/sh'
17+
else
18+
exec php -f /var/www/html/cron.php
19+
fi

27/fpm/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -ex; \
1515
rm -rf /var/lib/apt/lists/*; \
1616
\
1717
mkdir -p /var/spool/cron/crontabs; \
18-
echo '*/5 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
18+
echo '*/5 * * * * occ-cron' > /var/spool/cron/crontabs/www-data
1919

2020
# install the PHP extensions we need
2121
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
@@ -152,7 +152,8 @@ RUN set -ex; \
152152
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
153153
rm -rf /var/lib/apt/lists/*
154154

155-
COPY *.sh upgrade.exclude /
155+
COPY entrypoint.sh cron.sh upgrade.exclude /
156+
COPY occ occ-cron /usr/local/bin/
156157
COPY config/* /usr/src/nextcloud/config/
157158

158159
ENTRYPOINT ["/entrypoint.sh"]

27/fpm/entrypoint.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ directory_empty() {
1111
[ -z "$(ls -A "$1/")" ]
1212
}
1313

14-
run_as() {
15-
if [ "$(id -u)" = 0 ]; then
16-
su -p "$user" -s /bin/sh -c "$1"
17-
else
18-
sh -c "$1"
19-
fi
20-
}
21-
2214
# Execute all executable files in a given directory in alphanumeric order
2315
run_path() {
2416
local hook_folder_path="/docker-entrypoint-hooks.d/$1"
@@ -40,7 +32,11 @@ run_path() {
4032

4133
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
4234

43-
run_as "${script_file_path}" || return_code="$?"
35+
if [ "$(id -u)" = 0 ]; then
36+
su -p "$user" -s /bin/sh "${script_file_path}" || return_code="$?"
37+
else
38+
"${script_file_path}" || return_code="$?"
39+
fi
4440

4541
if [ "${return_code}" -ne "0" ]; then
4642
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
@@ -163,7 +159,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
163159
exit 1
164160
fi
165161
echo "Upgrading nextcloud from $installed_version ..."
166-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
162+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
167163
fi
168164
if [ "$(id -u)" = 0 ]; then
169165
rsync_options="-rlDog --chown $user:$group"
@@ -225,7 +221,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
225221
echo "Starting nextcloud installation"
226222
max_retries=10
227223
try=0
228-
until [ "$try" -gt "$max_retries" ] || run_as "php /var/www/html/occ maintenance:install $install_options"
224+
until [ "$try" -gt "$max_retries" ] || eval "occ maintenance:install $install_options"
229225
do
230226
echo "Retrying install..."
231227
try=$((try+1))
@@ -240,7 +236,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
240236
NC_TRUSTED_DOMAIN_IDX=1
241237
for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
242238
DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
243-
run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN"
239+
occ config:system:set trusted_domains "$NC_TRUSTED_DOMAIN_IDX" --value="$DOMAIN"
244240
NC_TRUSTED_DOMAIN_IDX=$((NC_TRUSTED_DOMAIN_IDX+1))
245241
done
246242
fi
@@ -257,9 +253,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
257253
else
258254
run_path pre-upgrade
259255

260-
run_as 'php /var/www/html/occ upgrade'
256+
occ upgrade
261257

262-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
258+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
263259
echo "The following apps have been disabled:"
264260
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
265261
rm -f /tmp/list_before /tmp/list_after
@@ -272,7 +268,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
272268

273269
# Update htaccess after init if requested
274270
if [ -n "${NEXTCLOUD_INIT_HTACCESS+x}" ] && [ "$installed_version" != "0.0.0.0" ]; then
275-
run_as 'php /var/www/html/occ maintenance:update:htaccess'
271+
occ maintenance:update:htaccess
276272
fi
277273
) 9> /var/www/html/nextcloud-init-sync.lock
278274

0 commit comments

Comments
 (0)