change_url 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. ynh_abort_if_errors
  10. #=================================================
  11. # RETRIEVE ARGUMENTS
  12. #=================================================
  13. old_domain=$YNH_APP_OLD_DOMAIN
  14. old_path=$YNH_APP_OLD_PATH
  15. new_domain=$YNH_APP_NEW_DOMAIN
  16. new_path=$YNH_APP_NEW_PATH
  17. app=$YNH_APP_INSTANCE_NAME
  18. #=================================================
  19. # LOAD SETTINGS
  20. #=================================================
  21. # Needed for helper "ynh_add_nginx_config"
  22. final_path=$(ynh_app_setting_get $app final_path)
  23. # Add settings here as needed by your application
  24. #db_name=$(ynh_app_setting_get "$app" db_name)
  25. #db_pwd=$(ynh_app_setting_get $app db_pwd)
  26. #=================================================
  27. # CHECK THE SYNTAX OF THE PATHS
  28. #=================================================
  29. test -n "$old_path" || old_path="/"
  30. test -n "$new_path" || new_path="/"
  31. new_path=$(ynh_normalize_url_path $new_path)
  32. old_path=$(ynh_normalize_url_path $old_path)
  33. #=================================================
  34. # CHECK WHICH PARTS SHOULD BE CHANGED
  35. #=================================================
  36. change_domain=0
  37. if [ "$old_domain" != "$new_domain" ]
  38. then
  39. change_domain=1
  40. fi
  41. change_path=0
  42. if [ "$old_path" != "$new_path" ]
  43. then
  44. change_path=1
  45. fi
  46. #=================================================
  47. # STANDARD MODIFICATIONS
  48. #=================================================
  49. # MODIFY URL IN NGINX CONF
  50. #=================================================
  51. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  52. # Change the path in the nginx config file
  53. if [ $change_path -eq 1 ]
  54. then
  55. # Make a backup of the original nginx config file if modified
  56. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  57. # Set global variables for nginx helper
  58. domain="$old_domain"
  59. path_url="$new_path"
  60. # Create a dedicated nginx config
  61. ynh_add_nginx_config
  62. fi
  63. # Change the domain for nginx
  64. if [ $change_domain -eq 1 ]
  65. then
  66. # Delete file checksum for the old conf file location
  67. ynh_delete_file_checksum "$nginx_conf_path"
  68. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  69. # Store file checksum for the new config file location
  70. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  71. fi
  72. #=================================================
  73. # SPECIFIC MODIFICATIONS
  74. #=================================================
  75. # ...
  76. #=================================================
  77. #=================================================
  78. # GENERIC FINALISATION
  79. #=================================================
  80. # RELOAD NGINX
  81. #=================================================
  82. systemctl reload nginx