change_url 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_script_progression --message="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_script_progression --message="Load settings" --weight=2
  22. final_path=$(ynh_app_setting_get $app final_path)
  23. #=================================================
  24. # CHECK THE SYNTAX OF THE PATHS
  25. #=================================================
  26. ynh_script_progression --message="Check the syntax of the paths"
  27. test -n "$old_path" || old_path="/"
  28. test -n "$new_path" || new_path="/"
  29. new_path=$(ynh_normalize_url_path $new_path)
  30. old_path=$(ynh_normalize_url_path $old_path)
  31. #=================================================
  32. # ACTIVATE MAINTENANCE MODE
  33. #=================================================
  34. ynh_script_progression --message="Activate maintenance mode"
  35. path_url=$old_path
  36. domain=$old_domain
  37. ynh_maintenance_mode_ON
  38. #=================================================
  39. # CHECK WHICH PARTS SHOULD BE CHANGED
  40. #=================================================
  41. change_domain=0
  42. if [ "$old_domain" != "$new_domain" ]
  43. then
  44. change_domain=1
  45. fi
  46. change_path=0
  47. if [ "$old_path" != "$new_path" ]
  48. then
  49. change_path=1
  50. fi
  51. #=================================================
  52. # MANAGE FAILURE OF THE SCRIPT
  53. #=================================================
  54. # Exit if an error occurs during the execution of the script
  55. ynh_abort_if_errors
  56. #=================================================
  57. # STANDARD MODIFICATIONS
  58. #=================================================
  59. # MODIFY URL IN NGINX CONF
  60. #=================================================
  61. ynh_script_progression --message="Modify url in nginx configuration" --weight=4
  62. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  63. # Change the path in the nginx config file
  64. if [ $change_path -eq 1 ]
  65. then
  66. # Make a backup of the original nginx config file if modified
  67. ynh_backup_if_checksum_is_different "$nginx_conf_path"
  68. # Set global variables for nginx helper
  69. domain="$old_domain"
  70. path_url="$new_path"
  71. # Store path_url setting
  72. ynh_app_setting_set $app path_url "$path_url"
  73. # Create a dedicated nginx config
  74. ynh_add_nginx_config
  75. fi
  76. # Change the domain for nginx
  77. if [ $change_domain -eq 1 ]
  78. then
  79. # Delete file checksum for the old conf file location
  80. ynh_delete_file_checksum "$nginx_conf_path"
  81. mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  82. # Store file checksum for the new config file location
  83. ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
  84. fi
  85. #=================================================
  86. # GENERIC FINALISATION
  87. #=================================================
  88. # RELOAD NGINX
  89. #=================================================
  90. ynh_script_progression --message="Reload nginx"
  91. ynh_systemd_action --action=reload --service_name=nginx
  92. #=================================================
  93. # DEACTIVE MAINTENANCE MODE
  94. #=================================================
  95. ynh_script_progression --message="Disable maintenance mode" --weight=5
  96. path_url=$old_path
  97. domain=$old_domain
  98. ynh_maintenance_mode_OFF
  99. #=================================================
  100. # END OF SCRIPT
  101. #=================================================
  102. ynh_script_progression --message="Change of url completed" --last