upgrade 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. ynh_abort_if_errors
  10. #=================================================
  11. # LOAD SETTINGS
  12. #=================================================
  13. ynh_print_info "Loading installation settings..."
  14. app=$YNH_APP_INSTANCE_NAME
  15. dns_method=$(ynh_app_setting_get $app dns_method)
  16. nameservers=$(ynh_app_setting_get $app nameservers)
  17. service_enabled=$(ynh_app_setting_get $app service_enabled)
  18. ip6_addr=$(ynh_app_setting_get $app ip6_addr)
  19. ip6_net=$(ynh_app_setting_get $app ip6_net)
  20. #=================================================
  21. # SPECIAL UPGRADE FOR VERSIONS < 1.2.0
  22. #=================================================
  23. # Removing configuration files with naming that occured in versions < 1.2.0 ("vpnadmin" instead off "$app")
  24. if [ -d /var/www/vpnadmin ]; then
  25. ynh_secure_remove /var/www/vpnadmin
  26. fi
  27. #=================================================
  28. # SPECIAL UPGRADE FOR VERSIONS < 2.0
  29. #=================================================
  30. # Old stuff
  31. if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
  32. ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
  33. ynh_systemd_action --service_name=nginx --action=reload
  34. fi
  35. for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
  36. ynh_secure_remove $php_path
  37. done
  38. if [ -d /var/www/$app ]; then
  39. ynh_secure_remove /var/www/$app
  40. fi
  41. [ -z "$(ynh_app_setting_get $app domain)" ] || ynh_app_setting_delete $app domain
  42. [ -z "$(ynh_app_setting_get $app path)" ] || ynh_app_setting_delete $app path
  43. [ -z "$(ynh_app_setting_get $app is_public)" ] || ynh_app_setting_delete $app is_public
  44. [ -z "$(ynh_app_setting_get $app final_path)" ] || ynh_app_setting_delete $app final_path
  45. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  46. ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
  47. fi
  48. # New stuff
  49. if [ -z "$dns_method" ]; then
  50. ynh_app_setting_set --app=$app --key=dns_method --value=custom
  51. fi
  52. if [ -z "$nameservers" ]; then
  53. nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  54. ynh_app_setting_set --app=$app --key=nameservers --value="$nameservers"
  55. fi
  56. if [ -z "$service_enabled" ]; then
  57. ynh_app_setting_set --app=$app --key=service_enabled --value=0
  58. fi
  59. if [ -z "$ip6_addr" ]; then
  60. ynh_app_setting_set --app=$app --key=ip6_addr --value=""
  61. fi
  62. if [ -z "$ip6_net" ]; then
  63. ynh_app_setting_set --app=$app --key=ip6_net --value=""
  64. fi
  65. ##=================================================
  66. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  67. ##=================================================
  68. # Not done because vpnclient backup ain't so relevant I guess ?
  69. #=================================================
  70. # DO UPGRADE
  71. #=================================================
  72. # INSTALL DEPENDENCIES
  73. #=================================================
  74. ynh_print_info "Installing dependencies..."
  75. ynh_install_app_dependencies "$pkg_dependencies"
  76. #=================================================
  77. # DEPLOY FILES FROM PACKAGE
  78. #=================================================
  79. # Keep a copy of existing config files before overwriting them
  80. tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  81. cp -r /etc/openvpn/client* ${tmpdir}
  82. # Deploy files from package
  83. vpnclient_deploy_files_and_services
  84. # Restore previously existing config files
  85. cp -r ${tmpdir}/client* /etc/openvpn/
  86. ynh_secure_remove ${tmpdir}
  87. #=================================================
  88. # SERVICE INTEGRATION IN YUNOHOST
  89. #=================================================
  90. ### Make sure that the yunohost services have a description and need-lock enabled
  91. # main service
  92. 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"
  93. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  94. if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
  95. then
  96. yunohost service remove $service_checker_name
  97. fi
  98. #=================================================
  99. # RESTART RELEVANT SERVICES
  100. #=================================================
  101. ynh_print_info "Restart services..."
  102. # this is meant to propagate the new files and configs
  103. systemctl -q is-active $service_name && yunohost service restart $service_name
  104. # Not sure if these are really necessary ...
  105. systemctl -q is-active $service_checker_name && systemctl restart $service_checker_name
  106. systemctl -q is-active $service_checker_name.timer && systemctl restart $service_checker_name.timer
  107. #=================================================
  108. # END OF SCRIPT
  109. #=================================================
  110. ynh_print_info "Upgrade of $app completed"