change_url 3.6 KB

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