change_url 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  22. #=================================================
  23. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  24. #=================================================
  25. ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=11
  26. # Backup the current version of the app
  27. ynh_backup_before_upgrade
  28. ynh_clean_setup () {
  29. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
  30. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  31. # restore it if the upgrade fails
  32. ynh_restore_upgradebackup
  33. }
  34. # Exit if an error occurs during the execution of the script
  35. ynh_abort_if_errors
  36. #=================================================
  37. # ACTIVATE MAINTENANCE MODE
  38. #=================================================
  39. ynh_script_progression --message="Activating maintenance mode..."
  40. path_url=$old_path
  41. domain=$old_domain
  42. ynh_maintenance_mode_ON
  43. #=================================================
  44. # CHECK WHICH PARTS SHOULD BE CHANGED
  45. #=================================================
  46. change_domain=0
  47. if [ "$old_domain" != "$new_domain" ]
  48. then
  49. change_domain=1
  50. fi
  51. change_path=0
  52. if [ "$old_path" != "$new_path" ]
  53. then
  54. change_path=1
  55. fi
  56. #=================================================
  57. # STANDARD MODIFICATIONS
  58. #=================================================
  59. # MODIFY URL IN NGINX CONF
  60. #=================================================
  61. ynh_script_progression --message="Updating NGINX web server configuration..." --weight=4
  62. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  63. # Change the path in the nginx config file
  64. if [ $change_path -eq 1 ]
  65. then
  66. # Make a backup of the original nginx config file if modified
  67. ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
  68. # Set global variables for nginx helper
  69. domain="$old_domain"
  70. path_url="$new_path"
  71. # Create a dedicated nginx config
  72. ynh_add_nginx_config
  73. fi
  74. # Change the domain for nginx
  75. if [ $change_domain -eq 1 ]
  76. then
  77. # Delete file checksum for the old conf file location
  78. ynh_delete_file_checksum --file="$nginx_conf_path"
  79. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  80. # Store file checksum for the new config file location
  81. ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  82. fi
  83. #=================================================
  84. # GENERIC FINALISATION
  85. #=================================================
  86. # RELOAD NGINX
  87. #=================================================
  88. ynh_script_progression --message="Reloading NGINX web server..."
  89. ynh_systemd_action --service_name=nginx --action=reload
  90. #=================================================
  91. # DEACTIVE MAINTENANCE MODE
  92. #=================================================
  93. ynh_script_progression --message="Disabling maintenance mode..." --weight=5
  94. path_url=$old_path
  95. domain=$old_domain
  96. ynh_maintenance_mode_OFF
  97. #=================================================
  98. # END OF SCRIPT
  99. #=================================================
  100. ynh_script_progression --message="Change of URL completed for $app" --last