upgrade 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. final_path=$(ynh_app_setting_get $app final_path)
  15. dns_method=$(ynh_app_setting_get $app dns_method)
  16. nameservers=$(ynh_app_setting_get $app nameservers)
  17. #=================================================
  18. # SPECIAL UPGRADE FOR VERSIONS < 1.2.0
  19. #=================================================
  20. # Removing configuration files with naming that occured in versions < 1.2.0 ("vpnadmin" instead off "$app")
  21. if [ -d /etc/nginx/conf.d/*.d/$app.conf ]; then
  22. ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
  23. fi
  24. if [ -d /etc/php/*/fpm/pool.d/$app.conf ]; then
  25. ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf
  26. fi
  27. if [ -d /var/www/$app ]; then
  28. ynh_secure_remove /var/www/$app
  29. fi
  30. if [ -d /var/www/vpnadmin ]; then
  31. ynh_secure_remove /var/www/vpnadmin
  32. fi
  33. # Removing sudoer file from before 2.x / Yunohost 4.3
  34. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  35. ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
  36. fi
  37. #=================================================
  38. # SPECIAL UPGRADE FOR VERSIONS < 2.0
  39. #=================================================
  40. if [ -z "$dns_method" ]; then
  41. ynh_app_setting_set --app=$app --key=dns_method --value=custom
  42. fi
  43. if [ -z "$nameservers" ]; then
  44. nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  45. ynh_app_setting_set --app=$app --key=nameservers --value="$nameservers"
  46. fi
  47. ## Versions known to have a buggy backup script
  48. #buggy_versions="1.0.0 1.0.1 1.1.0"
  49. #curr_version=$(read_manifest version)
  50. #if echo $buggy_versions | grep -w $curr_version > /dev/null; then
  51. # echo "Your current version of ${app} is very old: ${curr_version}. Please ignore the next warning." >&2
  52. #fi
  53. #
  54. ##=================================================
  55. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  56. ##=================================================
  57. #
  58. #ynh_backup_before_upgrade
  59. #ynh_clean_setup () {
  60. # ynh_restore_upgradebackup
  61. #}
  62. ## Exit if an error occurs during the execution of the script
  63. ynh_abort_if_errors
  64. #=================================================
  65. # DO UPGRADE
  66. #=================================================
  67. # INSTALL DEPENDENCIES
  68. #=================================================
  69. ynh_print_info "Installing dependencies..."
  70. ynh_install_app_dependencies "$pkg_dependencies"
  71. #=================================================
  72. # DEPLOY FILES FROM PACKAGE
  73. #=================================================
  74. # Keep a copy of existing config files before overwriting them
  75. tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  76. cp -r /etc/openvpn/client* ${tmpdir}
  77. # Deploy files from package
  78. vpnclient_deploy_files_and_services
  79. # Restore previously existing config files
  80. cp -r ${tmpdir}/client* /etc/openvpn/
  81. ynh_secure_remove ${tmpdir}
  82. #=================================================
  83. # SERVICE INTEGRATION IN YUNOHOST
  84. #=================================================
  85. ### Make sure that the yunohost services have a description and need-lock enabled
  86. # main service
  87. 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"
  88. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  89. if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
  90. then
  91. yunohost service remove $service_checker_name
  92. fi
  93. #=================================================
  94. # RESTART RELEVANT SERVICES
  95. #=================================================
  96. ynh_print_info "Restart services..."
  97. # this is meant to propagate the new files and configs
  98. systemctl -q is-active $service_name && yunohost service restart $service_name
  99. # Not sure if these are really necessary ...
  100. systemctl -q is-active $service_checker_name && systemctl restart $service_checker_name
  101. systemctl -q is-active $service_checker_name.timer && systemctl restart $service_checker_name.timer
  102. #=================================================
  103. # END OF SCRIPT
  104. #=================================================
  105. ynh_print_info "Upgrade of $app completed"