1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/my_webapp_ynh.git synced 2024-09-03 19:46:26 +02:00
my_webapp_ynh/scripts/actions/create_database
2020-03-25 20:46:16 +01:00

64 lines
2 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
#=================================================
# SPECIFIC ACTION
#=================================================
# REMOVE THE PREVIOUS DATABASE
#=================================================
ynh_script_progression --message="Removing the previous database..." --weight=6
if [ $with_mysql -eq 1 ]
then
yunohost app action run $app remove_database
fi
#=================================================
# CREATE A NEW DATABASE
#=================================================
ynh_script_progression --message="Creating a new database..." --weight=4
db_name=$(ynh_sanitize_dbid --db_name=$app)
# Reuse the previous password if existing
db_pwd=$(grep "pass:" "$final_path/db_access.txt" | cut -d' ' -f2 2> /dev/null)
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd
echo -e "# MySQL Database
name: ${db_name}\nuser: ${db_name}\npass: ${db_pwd}" > "$final_path/db_access.txt"
# Update the config of the app
ynh_app_setting_set --app=$app --key=with_mysql --value=1
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last