change_url 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. # Make a backup of the original nginx config file if modified
  47. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  48. # Set global variables for nginx helper
  49. domain="$old_domain"
  50. path_url="$new_path"
  51. # Store path_url setting
  52. ynh_app_setting_set $app path_url "$path_url"
  53. # Create a dedicated nginx config
  54. ynh_add_nginx_config
  55. if [ "$path_url" != "/" ]
  56. then
  57. ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path"
  58. fi
  59. ynh_store_file_checksum "$nginx_conf_path"
  60. fi
  61. # Change the domain for nginx
  62. if [ $change_domain -eq 1 ]
  63. then
  64. # Delete file checksum for the old conf file location
  65. ynh_delete_file_checksum "$nginx_conf_path"
  66. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  67. # Store file checksum for the new config file location
  68. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  69. fi
  70. #=================================================
  71. # SPECIFIC MODIFICATIONS
  72. #=================================================
  73. # ...
  74. #=================================================
  75. #=================================================
  76. # GENERIC FINALISATION
  77. #=================================================
  78. # RELOAD NGINX
  79. #=================================================
  80. systemctl reload nginx