change_url 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  39. #=================================================
  40. if [ $change_domain -eq 0 ]
  41. then
  42. # Backup the current version of the app
  43. ynh_backup_before_upgrade
  44. ynh_clean_setup () {
  45. # restore it if the upgrade fails
  46. ynh_restore_upgradebackup
  47. }
  48. # Exit if an error occurs during the execution of the script
  49. ynh_abort_if_errors
  50. fi
  51. #=================================================
  52. # STANDARD MODIFICATIONS
  53. #=================================================
  54. # MODIFY URL IN NGINX CONF
  55. #=================================================
  56. nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
  57. # Change the path in the nginx config file
  58. if [ $change_path -eq 1 ]
  59. then
  60. ynh_replace_string "location $old_path" "location $new_path" "$nginx_conf_path"
  61. fi
  62. # Change the domain for nginx
  63. if [ $change_domain -eq 1 ]
  64. then
  65. sudo mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  66. fi
  67. #=================================================
  68. # GENERIC FINALISATION
  69. #=================================================
  70. # RELOAD NGINX
  71. #=================================================
  72. sudo systemctl reload nginx