upgrade 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/bash
  2. source _common.sh
  3. source /usr/share/yunohost/helpers
  4. #=================================================
  5. # SPECIAL UPGRADE FOR VERSIONS < 2.0
  6. #=================================================
  7. # Removing configuration files with naming that occured in versions < 1.2.0 ("vpnadmin" instead off "$app")
  8. if [ -d /var/www/vpnadmin ]; then
  9. ynh_safe_rm /var/www/vpnadmin
  10. fi
  11. # Old stuff
  12. if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
  13. ynh_safe_rm /etc/nginx/conf.d/*.d/$app.conf
  14. ynh_systemctl --service="nginx" --action="reload"
  15. fi
  16. for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
  17. ynh_safe_rm "$php_path"
  18. done
  19. if [ -d /var/www/$app ]; then
  20. ynh_safe_rm "/var/www/$app"
  21. fi
  22. [ -z "${domain:-}" ] || ynh_app_setting_delete domain
  23. [ -z "${path:-}" ] || ynh_app_setting_delete path
  24. [ -z "${is_public:-}" ] || ynh_app_setting_delete is_public
  25. [ -z "${install_dir:-}" ] || ynh_app_setting_delete install_dir
  26. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  27. ynh_safe_rm "/etc/sudoers.d/${app}_ynh"
  28. fi
  29. if [ -e "/etc/yunohost/hooks.d/90-vpnclient.tpl" ]; then
  30. ynh_safe_rm "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  31. fi
  32. if [ -e "/etc/openvpn/client.conf.tpl" ]; then
  33. ynh_safe_rm "/etc/openvpn/client.conf.tpl"
  34. fi
  35. # New stuff
  36. ynh_app_setting_set_default --key="dns_method" --value="custom"
  37. default_nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  38. ynh_app_setting_set_default --key="nameservers" --value="$default_nameservers"
  39. ynh_app_setting_set_default --key="service_enabled" --value="0"
  40. ynh_app_setting_set_default --key="ip6_addr" --value=""
  41. ynh_app_setting_set_default --key="ip6_net" --value=""
  42. ynh_app_setting_set_default --key="ip6_send_over_tun_enabled" --value="0"
  43. #=================================================
  44. # UPGRADE FROM BUSTER TO BULLSEYE
  45. #=================================================
  46. if [ -e "/etc/systemd/system/openvpn@.service" ]; then
  47. ynh_safe_rm "/etc/systemd/system/openvpn@.service"
  48. fi
  49. #=================================================
  50. # DEPLOY FILES FROM PACKAGE
  51. #=================================================
  52. ynh_print_info "Stopping VPN client to apply config changes..."
  53. ynh_systemctl --action="stop" --service="$service_checker_name.timer"
  54. yunohost service stop $service_name
  55. # Moving log files from legacy location
  56. if [[ -e "/var/log/openvpn-client.log" ]]; then
  57. mkdir -p "/var/log/$app"
  58. mv "/var/log/openvpn-client.log" "/var/log/$app/"
  59. fi
  60. if [[ -e "/var/log/openvpn-client.status" ]]; then
  61. mkdir -p "/var/log/$app"
  62. mv "/var/log/openvpn-client.status" "/var/log/$app/"
  63. fi
  64. if [[ -e "/var/log/ynh-vpnclient.log" ]]; then
  65. mkdir -p "/var/log/$app"
  66. mv "/var/log/ynh-vpnclient.log" "/var/log/$app/"
  67. fi
  68. # Fixing incorrect logrotate config
  69. if grep -q -e "/var/log/ynh-vpnclient.log" -e "/var/log/openvpn-client.log" "/etc/logrotate.d/$app"; then
  70. ynh_config_remove_logrotate
  71. chmod 0755 /var/log
  72. chown root:root /var/log
  73. fi
  74. # Keep a copy of existing config files before overwriting them
  75. tmp_dir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  76. for config_file in /etc/openvpn/client.{conf,cube,ovpn}; do
  77. if [[ -f "${config_file}" ]]; then
  78. cp "${config_file}" "${tmp_dir}/"
  79. fi
  80. done
  81. # Deploy files from package
  82. vpnclient_deploy_files_and_services
  83. # Generate config file from the uploaded .cube or .ovpn file, if available
  84. if [[ -f "$tmp_dir/client.cube" ]]
  85. then
  86. cp -f "$tmp_dir/client.cube" "$tmp_dir/client.conf"
  87. convert_cube_file "$tmp_dir/client.conf"
  88. elif [[ -f "$tmp_dir/client.ovpn" ]]
  89. then
  90. cp -f "$tmp_dir/client.ovpn" "$tmp_dir/client.conf"
  91. convert_ovpn_file "$tmp_dir/client.conf"
  92. # In case we didn't keep the uploaded .ovpn file, we create one from the current config...
  93. elif [[ -f "$tmp_dir/client.conf" ]]
  94. then
  95. cp -f "$tmp_dir/client.conf" "$tmp_dir/client.ovpn"
  96. convert_ovpn_file "$tmp_dir/client.conf"
  97. fi
  98. # Restore previously existing config files
  99. for config_file in ${tmp_dir}/client.{conf,cube,ovpn}; do
  100. if [[ -f "${config_file}" ]]; then
  101. cp "${config_file}" /etc/openvpn/
  102. fi
  103. done
  104. ynh_safe_rm "${tmp_dir}"
  105. #=================================================
  106. # SERVICE INTEGRATION IN YUNOHOST
  107. #=================================================
  108. ### Make sure that the yunohost services have a description and need-lock enabled
  109. ynh_print_info "Configuring VPN client services..."
  110. # main service
  111. 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/$app/ynh-vpnclient.log"
  112. ynh_config_add_logrotate
  113. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  114. if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null
  115. then
  116. yunohost service remove $service_checker_name
  117. fi
  118. #=================================================
  119. # RESTART RELEVANT SERVICES
  120. #=================================================
  121. ynh_print_info "Restart services..."
  122. # this is meant to propagate the new files and configs
  123. yunohost service start $service_name
  124. ynh_systemctl --action="start" --service="$service_checker_name.timer"
  125. #=================================================
  126. # END OF SCRIPT
  127. #=================================================
  128. ynh_print_info "Upgrade of $app completed"