Skip to content

Commit fc2b523

Browse files
authored
Make script runable as nextcloud user (#27)
2 parents 7eef01d + 6128fef commit fc2b523

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

templates/occ.epp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#!/bin/sh
22

3-
cd <%= $nextcloud::current_version_dir %> && \
4-
sudo -u <%= $nextcloud::user %> \
5-
--preserve-env=OC_PASS \
6-
OC_CONFIG_WRITABLE=1 OC_CONFIG_APPSTORE_ENABLE=1 /usr/bin/php <%= $nextcloud::current_version_dir %>/occ "$@"
3+
NC_DIR="<%= $nextcloud::current_version_dir %>"
4+
NC_USER="<%= $nextcloud::user %>"
5+
6+
cd "$NC_DIR" || exit 1
7+
8+
if [ "$(id -un)" = "$NC_USER" ]; then
9+
# Already the nextcloud user: run directly, no sudo, no extra envvars.
10+
exec /usr/bin/php "$NC_DIR/occ" "$@"
11+
else
12+
# Running as someone else: drop to nextcloud via sudo, with the hardcoded envvars.
13+
exec sudo -u "$NC_USER" \
14+
--preserve-env=OC_PASS \
15+
OC_CONFIG_WRITABLE=1 \
16+
OC_CONFIG_APPSTORE_ENABLE=1 \
17+
/usr/bin/php "$NC_DIR/occ" "$@"
18+
fi

0 commit comments

Comments
 (0)