__nextcloud: move data directory if destination changes

The type now handles the case when the data directory will be moved to
an other location. To this, adjustment to the "maintainer mode" on
setting and the manpage.
This commit is contained in:
matze 2020-10-24 21:09:35 +02:00
parent 3bda4cf0c8
commit facb204749
3 changed files with 70 additions and 8 deletions

View file

@ -22,6 +22,28 @@ SU
SHELL 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<NF ? OFS : ""); return ret }
$1 == name { print ntostring(2); }
' "$__object/explorer/config"
}
# Get existing versions # Get existing versions
version_is="$( cat "$__object/explorer/version" )" version_is="$( cat "$__object/explorer/version" )"
version_should="$( cat "$__object/parameter/version" )" version_should="$( cat "$__object/parameter/version" )"
@ -60,7 +82,7 @@ cd '$updatedir'
chown '$user':'$group' -R '$tarballdir' chown '$user':'$group' -R '$tarballdir'
REMOTE REMOTE
occ maintenance:mode --on occ_maintainer_mode_on
cat << REMOTE cat << REMOTE
cp -pf '$installdir/config/config.php' '$tarballdir/config/config.php' cp -pf '$installdir/config/config.php' '$tarballdir/config/config.php'
@ -179,6 +201,7 @@ mkdir "$__object/files"
if [ -s "$__object/files/conf-cmds" ]; then if [ -s "$__object/files/conf-cmds" ]; then
# save that we did changes # save that we did changes
changes="yes" changes="yes"
occ_maintainer_mode_on
# print change commands incl. the switch of user context # print change commands incl. the switch of user context
# using -e to abort if the commands failed # using -e to abort if the commands failed
@ -186,8 +209,33 @@ if [ -s "$__object/files/conf-cmds" ]; then
printf "cd '%s'\n" "$installdir" printf "cd '%s'\n" "$installdir"
cat "$__object/files/conf-cmds" cat "$__object/files/conf-cmds"
printf "SU\n" printf "SU\n"
fi
# print a message
# Get the current and future data directory
data_old="$(getparam datadirectory)"
data_new="$(cat "$__object/parameter/data-directory" 2>/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" echo configured >> "$__messages_out"
fi fi
@ -208,6 +256,6 @@ if [ "$install" ]; then
fi fi
# Disable maintainer mode # Disable maintainer mode
if [ "$install" ] || [ "$upgrade" ] || [ "$changes" ]; then if [ "$_maintainer_mode_on" = "yes" ]; then
occ maintenance:mode --off occ maintenance:mode --off
fi fi

View file

@ -81,6 +81,15 @@ admin-email
The email address of the administrative user. This parameter has no effect The email address of the administrative user. This parameter has no effect
if nextcloud will not be installed. 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 database-type
Sets the type of database that should be used as backend. Possible backends Sets the type of database that should be used as backend. Possible backends
are: 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 detected by the type itself. Please set the webroot via `--webroot` or extend
this type. 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 EXAMPLES
-------- --------

View file

@ -84,13 +84,13 @@ conf_base() {
# 3: conditional mandatory of this parameter; value "required" if true # 3: conditional mandatory of this parameter; value "required" if true
# 4: default value; will be used if parameter is absent # 4: default value; will be used if parameter is absent
conf_string() { 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_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_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. # Sets the nextcloud configuration option after a boolean cdist parameter.
@ -232,6 +232,6 @@ if [ -z "$install" ]; then
;; ;;
esac esac
# data-dir # data-dir is handled in the gencode-remote
conf_string data-directory datadirectory installdef "$(cat "$__object/explorer/installdir")/$__object_id/data" #conf_string data-directory datadirectory installdef "$(cat "$__object/explorer/installdir")/$__object_id/data"
fi fi