Browse Source
add default_character_set parameter
convert-mysql-charset
Kay0u
5 years ago
No known key found for this signature in database
GPG Key ID: AAFEEB16CFA2AE2D
7 changed files with
76 additions and
4 deletions
-
scripts/_common.sh
-
scripts/_ynh_mysql_connect_as.sh
-
scripts/_ynh_mysql_dump_db.sh
-
scripts/backup
-
scripts/install
-
scripts/restore
-
scripts/upgrade
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# COMMON VARIABLES |
|
|
# COMMON VARIABLES |
|
|
|
|
|
@ -0,0 +1,34 @@ |
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
# Open a connection as a user |
|
|
|
|
|
# |
|
|
|
|
|
# example: ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;" |
|
|
|
|
|
# example: ynh_mysql_connect_as --user="user" --password="pass" --default_character_set="utf8mb4" < /path/to/file.sql |
|
|
|
|
|
# |
|
|
|
|
|
# usage: ynh_mysql_connect_as --user=user --password=password [--database=database] [--default_character_set=character-set] |
|
|
|
|
|
# | arg: -u, --user= - the user name to connect as |
|
|
|
|
|
# | arg: -p, --password= - the user password |
|
|
|
|
|
# | arg: -d, --database= - the database to connect to |
|
|
|
|
|
# | arg: -c, --default_character_set= - the charset to use |
|
|
|
|
|
# |
|
|
|
|
|
# Requires YunoHost version 2.2.4 or higher. |
|
|
|
|
|
ynh_mysql_connect_as() { |
|
|
|
|
|
# Declare an array to define the options of this helper. |
|
|
|
|
|
local legacy_args=updc |
|
|
|
|
|
local -A args_array=( [u]=user= [p]=password= [d]=database= [c]=default_character_set= ) |
|
|
|
|
|
local user |
|
|
|
|
|
local password |
|
|
|
|
|
local database |
|
|
|
|
|
local default_character_set |
|
|
|
|
|
# Manage arguments with getopts |
|
|
|
|
|
ynh_handle_getopts_args "$@" |
|
|
|
|
|
database="${database:-}" |
|
|
|
|
|
default_character_set="${default_character_set:-}" |
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$default_character_set" ] |
|
|
|
|
|
then |
|
|
|
|
|
default_character_set="--default-character-set=$default_character_set" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
mysql --user="$user" --password="$password" "$default_character_set" --batch "$database" |
|
|
|
|
|
} |
|
|
@ -0,0 +1,29 @@ |
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
# Dump a database |
|
|
|
|
|
# |
|
|
|
|
|
# example: ynh_mysql_dump_db --database=roundcube --default_character_set="utf8mb4" > ./dump.sql |
|
|
|
|
|
# |
|
|
|
|
|
# usage: ynh_mysql_dump_db --database=database |
|
|
|
|
|
# | arg: -d, --database= - the database name to dump |
|
|
|
|
|
# | arg: -c, --default_character_set= - the charset to use |
|
|
|
|
|
# | ret: the mysqldump output |
|
|
|
|
|
# |
|
|
|
|
|
# Requires YunoHost version 2.2.4 or higher. |
|
|
|
|
|
ynh_mysql_dump_db() { |
|
|
|
|
|
# Declare an array to define the options of this helper. |
|
|
|
|
|
local legacy_args=dc |
|
|
|
|
|
local -A args_array=( [d]=database= [c]=default_character_set= ) |
|
|
|
|
|
local database |
|
|
|
|
|
local default_character_set |
|
|
|
|
|
# Manage arguments with getopts |
|
|
|
|
|
ynh_handle_getopts_args "$@" |
|
|
|
|
|
default_character_set="${default_character_set:-}" |
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$default_character_set" ] |
|
|
|
|
|
then |
|
|
|
|
|
default_character_set="--default-character-set=$default_character_set" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
mysqldump --user="root" --password="$(cat $MYSQL_ROOT_PWD_FILE)" --single-transaction --skip-dump-date "$default_character_set" "$database" |
|
|
|
|
|
} |
|
|
@ -8,6 +8,7 @@ |
|
|
|
|
|
|
|
|
source ../settings/scripts/_common.sh |
|
|
source ../settings/scripts/_common.sh |
|
|
source /usr/share/yunohost/helpers |
|
|
source /usr/share/yunohost/helpers |
|
|
|
|
|
source ../settings/scripts/_ynh_mysql_dump_db.sh |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# MANAGE SCRIPT FAILURE |
|
|
# MANAGE SCRIPT FAILURE |
|
|
@ -56,7 +57,7 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" |
|
|
#================================================= |
|
|
#================================================= |
|
|
ynh_print_info --message="Backing up the MySQL database..." |
|
|
ynh_print_info --message="Backing up the MySQL database..." |
|
|
|
|
|
|
|
|
ynh_mysql_dump_db --database="$db_name" > db.sql |
|
|
|
|
|
|
|
|
ynh_mysql_dump_db --database="$db_name" --default_character_set="utf8mb4" > db.sql |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# SPECIFIC BACKUP |
|
|
# SPECIFIC BACKUP |
|
|
|
|
|
@ -8,6 +8,7 @@ |
|
|
|
|
|
|
|
|
source _common.sh |
|
|
source _common.sh |
|
|
source /usr/share/yunohost/helpers |
|
|
source /usr/share/yunohost/helpers |
|
|
|
|
|
source _ynh_mysql_connect_as.sh |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# MANAGE SCRIPT FAILURE |
|
|
# MANAGE SCRIPT FAILURE |
|
|
@ -250,7 +251,7 @@ ynh_replace_string --match_string="'overwrite.cli.url' => 'http://localhost'," - |
|
|
#================================================= |
|
|
#================================================= |
|
|
|
|
|
|
|
|
# Set the user as admin |
|
|
# Set the user as admin |
|
|
ynh_mysql_connect_as --user=$db_name --password="$db_pwd" --database=$db_name \ |
|
|
|
|
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password="$db_pwd" --database=$db_name --default_character_set="utf8mb4" \ |
|
|
<<< "INSERT INTO oc_group_user VALUES ('admin','$admin');" |
|
|
<<< "INSERT INTO oc_group_user VALUES ('admin','$admin');" |
|
|
# And delete admin user |
|
|
# And delete admin user |
|
|
exec_occ user:delete admin |
|
|
exec_occ user:delete admin |
|
|
|
|
|
@ -8,6 +8,7 @@ |
|
|
|
|
|
|
|
|
source ../settings/scripts/_common.sh |
|
|
source ../settings/scripts/_common.sh |
|
|
source /usr/share/yunohost/helpers |
|
|
source /usr/share/yunohost/helpers |
|
|
|
|
|
source ../settings/scripts/_ynh_mysql_connect_as.sh |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# MANAGE SCRIPT FAILURE |
|
|
# MANAGE SCRIPT FAILURE |
|
|
@ -73,7 +74,10 @@ ynh_script_progression --message="Restoring the MySQL database..." --weight=9 |
|
|
|
|
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) |
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) |
|
|
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd |
|
|
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd |
|
|
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql |
|
|
|
|
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password="$db_pwd" --database=$db_name \ |
|
|
|
|
|
<<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" |
|
|
|
|
|
|
|
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name --default_character_set="utf8mb4" < ./db.sql |
|
|
|
|
|
|
|
|
#================================================= |
|
|
#================================================= |
|
|
# RECREATE THE DEDICATED USER |
|
|
# RECREATE THE DEDICATED USER |
|
|
|
|
|
@ -221,7 +221,9 @@ then |
|
|
# Print the current version number of Nextcloud |
|
|
# Print the current version number of Nextcloud |
|
|
exec_occ -V |
|
|
exec_occ -V |
|
|
|
|
|
|
|
|
exec_occ db:convert-mysql-charset |
|
|
|
|
|
|
|
|
if [ "$(exec_occ config:system:get mysql.utf8mb4)" != "true" ]; then |
|
|
|
|
|
exec_occ db:convert-mysql-charset |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
# Upgrade may fail if this app is enabled |
|
|
# Upgrade may fail if this app is enabled |
|
|
# Take all apps enabled, and check if mail is one of them |
|
|
# Take all apps enabled, and check if mail is one of them |
|
|
|