change_url 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # CHECK THE SYNTAX OF THE PATHS
  19. #=================================================
  20. test -n "$old_path" || old_path="/"
  21. test -n "$new_path" || new_path="/"
  22. new_path=$(ynh_normalize_url_path $new_path)
  23. old_path=$(ynh_normalize_url_path $old_path)
  24. #=================================================
  25. # ACTIVATE MAINTENANCE MODE
  26. #=================================================
  27. path_url=$old_path
  28. domain=$old_domain
  29. ynh_maintenance_mode_ON
  30. #=================================================
  31. # CHECK WHICH PARTS SHOULD BE CHANGED
  32. #=================================================
  33. change_domain=0
  34. if [ "$old_domain" != "$new_domain" ]
  35. then
  36. change_domain=1
  37. fi
  38. change_path=0
  39. if [ "$old_path" != "$new_path" ]
  40. then
  41. change_path=1
  42. fi
  43. #=================================================
  44. # MANAGE FAILURE OF THE SCRIPT
  45. #=================================================
  46. # Exit if an error occurs during the execution of the script
  47. ynh_abort_if_errors
  48. #=================================================
  49. # STANDARD MODIFICATIONS
  50. #=================================================
  51. # MODIFY URL IN NGINX CONF
  52. #=================================================
  53. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  54. # Change the path in the nginx config file
  55. if [ $change_path -eq 1 ]
  56. then
  57. # Make a backup of the original nginx config file if modified
  58. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  59. # Set global variables for nginx helper
  60. domain="$old_domain"
  61. path_url="$new_path"
  62. # Store path_url setting
  63. ynh_app_setting_set $app path_url "$path_url"
  64. # Create a dedicated nginx config
  65. ynh_add_nginx_config
  66. fi
  67. # Change the domain for nginx
  68. if [ $change_domain -eq 1 ]
  69. then
  70. # Delete file checksum for the old conf file location
  71. ynh_delete_file_checksum "$nginx_conf_path"
  72. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  73. # Store file checksum for the new config file location
  74. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  75. fi
  76. #=================================================
  77. # GENERIC FINALISATION
  78. #=================================================
  79. # RELOAD NGINX
  80. #=================================================
  81. ynh_system_reload --service_name=nginx
  82. #=================================================
  83. # DEACTIVE MAINTENANCE MODE
  84. #=================================================
  85. path_url=$old_path
  86. domain=$old_domain
  87. ynh_maintenance_mode_OFF