upgrade 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # LOAD SETTINGS
  11. #=================================================
  12. ynh_print_info "Loading installation settings..."
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get $app domain)
  15. path_url=$(ynh_app_setting_get $app path)
  16. is_public=$(ynh_app_setting_get $app is_public)
  17. final_path=$(ynh_app_setting_get $app final_path)
  18. phpversion=$(ynh_app_setting_get $app phpversion)
  19. #=================================================
  20. # SPECIAL UPGRADE FOR VERSIONS < 1.2.0
  21. #=================================================
  22. # Apply renaming that occured in v1.2.0 ("vpnadmin" -> "${app}")
  23. if [ -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf ]; then
  24. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  25. ynh_replace_string "vpnadmin.sock" "${app}.sock" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  26. mv /etc/nginx/conf.d/${domain}.d/vpnadmin.conf /etc/nginx/conf.d/${domain}.d/${app}.conf
  27. fi
  28. if [ -f /etc/php/$phpversion/fpm/pool.d/vpnadmin.conf ]; then
  29. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" /etc/php/$phpversion/fpm/pool.d/vpnadmin.conf
  30. ynh_replace_string "vpnadmin.sock" "${app}.sock" /etc/php/$phpversion/fpm/pool.d/vpnadmin.conf
  31. mv /etc/php/$phpversion/fpm/pool.d/vpnadmin.conf /etc/php/$phpversion/fpm/pool.d/${app}.conf
  32. fi
  33. if [ -d /var/www/vpnadmin ]; then
  34. mv /var/www/vpnadmin /var/www/${app}
  35. fi
  36. ## Versions known to have a buggy backup script
  37. #buggy_versions="1.0.0 1.0.1 1.1.0"
  38. #curr_version=$(read_manifest version)
  39. #if echo $buggy_versions | grep -w $curr_version > /dev/null; then
  40. # echo "Your current version of ${app} is very old: ${curr_version}. Please ignore the next warning." >&2
  41. #fi
  42. #
  43. ##=================================================
  44. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  45. ##=================================================
  46. #
  47. #ynh_backup_before_upgrade
  48. #ynh_clean_setup () {
  49. # ynh_restore_upgradebackup
  50. #}
  51. ## Exit if an error occurs during the execution of the script
  52. ynh_abort_if_errors
  53. #=================================================
  54. # DO UPGRADE
  55. #=================================================
  56. # INSTALL DEPENDENCIES
  57. #=================================================
  58. ynh_print_info "Installing dependencies..."
  59. ynh_install_app_dependencies "$pkg_dependencies"
  60. #=================================================
  61. # DEPLOY FILES FROM PACKAGE
  62. #=================================================
  63. # Keep a copy of existing config files before overwriting them
  64. tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  65. cp -r /etc/openvpn/client* ${tmpdir}
  66. # Deploy files from package
  67. vpnclient_deploy_files_and_services
  68. # Restore previously existing config files
  69. cp -r ${tmpdir}/client* /etc/openvpn/
  70. ynh_secure_remove ${tmpdir}
  71. #=================================================
  72. # SERVICE INTEGRATION IN YUNOHOST
  73. #=================================================
  74. ### Make sure that the yunohost services have a description and need-lock enabled
  75. # main service
  76. yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
  77. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  78. if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
  79. then
  80. yunohost service remove $service_checker_name
  81. fi
  82. #=================================================
  83. # RESTART RELEVANT SERVICES
  84. #=================================================
  85. ynh_print_info "Restart services..."
  86. # this is meant to propagate the new files and configs
  87. systemctl -q is-active $service_name && yunohost service restart $service_name
  88. # Not sure if these are really necessary ...
  89. systemctl -q is-active $service_checker_name && systemctl restart $service_checker_name
  90. systemctl -q is-active $service_checker_name.timer && systemctl restart $service_checker_name.timer
  91. #=================================================
  92. # END OF SCRIPT
  93. #=================================================
  94. ynh_print_info "Upgrade of $app completed"