change_url 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. ynh_print_info "Loading installation settings..."
  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. ynh_print_info "Updating nginx web server configuration..."
  52. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  53. # Change the path in the nginx config file
  54. if [ $change_path -eq 1 ]
  55. then
  56. # Make a backup of the original nginx config file if modified
  57. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  58. # Set global variables for nginx helper
  59. domain="$old_domain"
  60. path_url="$new_path"
  61. # Create a dedicated nginx config
  62. ynh_add_nginx_config
  63. fi
  64. # Change the domain for nginx
  65. if [ $change_domain -eq 1 ]
  66. then
  67. # Delete file checksum for the old conf file location
  68. ynh_delete_file_checksum "$nginx_conf_path"
  69. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  70. # Store file checksum for the new config file location
  71. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  72. fi
  73. #=================================================
  74. # SPECIFIC MODIFICATIONS
  75. #=================================================
  76. # ...
  77. #=================================================
  78. #=================================================
  79. # GENERIC FINALISATION
  80. #=================================================
  81. # RELOAD NGINX
  82. #=================================================
  83. ynh_print_info "Reloading nginx web server..."
  84. systemctl reload nginx
  85. #=================================================
  86. # END OF SCRIPT
  87. #=================================================
  88. ynh_print_info "Change of URL completed for $app"