change_url 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. # Needed for helper "ynh_add_nginx_config"
  21. final_path=$(ynh_app_setting_get $app final_path)
  22. # Add settings here as needed by your application
  23. #db_name=$(ynh_app_setting_get "$app" db_name)
  24. #db_pwd=$(ynh_app_setting_get $app db_pwd)
  25. #=================================================
  26. # CHECK THE SYNTAX OF THE PATHS
  27. #=================================================
  28. test -n "$old_path" || old_path="/"
  29. test -n "$new_path" || new_path="/"
  30. new_path=$(ynh_normalize_url_path $new_path)
  31. old_path=$(ynh_normalize_url_path $old_path)
  32. #=================================================
  33. # CHECK WHICH PARTS SHOULD BE CHANGED
  34. #=================================================
  35. change_domain=0
  36. if [ "$old_domain" != "$new_domain" ]
  37. then
  38. change_domain=1
  39. fi
  40. change_path=0
  41. if [ "$old_path" != "$new_path" ]
  42. then
  43. change_path=1
  44. fi
  45. #=================================================
  46. # STANDARD MODIFICATIONS
  47. #=================================================
  48. # MODIFY URL IN NGINX CONF
  49. #=================================================
  50. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  51. # Change the path in the nginx config file
  52. if [ $change_path -eq 1 ]
  53. then
  54. # Make a backup of the original nginx config file if modified
  55. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  56. # Set global variables for nginx helper
  57. domain="$old_domain"
  58. path_url="$new_path"
  59. # Create a dedicated nginx config
  60. ynh_add_nginx_config
  61. fi
  62. # Change the domain for nginx
  63. if [ $change_domain -eq 1 ]
  64. then
  65. # Delete file checksum for the old conf file location
  66. ynh_delete_file_checksum "$nginx_conf_path"
  67. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  68. # Store file checksum for the new config file location
  69. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  70. fi
  71. #=================================================
  72. # SPECIFIC MODIFICATIONS
  73. #=================================================
  74. # ...
  75. #=================================================
  76. #=================================================
  77. # GENERIC FINALISATION
  78. #=================================================
  79. # RELOAD NGINX
  80. #=================================================
  81. systemctl reload nginx