change_url 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
  13. #REMOVEME? old_path=$YNH_APP_OLD_PATH
  14. #REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
  15. #REMOVEME? new_path=$YNH_APP_NEW_PATH
  16. #REMOVEME? app=$YNH_APP_INSTANCE_NAME
  17. #=================================================
  18. # LOAD SETTINGS
  19. #=================================================
  20. #REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
  21. #REMOVEME? # Needed for helper "ynh_add_nginx_config"
  22. #REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
  23. #=================================================
  24. # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
  25. #=================================================
  26. #REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
  27. # Backup the current version of the app
  28. #REMOVEME? ynh_backup_before_upgrade
  29. #REMOVEME? ynh_clean_setup () {
  30. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
  31. #REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  32. # Restore it if the upgrade fails
  33. #REMOVEME? ynh_restore_upgradebackup
  34. }
  35. # Exit if an error occurs during the execution of the script
  36. #REMOVEME? ynh_abort_if_errors
  37. #=================================================
  38. # CHECK WHICH PARTS SHOULD BE CHANGED
  39. #=================================================
  40. #REMOVEME? change_domain=0
  41. #REMOVEME? if [ "$old_domain" != "$new_domain" ]
  42. then
  43. #REMOVEME? change_domain=1
  44. fi
  45. #REMOVEME? change_path=0
  46. #REMOVEME? if [ "$old_path" != "$new_path" ]
  47. then
  48. #REMOVEME? change_path=1
  49. fi
  50. #=================================================
  51. # STANDARD MODIFICATIONS
  52. #=================================================
  53. # STOP SYSTEMD SERVICE
  54. #=================================================
  55. ynh_script_progression --message="Stopping a systemd service..." --weight=1
  56. ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
  57. #=================================================
  58. # MODIFY URL IN NGINX CONF
  59. #=================================================
  60. ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
  61. ynh_change_url_nginx_config
  62. #REMOVEME? 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. #REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
  68. # Set global variables for NGINX helper
  69. #REMOVEME? domain="$old_domain"
  70. #REMOVEME? path="$new_path"
  71. # Create a dedicated NGINX config
  72. #REMOVEME? ynh_add_nginx_config
  73. fi
  74. # Change the domain for NGINX
  75. if [ $change_domain -eq 1 ]
  76. then
  77. # Delete file checksum for the old conf file location
  78. #REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
  79. #REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
  80. # Store file checksum for the new config file location
  81. #REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
  82. fi
  83. #=================================================
  84. # GENERIC FINALISATION
  85. #=================================================
  86. # START SYSTEMD SERVICE
  87. #=================================================
  88. ynh_script_progression --message="Starting a systemd service..." --weight=1
  89. ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
  90. #=================================================
  91. # RELOAD NGINX
  92. #=================================================
  93. #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  94. #REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
  95. #=================================================
  96. # END OF SCRIPT
  97. #=================================================
  98. ynh_script_progression --message="Change of URL completed for $app" --last