diff --git a/type/__nextcloud/gencode-remote b/type/__nextcloud/gencode-remote index 9ffbc4a..38024a6 100755 --- a/type/__nextcloud/gencode-remote +++ b/type/__nextcloud/gencode-remote @@ -22,6 +22,28 @@ SU SHELL } +# Turn the maintainer mode on, but print it only once at all. +# +# No arguments. +occ_maintainer_mode_on() { + # Check if this was not already done + if [ "$_maintainer_mode_on" != "yes" ]; then + occ maintenance:mode --on + _maintainer_mode_on="yes" + fi +} + +# Print the value of the given configuration. +# +# Arguments: +# 1: the nextcloud configuration name +getparam() { + awk -v FS=" = " -v name="$1" ' + function ntostring(n) { ret=""; for(i=n; i<=NF; i++) ret=ret $i (i/dev/null || printf "%s/data" "$installdir")" + +# Move if they should be moved. Avoid false positives if $data_old is empty +if [ "$data_old" ] && [ "$data_old" != "$data_new" ]; then + # save that we did changes + changes="yes" + occ_maintainer_mode_on + + # Change the configuration variable and then move the folder. This order is + # important if SQLite is used, but the config already corrupted if it can + # not be moved. + occ config:system:set datadirectory --type=string --value "'$data_new'" + cat << REMOTE +rm -rf '$data_new' +mkdir -p '$(dirname "$data_new")' # if the parent not exists +mv '$data_old' '$data_new' + +REMOTE +fi + +# Print configured message if changes where done to the configuration +if [ "$changes" ]; then echo configured >> "$__messages_out" fi @@ -208,6 +256,6 @@ if [ "$install" ]; then fi # Disable maintainer mode -if [ "$install" ] || [ "$upgrade" ] || [ "$changes" ]; then +if [ "$_maintainer_mode_on" = "yes" ]; then occ maintenance:mode --off fi diff --git a/type/__nextcloud/man.rst b/type/__nextcloud/man.rst index e958a82..2bff614 100644 --- a/type/__nextcloud/man.rst +++ b/type/__nextcloud/man.rst @@ -81,6 +81,15 @@ admin-email The email address of the administrative user. This parameter has no effect if nextcloud will not be installed. +data-directory + This will set or change the data directory where nextcloud will keep all + its data, including the SQLite database if any. By default, it will be + saved in the ``data`` directory below the nextcloud directory. + + If this directory change, this type will move the old location to the new + one to preserve all data. This is not supported by upstream, as some apps + may not handle this. + database-type Sets the type of database that should be used as backend. Possible backends are: @@ -159,6 +168,11 @@ The type aborts if there is no webroot given as parameter and no could be detected by the type itself. Please set the webroot via `--webroot` or extend this type. +It may abort if the data directory can not be moved correctly. Then, the +nextcloud configuration is broken and must be resolved manually: Move the data +directory to the correct location or change the configuration to point to the +old destination and retry. + EXAMPLES -------- diff --git a/type/__nextcloud/map-conf-changes.sh b/type/__nextcloud/map-conf-changes.sh index 7d11728..caea3bd 100755 --- a/type/__nextcloud/map-conf-changes.sh +++ b/type/__nextcloud/map-conf-changes.sh @@ -84,13 +84,13 @@ conf_base() { # 3: conditional mandatory of this parameter; value "required" if true # 4: default value; will be used if parameter is absent conf_string() { - conf_base "$1" "$2" "$3" "$4" "set '%s' --type=string --value='%s'" + conf_base "$1" "$2" "$3" "set '%s' --type=string --value='%s'" "$4" } conf_number() { - conf_base "$1" "$2" "$3" "$4" "set '%s' --type=integer --value='%s'" + conf_base "$1" "$2" "$3" "set '%s' --type=integer --value='%s'" "$4" } conf_decimal() { - conf_base "$1" "$2" "$3" "$4" "set '%s' --type=double --value='%s'" + conf_base "$1" "$2" "$3" "set '%s' --type=double --value='%s'" "$4" } # Sets the nextcloud configuration option after a boolean cdist parameter. @@ -232,6 +232,6 @@ if [ -z "$install" ]; then ;; esac - # data-dir - conf_string data-directory datadirectory installdef "$(cat "$__object/explorer/installdir")/$__object_id/data" + # data-dir is handled in the gencode-remote + #conf_string data-directory datadirectory installdef "$(cat "$__object/explorer/installdir")/$__object_id/data" fi