change_url 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
  35. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  36. # Restore it if the upgrade fails
  37. ynh_restore_upgradebackup
  38. }
  39. # Exit if an error occurs during the execution of the script
  40. ynh_abort_if_errors
  41. #=================================================
  42. # CHECK WHICH PARTS SHOULD BE CHANGED
  43. #=================================================
  44. change_domain=0
  45. if [ "$old_domain" != "$new_domain" ]
  46. then
  47. change_domain=1
  48. fi
  49. change_path=0
  50. if [ "$old_path" != "$new_path" ]
  51. then
  52. change_path=1
  53. fi
  54. #=================================================
  55. # STANDARD MODIFICATIONS
  56. #=================================================
  57. # MODIFY URL IN NGINX CONF
  58. #=================================================
  59. ynh_script_progression --message="Updating NGINX web server configuration..."
  60. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  61. # Change the path in the NGINX config file
  62. if [ $change_path -eq 1 ]
  63. then
  64. # Make a backup of the original NGINX config file if modified
  65. ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
  66. # Set global variables for NGINX helper
  67. domain="$old_domain"
  68. path_url="$new_path"
  69. # Create a dedicated NGINX config
  70. ynh_add_nginx_config
  71. fi
  72. # Change the domain for NGINX
  73. if [ $change_domain -eq 1 ]
  74. then
  75. # Delete file checksum for the old conf file location
  76. ynh_delete_file_checksum --file="$nginx_conf_path"
  77. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  78. # Store file checksum for the new config file location
  79. ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  80. fi
  81. #=================================================
  82. # SPECIFIC MODIFICATIONS
  83. #=================================================
  84. # ...
  85. #=================================================
  86. #=================================================
  87. # GENERIC FINALISATION
  88. #=================================================
  89. # RELOAD NGINX
  90. #=================================================
  91. ynh_script_progression --message="Reloading NGINX web server..."
  92. ynh_systemd_action --service_name=nginx --action=reload
  93. #=================================================
  94. # END OF SCRIPT
  95. #=================================================
  96. ynh_script_progression --message="Change of URL completed for $app"