change_url 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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=2
  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=11
  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. # ACTIVATE MAINTENANCE MODE
  39. #=================================================
  40. ynh_script_progression --message="Activating maintenance mode..." --weight=1
  41. path_url=$old_path
  42. domain=$old_domain
  43. ynh_maintenance_mode_ON
  44. #=================================================
  45. # CHECK WHICH PARTS SHOULD BE CHANGED
  46. #=================================================
  47. change_domain=0
  48. if [ "$old_domain" != "$new_domain" ]
  49. then
  50. change_domain=1
  51. fi
  52. change_path=0
  53. if [ "$old_path" != "$new_path" ]
  54. then
  55. change_path=1
  56. fi
  57. #=================================================
  58. # STANDARD MODIFICATIONS
  59. #=================================================
  60. # MODIFY URL IN NGINX CONF
  61. #=================================================
  62. ynh_script_progression --message="Updating NGINX web server configuration..." --weight=4
  63. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  64. # Change the path in the NGINX config file
  65. if [ $change_path -eq 1 ]
  66. then
  67. # Make a backup of the original NGINX config file if modified
  68. ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
  69. # Set global variables for NGINX helper
  70. domain="$old_domain"
  71. path_url="$new_path"
  72. # Create a dedicated NGINX config
  73. ynh_add_nginx_config
  74. fi
  75. # Change the domain for NGINX
  76. if [ $change_domain -eq 1 ]
  77. then
  78. # Delete file checksum for the old conf file location
  79. ynh_delete_file_checksum --file="$nginx_conf_path"
  80. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  81. # Store file checksum for the new config file location
  82. ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  83. fi
  84. #=================================================
  85. # GENERIC FINALISATION
  86. #=================================================
  87. # RELOAD NGINX
  88. #=================================================
  89. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  90. ynh_systemd_action --service_name=nginx --action=reload
  91. #=================================================
  92. # DEACTIVE MAINTENANCE MODE
  93. #=================================================
  94. ynh_script_progression --message="Disabling maintenance mode..." --weight=5
  95. path_url=$old_path
  96. domain=$old_domain
  97. ynh_maintenance_mode_OFF
  98. #=================================================
  99. # END OF SCRIPT
  100. #=================================================
  101. ynh_script_progression --message="Change of URL completed for $app" --last