Skip to content

Commit 587d6d5

Browse files
committed
Run update.sh
Signed-off-by: Daniel Rudolf <[email protected]>
1 parent 1733e21 commit 587d6d5

36 files changed

+432
-162
lines changed

26/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
@@ -165,7 +165,8 @@ RUN set -ex; \
165165
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
166166
rm -rf /var/lib/apt/lists/*
167167

168-
COPY *.sh upgrade.exclude /
168+
COPY entrypoint.sh cron.sh upgrade.exclude /
169+
COPY occ occ-cron /usr/local/bin/
169170
COPY config/* /usr/src/nextcloud/config/
170171

171172
ENTRYPOINT ["/entrypoint.sh"]

26/apache/entrypoint.sh

Lines changed: 12 additions & 16 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"
@@ -32,15 +24,19 @@ run_path() {
3224
echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"
3325

3426
(
35-
find "${hook_folder_path}" -type f -maxdepth 1 -iname '*.sh' -print | sort | while read -r script_file_path; do
27+
find "${hook_folder_path}" -maxdepth 1 -type f -iname '*.sh' -print | sort | while read -r script_file_path; do
3628
if ! [ -x "${script_file_path}" ]; then
3729
echo "==> The script \"${script_file_path}\" was skipped, because it didn't have the executable flag"
3830
continue
3931
fi
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 run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
224+
until eval "occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
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
@@ -254,9 +250,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
254250
else
255251
run_path pre-upgrade
256252

257-
run_as 'php /var/www/html/occ upgrade'
253+
occ upgrade
258254

259-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
255+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
260256
echo "The following apps have been disabled:"
261257
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
262258
rm -f /tmp/list_before /tmp/list_after
@@ -269,7 +265,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
269265

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

26/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

26/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

26/fpm-alpine/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN set -ex; \
1010
; \
1111
\
1212
rm /var/spool/cron/crontabs/root; \
13-
echo '*/5 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
13+
echo '*/5 * * * * occ-cron' > /var/spool/cron/crontabs/www-data
1414

1515
# install the PHP extensions we need
1616
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
@@ -134,7 +134,8 @@ RUN set -ex; \
134134
chmod +x /usr/src/nextcloud/occ; \
135135
apk del --no-network .fetch-deps
136136

137-
COPY *.sh upgrade.exclude /
137+
COPY entrypoint.sh cron.sh upgrade.exclude /
138+
COPY occ occ-cron /usr/local/bin/
138139
COPY config/* /usr/src/nextcloud/config/
139140

140141
ENTRYPOINT ["/entrypoint.sh"]

26/fpm-alpine/entrypoint.sh

Lines changed: 12 additions & 16 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"
@@ -32,15 +24,19 @@ run_path() {
3224
echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"
3325

3426
(
35-
find "${hook_folder_path}" -type f -maxdepth 1 -iname '*.sh' -print | sort | while read -r script_file_path; do
27+
find "${hook_folder_path}" -maxdepth 1 -type f -iname '*.sh' -print | sort | while read -r script_file_path; do
3628
if ! [ -x "${script_file_path}" ]; then
3729
echo "==> The script \"${script_file_path}\" was skipped, because it didn't have the executable flag"
3830
continue
3931
fi
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 run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
224+
until eval "occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
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
@@ -254,9 +250,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
254250
else
255251
run_path pre-upgrade
256252

257-
run_as 'php /var/www/html/occ upgrade'
253+
occ upgrade
258254

259-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
255+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
260256
echo "The following apps have been disabled:"
261257
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
262258
rm -f /tmp/list_before /tmp/list_after
@@ -269,7 +265,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
269265

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

26/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

26/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

26/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
@@ -150,7 +150,8 @@ RUN set -ex; \
150150
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
151151
rm -rf /var/lib/apt/lists/*
152152

153-
COPY *.sh upgrade.exclude /
153+
COPY entrypoint.sh cron.sh upgrade.exclude /
154+
COPY occ occ-cron /usr/local/bin/
154155
COPY config/* /usr/src/nextcloud/config/
155156

156157
ENTRYPOINT ["/entrypoint.sh"]

26/fpm/entrypoint.sh

Lines changed: 12 additions & 16 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"
@@ -32,15 +24,19 @@ run_path() {
3224
echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"
3325

3426
(
35-
find "${hook_folder_path}" -type f -maxdepth 1 -iname '*.sh' -print | sort | while read -r script_file_path; do
27+
find "${hook_folder_path}" -maxdepth 1 -type f -iname '*.sh' -print | sort | while read -r script_file_path; do
3628
if ! [ -x "${script_file_path}" ]; then
3729
echo "==> The script \"${script_file_path}\" was skipped, because it didn't have the executable flag"
3830
continue
3931
fi
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 run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
224+
until eval "occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
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
@@ -254,9 +250,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
254250
else
255251
run_path pre-upgrade
256252

257-
run_as 'php /var/www/html/occ upgrade'
253+
occ upgrade
258254

259-
run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
255+
occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
260256
echo "The following apps have been disabled:"
261257
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
262258
rm -f /tmp/list_before /tmp/list_after
@@ -269,7 +265,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
269265

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

0 commit comments

Comments
 (0)