__nextcloud: make some db parameters mandatory
Some database parameters are required if the type is `mysql` or `pgsql`. Also, the variants of the parameter --database-type decreased to those that work with the configuration, as it is directly mapped to the parameter. The functions in `map-conf-changes.sh` where extended to support the conditional mandatory argument to throw an error if this parameter is set.
This commit is contained in:
parent
b6f4da7692
commit
f5c988c0f2
3 changed files with 75 additions and 40 deletions
|
@ -97,27 +97,28 @@ if ! grep -q -F "installed = 1" "$__object/explorer/config"; then
|
|||
# argument construction
|
||||
occ_install_args=""
|
||||
|
||||
# Database
|
||||
# Error function if value not found
|
||||
die_err() {
|
||||
echo "parameter not found but required; can't continue!!" >&2
|
||||
exit 1
|
||||
}
|
||||
# Database setup for mysql and pgsql
|
||||
db_setup() {
|
||||
if ! [ -f "$__object/parameter/db-host" ]; then
|
||||
echo "no hostname given! can't proceed." >&2
|
||||
exit 3
|
||||
fi
|
||||
occ_install_args="$occ_install_args --database '$1'"
|
||||
occ_install_args="$occ_install_args --database-host '$(cat "$__object/parameter/db-host")'"
|
||||
|
||||
db_name="$__object/parameter/database-name"
|
||||
if [ -f "$db_name" ]; then
|
||||
occ_install_args="$occ_install_args --database-name '$(cat "$db_name")'"
|
||||
fi
|
||||
db_user="$__object/parameter/database-user"
|
||||
if [ -f "$db_user" ]; then
|
||||
occ_install_args="$occ_install_args --database-user '$(cat "$db_user")'"
|
||||
fi
|
||||
db_pass="$__object/parameter/database-password"
|
||||
if [ -f "$db_pass" ]; then
|
||||
occ_install_args="$occ_install_args --database-pass '$(cat "$db_pass")'"
|
||||
db_host="$__object/parameter/database-host"
|
||||
if [ -f "$db_host" ]; then
|
||||
occ_install_args="$occ_install_args --database-host '$(cat "$db_host")'"
|
||||
fi
|
||||
|
||||
occ_install_args="$occ_install_args --database-name '$(cat "$__object/parameter/database-name" || die_err)'"
|
||||
occ_install_args="$occ_install_args --database-user '$(cat "$__object/parameter/database-user" || die_err)'"
|
||||
occ_install_args="$occ_install_args --database-pass '$(cat "$__object/parameter/database-password" || die_err)'"
|
||||
|
||||
db_prefix="$__object/parameter/database-prefix"
|
||||
if [ -f "$db_prefix" ]; then
|
||||
occ_install_args="$occ_install_args --database-table-prefix '$(cat "$db_prefix")'"
|
||||
|
@ -126,18 +127,18 @@ if ! grep -q -F "installed = 1" "$__object/explorer/config"; then
|
|||
|
||||
database_type="$(cat "$__object/parameter/database-type")"
|
||||
case "$database_type" in
|
||||
sqlite|sqlite3)
|
||||
sqlite3)
|
||||
occ_install_args="$occ_install_args --database sqlite"
|
||||
;;
|
||||
mysql|mariadb)
|
||||
mysql)
|
||||
db_setup mysql
|
||||
;;
|
||||
pgsql|postgres|postgresql)
|
||||
pgsql)
|
||||
db_setup pgsql
|
||||
;;
|
||||
|
||||
*)
|
||||
printf "Database type '%s' is unkown!\n" "" >&2
|
||||
printf "Database type '%s' is unkown!\n" "$database_type" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
@ -197,7 +198,7 @@ if [ "$install" ]; then
|
|||
|
||||
# variable accessible from the last $install if-clause
|
||||
case "$database_type" in
|
||||
mysql|mariadb)
|
||||
mysql)
|
||||
# only available for mysql
|
||||
occ db:convert-mysql-charset
|
||||
;;
|
||||
|
|
|
@ -74,8 +74,8 @@ host
|
|||
|
||||
admin-user
|
||||
The username of the administrative user which will be created while the
|
||||
installation. This parameter has no effect if nextcloud will not be
|
||||
installed.
|
||||
installation. If not set, nextcloud defaults to "admin". This parameter has
|
||||
no effect if nextcloud will not be installed.
|
||||
|
||||
admin-email
|
||||
The email address of the administrative user. This parameter has no effect
|
||||
|
@ -86,7 +86,7 @@ database-type
|
|||
are:
|
||||
|
||||
SQLite
|
||||
Use ``sqlite`` or ``sqlite3``. Saves everything in a database file
|
||||
Use ``sqlite3`` as value. Saves everything in a database file
|
||||
stored in the data directory. It is only recommended for very small
|
||||
installations or test environments from upstream.
|
||||
|
||||
|
@ -94,12 +94,12 @@ database-type
|
|||
database backend.*
|
||||
|
||||
MariaDB
|
||||
Use ``mysql`` or ``mariadb``. MariaDB and MySQL are threated the same
|
||||
Use ``mysql`` as value. MariaDB and MySQL are threated the same
|
||||
way. They are the recommended database backends recommended from
|
||||
upstream.
|
||||
|
||||
PostgreSQL
|
||||
Use ``pgsql``, ``postgres`` or ``postgresql``.
|
||||
Use ``pgsql`` as value.
|
||||
|
||||
**This parameter defaults to the SQLite database backend, as it is the
|
||||
simplest one to setup and do not require extra parameters.**
|
||||
|
@ -110,17 +110,22 @@ database-host
|
|||
``localhost:/path/to/socket``. If an non-standard port is used, set it
|
||||
after the hostname or ip address seperated by an colon (``:``).
|
||||
|
||||
If this value is not set, nextcloud defaults to the value ``localhost``.
|
||||
|
||||
database-name
|
||||
The name of the database to connect to.
|
||||
The name of the database to connect to. Required if MariaDB or PostgreSQL
|
||||
is used.
|
||||
|
||||
database-user
|
||||
The username to access the database.
|
||||
The username to access the database. Required if MariaDB or PostgreSQL is
|
||||
used.
|
||||
|
||||
database-password
|
||||
The password required to authorize the given user.
|
||||
The password required to authorize the given user. Required if MariaDB or
|
||||
PostgreSQL is used.
|
||||
|
||||
database-prefix
|
||||
The table prefix used by nextcloud. If nothing set, it defaults to
|
||||
The table prefix used by nextcloud. If nothing set, nextcloud defaults to
|
||||
``oc_``.
|
||||
|
||||
|
||||
|
|
|
@ -51,16 +51,23 @@ paramexist() {
|
|||
# Arguments:
|
||||
# 1: cdist type parameter name
|
||||
# 2: nextcloud config name
|
||||
# 3: occ printf pattern to set the value
|
||||
# 3: conditially mandatory argument, value "required" if true
|
||||
# 4: occ printf pattern to set the value
|
||||
conf_base() {
|
||||
if [ -f "$__object/parameter/$1" ]; then
|
||||
value="$(cat "$__object/parameter/$1")"
|
||||
if ! testparam "$2" "$value"; then
|
||||
# set it because it does not exist
|
||||
# shellcheck disable=SC2059 # $3 contains patterns
|
||||
printf "php occ config:system:$3\n" "$2" "$value"
|
||||
# shellcheck disable=SC2059 # $4 contains patterns
|
||||
printf "php occ config:system:$4\n" "$2" "$value"
|
||||
fi
|
||||
else
|
||||
if [ "$3" = "required" ]; then
|
||||
# error because the parameter should be set
|
||||
printf "Parameter '%s' not set by user, but required!\n" "$1" >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
if paramexist "$2"; then
|
||||
# remove it because it exists
|
||||
printf "php occ config:system:delete '%s'\n" "$2"
|
||||
|
@ -73,14 +80,15 @@ conf_base() {
|
|||
# Arguments:
|
||||
# 1: cdist type parameter name
|
||||
# 2: nextcloud config name
|
||||
# 3: conditional mandatory of this parameter; value "required" if true
|
||||
conf_string() {
|
||||
conf_base "$1" "$2" "set '%s' --type=string --value='%s'"
|
||||
conf_base "$1" "$2" "$3" "set '%s' --type=string --value='%s'"
|
||||
}
|
||||
conf_number() {
|
||||
conf_base "$1" "$2" "set '%s' --type=integer --value='%s'"
|
||||
conf_base "$1" "$2" "$3" "set '%s' --type=integer --value='%s'"
|
||||
}
|
||||
conf_decimal() {
|
||||
conf_base "$1" "$2" "set '%s' --type=double --value='%s'"
|
||||
conf_base "$1" "$2" "$3" "set '%s' --type=double --value='%s'"
|
||||
}
|
||||
|
||||
# Sets the nextcloud configuration option after a boolean cdist parameter.
|
||||
|
@ -110,6 +118,7 @@ conf_boolean() {
|
|||
# Arguments:
|
||||
# 1: cdist type parameter name
|
||||
# 2: nextcloud config name
|
||||
# 3: conditional mandatory of this parameter; value "required" if true
|
||||
conf_array() {
|
||||
if [ -f "$__object/parameter/$1" ]; then
|
||||
# reset array if installation is fresh
|
||||
|
@ -167,6 +176,12 @@ conf_array() {
|
|||
done < "$_dir/$2"
|
||||
fi
|
||||
else
|
||||
if [ "$3" = "required" ]; then
|
||||
# error because the parameter should be set
|
||||
printf "Parameter '%s' not set by user, but required!\n" "$1" >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# remove everything because we don't know which was set by the user
|
||||
if paramexist "$2"; then
|
||||
# remove the whole array
|
||||
|
@ -190,13 +205,27 @@ conf_array host trusted_domains
|
|||
|
||||
# Already set via the installer
|
||||
if [ -z "$install" ]; then
|
||||
# db
|
||||
conf_string database-type dbtype
|
||||
conf_string database-host dbhost # FIXME host included here (takes port also)
|
||||
conf_string database-name dbname
|
||||
conf_string database-user dbuser
|
||||
conf_string database-password dbpassword
|
||||
conf_string database-prefix dbtableprefix
|
||||
# database
|
||||
database_type="$(cat "$__object/parameter/database-type")"
|
||||
case "$database_type" in
|
||||
sqlite3)
|
||||
conf_string database-type dbtype
|
||||
;;
|
||||
|
||||
mysql|pgsql)
|
||||
conf_string database-type dbtype
|
||||
conf_string database-host dbhost
|
||||
conf_string database-name dbname required
|
||||
conf_string database-user dbuser required
|
||||
conf_string database-password dbpassword required
|
||||
conf_string database-prefix dbtableprefix
|
||||
;;
|
||||
|
||||
*)
|
||||
printf "Databasetype '%s' is unkown!\n" "$database_type" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
# data-dir
|
||||
conf_string data-directory datadirectory
|
||||
|
|
Loading…
Reference in a new issue