change_url 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # RETRIEVE ARGUMENTS
  11. #=================================================
  12. old_domain=$YNH_APP_OLD_DOMAIN
  13. old_path=$YNH_APP_OLD_PATH
  14. new_domain=$YNH_APP_NEW_DOMAIN
  15. new_path=$YNH_APP_NEW_PATH
  16. app=$YNH_APP_INSTANCE_NAME
  17. #=================================================
  18. # LOAD SETTINGS
  19. #=================================================
  20. ynh_script_progression --message="Loading installation settings..." --weight=1
  21. # Needed for helper "ynh_add_nginx_config"
  22. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  23. #=================================================
  24. # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
  25. #=================================================
  26. ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
  27. # Backup the current version of the app
  28. ynh_backup_before_upgrade
  29. ynh_clean_setup () {
  30. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
  31. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  32. # Restore it if the upgrade fails
  33. ynh_restore_upgradebackup
  34. }
  35. # Exit if an error occurs during the execution of the script
  36. ynh_abort_if_errors
  37. #=================================================
  38. # CHECK WHICH PARTS SHOULD BE CHANGED
  39. #=================================================
  40. change_domain=0
  41. if [ "$old_domain" != "$new_domain" ]
  42. then
  43. change_domain=1
  44. fi
  45. change_path=0
  46. if [ "$old_path" != "$new_path" ]
  47. then
  48. change_path=1
  49. fi
  50. #=================================================
  51. # MODIFY URL IN NGINX CONF
  52. #=================================================
  53. ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
  54. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  55. # Change the path in the NGINX config file
  56. if [ $change_path -eq 1 ]
  57. then
  58. # Make a backup of the original NGINX config file if modified
  59. ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
  60. # Set global variables for NGINX helper
  61. domain="$old_domain"
  62. path_url="$new_path"
  63. # Create a dedicated NGINX config
  64. ynh_add_nginx_config
  65. fi
  66. # Change the domain for NGINX
  67. if [ $change_domain -eq 1 ]
  68. then
  69. # Delete file checksum for the old conf file location
  70. ynh_delete_file_checksum --file="$nginx_conf_path"
  71. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  72. # Store file checksum for the new config file location
  73. ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  74. fi
  75. #=================================================
  76. # RELOAD NGINX
  77. #=================================================
  78. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  79. ynh_systemd_action --service_name=nginx --action=reload
  80. #=================================================
  81. # END OF SCRIPT
  82. #=================================================
  83. ynh_script_progression --message="Change of URL completed for $app" --last