upgrade 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_secure_remove /var/www/vpnadmin
  10. fi
  11. # Old stuff
  12. if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
  13. ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
  14. ynh_systemd_action --service_name=nginx --action=reload
  15. fi
  16. for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
  17. ynh_secure_remove $php_path
  18. done
  19. if [ -d /var/www/$app ]; then
  20. ynh_secure_remove /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_secure_remove "/etc/sudoers.d/${app}_ynh"
  28. fi
  29. for script_path in $(ls /etc/openvpn/scripts/route-*.d/10-vpnclient-{set-firewall,unset-firewall} 2> /dev/null); do
  30. ynh_secure_remove "$script_path"
  31. done
  32. if [ -e "/etc/yunohost/hooks.d/90-vpnclient.tpl" ]; then
  33. ynh_secure_remove "/etc/yunohost/hooks.d/90-vpnclient.tpl"
  34. fi
  35. # New stuff
  36. if [ -z "${dns_method:-}" ]; then
  37. ynh_app_setting_set --app=$app --key=dns_method --value=custom
  38. fi
  39. if [ -z "${nameservers:-}" ]; then
  40. nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
  41. ynh_app_setting_set --app=$app --key=nameservers --value="$nameservers"
  42. fi
  43. if [ -z "${service_enabled:-}" ]; then
  44. ynh_app_setting_set --app=$app --key=service_enabled --value=0
  45. fi
  46. if [ -z "${ip6_addr:-}" ]; then
  47. ynh_app_setting_set --app=$app --key=ip6_addr --value=""
  48. fi
  49. if [ -z "${ip6_net:-}" ]; then
  50. ynh_app_setting_set --app=$app --key=ip6_net --value=""
  51. fi
  52. #=================================================
  53. # UPGRADE FROM BUSTER TO BULLSEYE
  54. #=================================================
  55. if [ -e "/etc/systemd/system/openvpn@.service" ]; then
  56. ynh_secure_remove "/etc/systemd/system/openvpn@.service"
  57. fi
  58. #=================================================
  59. # DEPLOY FILES FROM PACKAGE
  60. #=================================================
  61. ynh_print_info --message="Stopping VPN client to apply config changes..."
  62. ynh_systemd_action --action="stop" --service_name="$service_checker_name.timer"
  63. yunohost service stop $service_name
  64. # Keep a copy of existing config files before overwriting them
  65. tmp_dir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  66. cp -r /etc/openvpn/client* ${tmp_dir}
  67. # Deploy files from package
  68. vpnclient_deploy_files_and_services
  69. # Generate config file from the uploaded .cube or .ovpn file, if available
  70. if [[ -f "$tmp_dir/client.cube" ]]
  71. then
  72. cp -f "$tmp_dir/client.cube" "$tmp_dir/client.conf"
  73. convert_cube_file "$tmp_dir/client.conf"
  74. elif [[ -f "$tmp_dir/client.ovpn" ]]
  75. then
  76. cp -f "$tmp_dir/client.ovpn" "$tmp_dir/client.conf"
  77. convert_ovpn_file "$tmp_dir/client.conf"
  78. # In case we didn't keep the uploaded .ovpn file, we create one from the current config...
  79. elif [[ -f "$tmp_dir/client.conf" ]]
  80. then
  81. cp -f "$tmp_dir/client.conf" "$tmp_dir/client.ovpn"
  82. convert_ovpn_file "$tmp_dir/client.conf"
  83. fi
  84. # Restore previously existing config files
  85. cp -r ${tmp_dir}/client* /etc/openvpn/
  86. ynh_secure_remove ${tmp_dir}
  87. #=================================================
  88. # SERVICE INTEGRATION IN YUNOHOST
  89. #=================================================
  90. ### Make sure that the yunohost services have a description and need-lock enabled
  91. ynh_print_info "Configuring VPN client services..."
  92. # main service
  93. 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"
  94. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  95. if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
  96. then
  97. yunohost service remove $service_checker_name
  98. fi
  99. #=================================================
  100. # RESTART RELEVANT SERVICES
  101. #=================================================
  102. ynh_print_info "Restart services..."
  103. # this is meant to propagate the new files and configs
  104. yunohost service start $service_name
  105. ynh_systemd_action --action="start" --service_name="$service_checker_name.timer"
  106. #=================================================
  107. # END OF SCRIPT
  108. #=================================================
  109. ynh_print_info "Upgrade of $app completed"