diff --git a/conf/env.prod b/conf/env.prod index 4a62772..7b9d330 100644 --- a/conf/env.prod +++ b/conf/env.prod @@ -67,7 +67,7 @@ REVERSE_PROXY_TYPE=nginx # DATABASE_URL=postgresql://:@:/ # DATABASE_URL=postgresql://funkwhale:passw0rd@localhost:5432/funkwhale_database # Use the next one if you followed Debian installation guide -DATABASE_URL=postgresql://__DBUSER__:__DBPWD__@:5432/__DBNAME__ +DATABASE_URL=postgresql://__DB_USER__:__DB_PWD__@:5432/__DB_NAME__ # Cache configuration # Examples: diff --git a/scripts/change_url b/scripts/change_url index a625ed1..7942d0e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,16 +24,22 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +key=$(ynh_app_setting_get --app=$app --key=key) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -70,14 +76,14 @@ fi #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-server" --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-worker" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-server" --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-worker" --action=stop --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --time --weight=1 +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -103,6 +109,23 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi +#================================================= +# MODIFY THE CONFIG FILE +#================================================= + +configfile="$final_path/code/config/.env" + +cp ../conf/env.prod "$configfile" + +ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$new_domain" --target_file="$configfile" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_name" --target_file="$configfile" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$configfile" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$configfile" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile" +ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile" + #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/install b/scripts/install index a2135e2..c635e79 100644 --- a/scripts/install +++ b/scripts/install @@ -56,7 +56,7 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." +ynh_script_progression --message="Finding an available port..." # Find a free port port=$(ynh_find_port --port=5000) @@ -148,20 +148,21 @@ redis_db=$(ynh_redis_get_free_db) ynh_app_setting_set --app=$app --key=key --value=$key ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db -ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$configfile" -ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$configfile" -ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$configfile" -ynh_replace_string --match_string="__DBNAME__" --replace_string="$app" --target_file="$configfile" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile" -ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile" +ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$configfile" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_name" --target_file="$configfile" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$configfile" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$configfile" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile" +ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile" #================================================= # CONFIGURE ADMIN USER #================================================= -admin_mail=$(ynh_user_get_info --username="$admin" --key="mail") +admin_mail=$(ynh_user_get_info --username=$admin --key=mail) + ( set +o nounset source "$final_path/code/virtualenv/bin/activate" @@ -182,7 +183,7 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key="mail") ynh_script_progression --message="Configuring a systemd service..." cp ../conf/funkwhale.target "/etc/systemd/system/$app.target" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.target" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.target" # Create a dedicated systemd config ynh_add_systemd_config --service="$app-server" --template="funkwhale-server.service" @@ -236,14 +237,12 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failrege #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." # Make app public if necessary or protect it if [ $is_public -eq 1 ] then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission "main" --add "visitors" + ynh_permission_update --permission="main" --add="visitors" fi #================================================= diff --git a/scripts/remove b/scripts/remove index 86231cb..c3bf02f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -53,9 +53,9 @@ fi #================================================= ynh_script_progression --message="Stopping and removing the systemd service" -ynh_systemd_action --action="stop" --service_name="${app}-beat" -ynh_systemd_action --action="stop" --service_name="${app}-server" -ynh_systemd_action --action="stop" --service_name="${app}-worker" +ynh_systemd_action --action=stop --service_name="${app}-beat" +ynh_systemd_action --action=stop --service_name="${app}-server" +ynh_systemd_action --action=stop --service_name="${app}-worker" # Remove the dedicated systemd config ynh_remove_systemd_config --service="$app-server" diff --git a/scripts/restore b/scripts/restore index 7871816..a75c682 100644 --- a/scripts/restore +++ b/scripts/restore @@ -148,9 +148,9 @@ yunohost service add "$app-beat" --log="/var/log/$app/beat.log" #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-server" --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action=start --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-server" --action=start --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-worker" --action=start --log_path="/var/log/$app/$app.log" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 1ea95f0..9f20966 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -52,6 +52,13 @@ if [ ! -d "$final_path/code/" ]; then ynh_app_setting_set --app="$app" --key=code_migration --value=1 fi +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -165,9 +172,9 @@ ynh_app_setting_set --app="$app" --key=key --value="$key" ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$configfile" -ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$configfile" -ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$configfile" -ynh_replace_string --match_string="__DBNAME__" --replace_string="$app" --target_file="$configfile" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_name" --target_file="$configfile" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$configfile" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$configfile" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile" ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile" @@ -220,7 +227,7 @@ ynh_store_file_checksum --file="$configfile" ynh_script_progression --message="Upgrading systemd configuration..." cp ../conf/funkwhale.target "/etc/systemd/system/$app.target" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.target" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.target" # Create a dedicated systemd config ynh_add_systemd_config --service="$app-server" --template="funkwhale-server.service" @@ -259,9 +266,9 @@ yunohost service add "$app-beat" --log="/var/log/$app/beat.log" #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-server" --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-worker" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action=start --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-server" --action=start --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-worker" --action=start --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX