1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wekan_ynh.git synced 2024-09-03 20:36:09 +02:00

Adding a db_name variable

Sanitize before being used: $(ynh_sanitize_dbid $app)
This commit is contained in:
yalh76 2019-02-05 21:57:12 +01:00
parent 48373305e6
commit afa9e6d452
5 changed files with 47 additions and 15 deletions

View file

@ -13,6 +13,10 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -24,6 +28,7 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
@ -39,5 +44,5 @@ ynh_backup "/etc/systemd/system/$app.service"
# BACKUP OF MONGODB # BACKUP OF MONGODB
#================================================= #=================================================
mongodump --db "$app" -o "./dump" mongodump --db "$db_name" -o "./dump"

View file

@ -101,6 +101,32 @@ ynh_install_nodejs 8.9.3
ynh_print_info "Installing mongodb dependencies ..." ynh_print_info "Installing mongodb dependencies ..."
ynh_install_app_dependencies "mongodb mongodb-server" ynh_install_app_dependencies "mongodb mongodb-server"
#=================================================
# Start MONGODB
#=================================================
# Start mogodb
ynh_print_info "Starting mongodb ..."
systemctl enable mongodb
systemctl restart mongodb
#=================================================
# CREATE A MONGODB DATABASE
#=================================================
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
### The password will be stored as 'mysqlpwd' into the app settings,
### and will be available as $db_pwd
### If you're not using these lines:
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
#ynh_mysql_setup_db $db_name $db_name
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -145,15 +171,6 @@ pushd $final_path/programs/server
npm install npm install
popd popd
#=================================================
# Start MONGODB
#=================================================
# Start mogodb
ynh_print_info "Starting mongodb ..."
systemctl enable mongodb
systemctl restart mongodb
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
@ -172,7 +189,7 @@ systemctl restart mongodb
ynh_print_info "Adding wekan systemd service ..." ynh_print_info "Adding wekan systemd service ..."
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__DB_NAME__" "$app" "../conf/systemd.service" ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
ynh_replace_string "__URI__" "$path_url" "../conf/systemd.service" ynh_replace_string "__URI__" "$path_url" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service" ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service"

View file

@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
readonly app=$YNH_APP_INSTANCE_NAME readonly app=$YNH_APP_INSTANCE_NAME
readonly domain=$(ynh_app_setting_get "$app" domain) readonly domain=$(ynh_app_setting_get "$app" domain)
db_name=$(ynh_app_setting_get $app db_name)
readonly final_path=$(ynh_app_setting_get "$app" final_path) readonly final_path=$(ynh_app_setting_get "$app" final_path)
#================================================= #=================================================
@ -38,7 +39,7 @@ fi
#================================================= #=================================================
# REMOVE DB # REMOVE DB
#================================================= #=================================================
mongo $app --eval "db.dropDatabase()" mongo $db_name --eval "db.dropDatabase()"
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES

View file

@ -28,6 +28,7 @@ domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
port=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
@ -66,7 +67,7 @@ ynh_install_app_dependencies "mongodb mongodb-server"
# Start mogodb # Start mogodb
systemctl enable mongodb systemctl enable mongodb
systemctl start mongodb systemctl start mongodb
mongorestore --db $app ./dump/$app mongorestore --db $db_name ./dump/$app
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP

View file

@ -20,8 +20,16 @@ domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
if [ -z "$db_name" ]
then
db_name=$app
ynh_app_setting_set "$app" db_name "$db_name"
fi
#================================================= #=================================================
# Check version # Check version
#================================================= #=================================================
@ -55,7 +63,7 @@ if ynh_version_gt "0.77-2" "${previous_version}" ; then
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__DB_NAME__" "$app" "../conf/systemd.service" ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
ynh_replace_string "__URI__" "$path_url/" "../conf/systemd.service" ynh_replace_string "__URI__" "$path_url/" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service" ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service"
@ -76,7 +84,7 @@ if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then
nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__DB_NAME__" "$app" "../conf/systemd.service" ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service"
ynh_replace_string "__URI__" "$path_url/" "../conf/systemd.service" ynh_replace_string "__URI__" "$path_url/" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service" ynh_replace_string "__DOMAIN__" "$domain" "../conf/systemd.service"