mirror of
https://github.com/YunoHost-Apps/wallabag2_ynh.git
synced 2024-10-01 13:35:06 +02:00
fix #32, use latest mysql helpers
This commit is contained in:
parent
3439a80c22
commit
b0812d6adc
4 changed files with 71 additions and 19 deletions
|
@ -178,9 +178,61 @@ ynh_remove_app_dependencies () {
|
||||||
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if a mysql user exists
|
||||||
|
#
|
||||||
|
# usage: ynh_mysql_user_exists user
|
||||||
|
# | arg: user - the user for which to check existence
|
||||||
|
function ynh_mysql_user_exists()
|
||||||
|
{
|
||||||
|
local user=$1
|
||||||
|
if [[ -z $(ynh_mysql_execute_as_root "SELECT User from mysql.user WHERE User = '$user';") ]]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Correct the name given in argument for mariadb
|
# Create a database, an user and its password. Then store the password in the app's config
|
||||||
# Avoid invalid characters in your database name
|
#
|
||||||
|
# After executing this helper, the password of the created database will be available in $db_pwd
|
||||||
|
# It will also be stored as "mysqlpwd" into the app settings.
|
||||||
|
#
|
||||||
|
# usage: ynh_mysql_setup_db user name
|
||||||
|
# | arg: user - Owner of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
ynh_mysql_setup_db () {
|
||||||
|
local db_user="$1"
|
||||||
|
local db_name="$2"
|
||||||
|
db_pwd=$(ynh_string_random) # Generate a random password
|
||||||
|
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
|
||||||
|
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove a database if it exists, and the associated user
|
||||||
|
#
|
||||||
|
# usage: ynh_mysql_remove_db user name
|
||||||
|
# | arg: user - Owner of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
ynh_mysql_remove_db () {
|
||||||
|
local db_user="$1"
|
||||||
|
local db_name="$2"
|
||||||
|
local mysql_root_password=$(sudo cat $MYSQL_ROOT_PWD_FILE)
|
||||||
|
if mysqlshow -u root -p$mysql_root_password | grep -q "^| $db_name"; then # Check if the database exists
|
||||||
|
echo "Removing database $db_name" >&2
|
||||||
|
ynh_mysql_drop_db $db_name # Remove the database
|
||||||
|
else
|
||||||
|
echo "Database $db_name not found" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove mysql user if it exists
|
||||||
|
if $(ynh_mysql_user_exists $db_user); then
|
||||||
|
ynh_mysql_drop_user $db_user
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sanitize a string intended to be the name of a database
|
||||||
|
# (More specifically : replace - and . by _)
|
||||||
#
|
#
|
||||||
# Exemple: dbname=$(ynh_sanitize_dbid $app)
|
# Exemple: dbname=$(ynh_sanitize_dbid $app)
|
||||||
#
|
#
|
||||||
|
@ -188,7 +240,7 @@ ynh_remove_app_dependencies () {
|
||||||
# | arg: name - name to correct/sanitize
|
# | arg: name - name to correct/sanitize
|
||||||
# | ret: the corrected name
|
# | ret: the corrected name
|
||||||
ynh_sanitize_dbid () {
|
ynh_sanitize_dbid () {
|
||||||
dbid=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
|
dbid=${1//[-.]/_} # We should avoid having - and . in the name of databases. They are replaced by _
|
||||||
echo $dbid
|
echo $dbid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,14 +60,11 @@ db_user="$db_name"
|
||||||
|
|
||||||
# Generate random DES key & password
|
# Generate random DES key & password
|
||||||
deskey=$(ynh_string_random 24)
|
deskey=$(ynh_string_random 24)
|
||||||
dbpass=$(ynh_string_random)
|
|
||||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
||||||
ynh_app_setting_set "$app" deskey "$deskey"
|
ynh_app_setting_set "$app" deskey "$deskey"
|
||||||
ynh_app_setting_set "$app" db_name "$db_name"
|
ynh_app_setting_set "$app" db_name "$db_name"
|
||||||
|
|
||||||
# Initialize database
|
# Initialize database
|
||||||
ynh_mysql_create_db "$db_name" "$db_user" "$dbpass"
|
ynh_mysql_setup_db "$db_user" "$db_name"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -92,7 +89,7 @@ wb_conf="${TMPDIR}/app/config/parameters.yml"
|
||||||
cp ../conf/parameters.yml "$wb_conf"
|
cp ../conf/parameters.yml "$wb_conf"
|
||||||
ynh_replace_string "{DBNAME}" "${db_name}" "$wb_conf"
|
ynh_replace_string "{DBNAME}" "${db_name}" "$wb_conf"
|
||||||
ynh_replace_string "{DBUSER}" "${db_user}" "$wb_conf"
|
ynh_replace_string "{DBUSER}" "${db_user}" "$wb_conf"
|
||||||
ynh_replace_string "{DBPASS}" "${dbpass}" "$wb_conf"
|
ynh_replace_string "{DBPASS}" "${db_pwd}" "$wb_conf"
|
||||||
ynh_replace_string "{DESKEY}" "${deskey}" "$wb_conf"
|
ynh_replace_string "{DESKEY}" "${deskey}" "$wb_conf"
|
||||||
|
|
||||||
# Install files and set permissions
|
# Install files and set permissions
|
||||||
|
@ -118,7 +115,7 @@ done
|
||||||
exec_console $app "$final_path" fos:user:promote --super "$admin"
|
exec_console $app "$final_path" fos:user:promote --super "$admin"
|
||||||
|
|
||||||
# Configure Wallabag instance URL
|
# Configure Wallabag instance URL
|
||||||
ynh_mysql_connect_as "$db_name" "$dbpass" "$db_user" <<< "UPDATE craue_config_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
|
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user" <<< "UPDATE craue_config_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
|
|
@ -33,8 +33,7 @@ ynh_remove_app_dependencies
|
||||||
# REMOVE THE MYSQL DB
|
# REMOVE THE MYSQL DB
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_mysql_drop_db "$db_name"
|
ynh_mysql_remove_db "$app" "$db_name"
|
||||||
ynh_mysql_drop_user "$app"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
|
|
|
@ -32,7 +32,7 @@ if [ -z "$path_url" ] ; then
|
||||||
ynh_app_setting_set $app path_url "$path_url"
|
ynh_app_setting_set $app path_url "$path_url"
|
||||||
fi
|
fi
|
||||||
path_url=$(ynh_normalize_url_path $path_url)
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
deskey=$(ynh_app_setting_get "$app" deskey)
|
deskey=$(ynh_app_setting_get "$app" deskey)
|
||||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||||
# Compatibility with previous version
|
# Compatibility with previous version
|
||||||
|
@ -53,11 +53,15 @@ db_user="$db_name"
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup_before_upgrade # Backup the current version of the app
|
# Use prior backup and restore on error only if backup feature
|
||||||
ynh_clean_setup () {
|
# exists on installed instance
|
||||||
ynh_backup_after_failed_upgrade
|
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
|
||||||
}
|
ynh_backup_before_upgrade # Backup the current version of the app
|
||||||
ynh_abort_if_errors # Stop script if an error is detected
|
ynh_clean_setup () {
|
||||||
|
ynh_backup_after_failed_upgrade
|
||||||
|
}
|
||||||
|
ynh_abort_if_errors # Stop script if an error is detected
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
|
@ -88,7 +92,7 @@ wb_conf="${TMPDIR}/app/config/parameters.yml"
|
||||||
cp ../conf/parameters.yml "$wb_conf"
|
cp ../conf/parameters.yml "$wb_conf"
|
||||||
ynh_replace_string "{DBNAME}" "${db_name}" "$wb_conf"
|
ynh_replace_string "{DBNAME}" "${db_name}" "$wb_conf"
|
||||||
ynh_replace_string "{DBUSER}" "${db_user}" "$wb_conf"
|
ynh_replace_string "{DBUSER}" "${db_user}" "$wb_conf"
|
||||||
ynh_replace_string "{DBPASS}" "${dbpass}" "$wb_conf"
|
ynh_replace_string "{DBPASS}" "${db_pwd}" "$wb_conf"
|
||||||
ynh_replace_string "{DESKEY}" "${deskey}" "$wb_conf"
|
ynh_replace_string "{DESKEY}" "${deskey}" "$wb_conf"
|
||||||
|
|
||||||
# Replace files and set permissions
|
# Replace files and set permissions
|
||||||
|
@ -103,7 +107,7 @@ exec_console $app "${final_path}" doctrine:migrations:migrate
|
||||||
exec_console $app "${final_path}" cache:clear
|
exec_console $app "${final_path}" cache:clear
|
||||||
|
|
||||||
# Configure Wallabag instance URL
|
# Configure Wallabag instance URL
|
||||||
ynh_mysql_connect_as "$db_name" "$dbpass" "$db_user" <<< "UPDATE craue_config_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
|
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user" <<< "UPDATE craue_config_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
|
Loading…
Add table
Reference in a new issue