From 5594b725eb83187e66289a8ce6c110b21bce251e Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Tue, 17 Nov 2020 10:38:12 +0100 Subject: [PATCH] Add change_url script --- check_process | 5 +-- issue_template.md | 6 +-- scripts/change_url | 105 +++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 2 +- scripts/upgrade | 2 +- 5 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 scripts/change_url diff --git a/check_process b/check_process index 9a5b893..25c2da1 100644 --- a/check_process +++ b/check_process @@ -20,10 +20,8 @@ upgrade=1 from_commit=bd2c87a6fd4212771f9c06e7965598a5ea744ffc backup_restore=1 multi_instance=1 - # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. - # incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels # If the level 5 (Package linter) is forced to 1. Please add justifications here. Level 5=auto @@ -34,4 +32,3 @@ Notification=none ; commit=CommitHash name=Name and date of the commit. manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - diff --git a/issue_template.md b/issue_template.md index 2c9be53..72057cf 100644 --- a/issue_template.md +++ b/issue_template.md @@ -7,7 +7,7 @@ about: Create a report to help us debug, it would be nice to fill the template a **How to post a meaningful bug report** 1. *Read this whole template first.* 2. *Determine if you are on the right place:* - - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* - *Otherwise, the issue may be due to Framagames itself. Refer to its documentation or repository for help.* - *If you have a doubt, post here, we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* @@ -34,8 +34,8 @@ about: Create a report to help us debug, it would be nice to fill the template a - *If you used the webadmin, please perform the equivalent command from the CLI first.* - *If the error occurs in your browser, explain what you did:* 1. *Go to '...'* - 2. *Click on '....'* - 3. *Scroll down to '....'* + 2. *Click on '...'* + 3. *Scroll down to '...'* 4. *See error* **Expected behavior** diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..dfa4e60 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,105 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +#================================================= +# 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 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating nginx web server configuration..." --weight=2 + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINXweb server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index ea4f2b5..55c7285 100644 --- a/scripts/install +++ b/scripts/install @@ -80,7 +80,7 @@ ynh_add_fpm_config ynh_script_progression --message="Securing files and directories..." # Set permissions to app files -chmod 775 -R $final_path +chmod -R 775 $final_path chown -hR www-data:www-data $final_path #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2ec70fe..b1b50a0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -107,7 +107,7 @@ ynh_add_fpm_config ynh_script_progression --message="Securing files and directories..." # Set permissions on app files -chmod 775 -R $final_path +chmod -R 775 $final_path chown -hR www-data:www-data $final_path #=================================================