upgrade 3.8 KB

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