upgrade 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 $app domain
  23. [ -z "${path:-}" ] || ynh_app_setting_delete $app path
  24. [ -z "${is_public:-}" ] || ynh_app_setting_delete $app is_public
  25. [ -z "${install_dir:-}" ] || ynh_app_setting_delete $app install_dir
  26. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  27. ynh_safe_rm "/etc/sudoers.d/${app}_ynh"
  28. fi
  29. # New stuff
  30. if [ -z "${dns_method:-}" ]; then
  31. ynh_app_setting_set --key=dns_method --value=custom
  32. fi
  33. # FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=nameservers --value="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  34. if [ -z "${nameservers:-}" ]; then
  35. nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  36. ynh_app_setting_set --key=nameservers --value="$nameservers"
  37. fi
  38. if [ -z "${service_enabled:-}" ]; then
  39. ynh_app_setting_set --key=service_enabled --value=0
  40. fi
  41. if [ -z "${ip6_addr:-}" ]; then
  42. ynh_app_setting_set --key=ip6_addr --value=""
  43. fi
  44. if [ -z "${ip6_net:-}" ]; then
  45. ynh_app_setting_set --key=ip6_net --value=""
  46. fi
  47. #=================================================
  48. # UPGRADE FROM BUSTER TO BULLSEYE
  49. #=================================================
  50. if [ -e "/etc/systemd/system/openvpn@.service" ]; then
  51. ynh_safe_rm "/etc/systemd/system/openvpn@.service"
  52. fi
  53. #=================================================
  54. # DEPLOY FILES FROM PACKAGE
  55. #=================================================
  56. ynh_print_info "Stopping VPN client to apply config changes..."
  57. ynh_systemctl --action="stop" --service="$service_checker_name.timer"
  58. yunohost service stop $service_name
  59. # Keep a copy of existing config files before overwriting them
  60. tmp_dir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  61. cp -r /etc/openvpn/client* ${tmp_dir}
  62. # Deploy files from package
  63. vpnclient_deploy_files_and_services
  64. # Generate config file from the uploaded .cube or .ovpn file, if available
  65. if [[ -f "$tmp_dir/client.cube" ]]
  66. then
  67. cp -f "$tmp_dir/client.cube" "$tmp_dir/client.conf"
  68. convert_cube_file "$tmp_dir/client.conf"
  69. elif [[ -f "$tmp_dir/client.ovpn" ]]
  70. then
  71. cp -f "$tmp_dir/client.ovpn" "$tmp_dir/client.conf"
  72. convert_ovpn_file "$tmp_dir/client.conf"
  73. # In case we didn't keep the uploaded .ovpn file, we create one from the current config...
  74. elif [[ -f "$tmp_dir/client.conf" ]]
  75. then
  76. cp -f "$tmp_dir/client.conf" "$tmp_dir/client.ovpn"
  77. convert_ovpn_file "$tmp_dir/client.conf"
  78. fi
  79. # Restore previously existing config files
  80. cp -r ${tmp_dir}/client* /etc/openvpn/
  81. ynh_safe_rm ${tmp_dir}
  82. #=================================================
  83. # SERVICE INTEGRATION IN YUNOHOST
  84. #=================================================
  85. ### Make sure that the yunohost services have a description and need-lock enabled
  86. ynh_print_info "Configuring VPN client services..."
  87. # main service
  88. 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"
  89. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  90. if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null
  91. then
  92. yunohost service remove $service_checker_name
  93. fi
  94. #=================================================
  95. # RESTART RELEVANT SERVICES
  96. #=================================================
  97. ynh_print_info "Restart services..."
  98. # this is meant to propagate the new files and configs
  99. yunohost service start $service_name
  100. ynh_systemctl --action="start" --service="$service_checker_name.timer"
  101. #=================================================
  102. # END OF SCRIPT
  103. #=================================================
  104. ynh_print_info "Upgrade of $app completed"