From 03a869b0a0a3b4545a7cb52c0e3cab37b1bc8e6f Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 27 Sep 2024 16:08:23 +0200 Subject: [PATCH] fix: [nextcloud] move nextcloud php config files towards datastore This makes sense as it is modifiable by the web interface, and holds unique information we want to backup and we can't regenerate. --- nextcloud/actions/upgrade | 7 ++++++- nextcloud/hooks/init | 22 ++++++++++++++++++++++ nextcloud/lib/common | 5 +++-- nextcloud/metadata.yml | 2 -- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/nextcloud/actions/upgrade b/nextcloud/actions/upgrade index 41a4c29..86c0241 100755 --- a/nextcloud/actions/upgrade +++ b/nextcloud/actions/upgrade @@ -56,7 +56,12 @@ while [ "$1" ]; do done nextcloud:config:version() { - cat "$SERVICE_CONFIGSTORE/var/www/html/config/config.php" | + for f in {"$SERVICE_CONFIGSTORE","$SERVICE_DATASTORE"}/var/www/html/config/config.php; do + if [ -e "$f" ]; then + cat "$f" + break + fi + done | grep "'version' =>" | cut -f 4 -d \' | cut -f 1-3 -d . diff --git a/nextcloud/hooks/init b/nextcloud/hooks/init index 4a27d8e..fafac22 100755 --- a/nextcloud/hooks/init +++ b/nextcloud/hooks/init @@ -19,6 +19,28 @@ admin_user=$(options-get admin.user 2>&1) || { admin_user="admin" } + +OLD_CONFIGDIR="$SERVICE_CONFIGSTORE/var/www/html/config" +if [ -d "$OLD_CONFIGDIR" ]; then + info "Old config directory found" + if [ -d "$CONFIGDIR" ]; then + if ! dir_is_empty "$CONFIGDIR"; then + err "Both old and new config directories found" + exit 1 + fi + rmdir "$CONFIGDIR" || { + err "Failed to remove new (empty) config directory" + exit 1 + } + fi + mkdir -p "${CONFIGDIR%/*}" || exit 1 + mv -v "$OLD_CONFIGDIR" "$CONFIGDIR" || { + err "Failed to move old config directory to new location" + exit 1 + } +fi + + first_run=0 read-0 current_user current_password < <(get_admin_user_password) || { info "Probably no admin user and password set before." diff --git a/nextcloud/lib/common b/nextcloud/lib/common index a923608..2a75116 100644 --- a/nextcloud/lib/common +++ b/nextcloud/lib/common @@ -8,7 +8,8 @@ PASSWORD_FILE="$SERVICE_CONFIGSTORE/etc/$SERVICE_NAME/pass" ## Used to check existence and make direct changes when 'occ' command ## can't do it properly. -CONFIGFILE="$SERVICE_CONFIGSTORE/var/www/html/config/config.php" +CONFIGDIR="$SERVICE_DATASTORE/var/www/html/config" +CONFIGFILE="$CONFIGDIR/config.php" has_user() { @@ -145,7 +146,7 @@ nextcloud:config:simple:add() { local key="$1" value="$2" create_occ_if_not_exists || return 1 - if ![ -e "$CONFIGFILE" ]; then + if ! [ -e "$CONFIGFILE" ]; then err "Config file '$CONFIGFILE' does not exist." return 1 fi diff --git a/nextcloud/metadata.yml b/nextcloud/metadata.yml index 215cddf..3d1924c 100644 --- a/nextcloud/metadata.yml +++ b/nextcloud/metadata.yml @@ -2,8 +2,6 @@ docker-image: docker.0k.io/nextcloud:18.0.1-myc data-resources: - /var/www/html - /var/lib/nextcloud/data -config-resources: - - /var/www/html/config provides: nextcloud-app: uses: