change_url 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # CHECK WHICH PARTS SHOULD BE CHANGED
  26. #=================================================
  27. change_domain=0
  28. if [ "$old_domain" != "$new_domain" ]
  29. then
  30. change_domain=1
  31. fi
  32. change_path=0
  33. if [ "$old_path" != "$new_path" ]
  34. then
  35. change_path=1
  36. fi
  37. #=================================================
  38. # STANDARD MODIFICATIONS
  39. #=================================================
  40. # MODIFY URL IN NGINX CONF
  41. #=================================================
  42. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  43. # Change the path in the nginx config file
  44. if [ $change_path -eq 1 ]
  45. then
  46. # Set global variables for nginx helper
  47. domain="$old_domain"
  48. path_url="$new_path"
  49. # Store path_url setting
  50. ynh_app_setting_set $app path_url "$path_url"
  51. # Create a dedicated nginx config
  52. ynh_add_nginx_config
  53. fi
  54. # Change the domain for nginx
  55. if [ $change_domain -eq 1 ]
  56. then
  57. # Delete file checksum for the old conf file location
  58. ynh_delete_file_checksum "$nginx_conf_path"
  59. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  60. # Store file checksum for the new config file location
  61. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  62. fi
  63. #=================================================
  64. # SPECIFIC MODIFICATIONS
  65. #=================================================
  66. # ...
  67. #=================================================
  68. #=================================================
  69. # GENERIC FINALISATION
  70. #=================================================
  71. # RELOAD NGINX
  72. #=================================================
  73. systemctl reload nginx