change_url 3.1 KB

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