change_url 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. ynh_script_progression --message="Retrieve arguments from the manifest"
  13. old_domain=$YNH_APP_OLD_DOMAIN
  14. old_path=$YNH_APP_OLD_PATH
  15. new_domain=$YNH_APP_NEW_DOMAIN
  16. new_path=$YNH_APP_NEW_PATH
  17. app=$YNH_APP_INSTANCE_NAME
  18. #=================================================
  19. # LOAD SETTINGS
  20. #=================================================
  21. ynh_script_progression --message="Load settings" --weight=2
  22. final_path=$(ynh_app_setting_get $app final_path)
  23. #=================================================
  24. # BACKUP BEFORE UPGRADE 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="Activate maintenance mode"
  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. # MANAGE FAILURE OF THE SCRIPT
  59. #=================================================
  60. # Exit if an error occurs during the execution of the script
  61. ynh_abort_if_errors
  62. #=================================================
  63. # STANDARD MODIFICATIONS
  64. #=================================================
  65. # MODIFY URL IN NGINX CONF
  66. #=================================================
  67. ynh_script_progression --message="Modify url in nginx configuration" --weight=4
  68. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  69. # Change the path in the nginx config file
  70. if [ $change_path -eq 1 ]
  71. then
  72. # Make a backup of the original nginx config file if modified
  73. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  74. # Set global variables for nginx helper
  75. domain="$old_domain"
  76. path_url="$new_path"
  77. # Store path_url setting
  78. ynh_app_setting_set $app path_url "$path_url"
  79. # Create a dedicated nginx config
  80. ynh_add_nginx_config
  81. fi
  82. # Change the domain for nginx
  83. if [ $change_domain -eq 1 ]
  84. then
  85. # Delete file checksum for the old conf file location
  86. ynh_delete_file_checksum "$nginx_conf_path"
  87. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  88. # Store file checksum for the new config file location
  89. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  90. fi
  91. #=================================================
  92. # GENERIC FINALISATION
  93. #=================================================
  94. # RELOAD NGINX
  95. #=================================================
  96. ynh_script_progression --message="Reload nginx"
  97. ynh_systemd_action --action=reload --service_name=nginx
  98. #=================================================
  99. # DEACTIVE MAINTENANCE MODE
  100. #=================================================
  101. ynh_script_progression --message="Disable maintenance mode" --weight=5
  102. path_url=$old_path
  103. domain=$old_domain
  104. ynh_maintenance_mode_OFF
  105. #=================================================
  106. # END OF SCRIPT
  107. #=================================================
  108. ynh_script_progression --message="Change of url completed" --last