upgrade 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. # UPGRADE FROM BUSTER TO BULLSEYE
  67. #=================================================
  68. if [ -e "/etc/systemd/system/openvpn@.service" ]; then
  69. ynh_secure_remove "/etc/systemd/system/openvpn@.service"
  70. fi
  71. ##=================================================
  72. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  73. ##=================================================
  74. # Not done because vpnclient backup ain't so relevant I guess ?
  75. #=================================================
  76. # DO UPGRADE
  77. #=================================================
  78. # INSTALL DEPENDENCIES
  79. #=================================================
  80. ynh_print_info "Installing dependencies..."
  81. ynh_install_app_dependencies "$pkg_dependencies"
  82. #=================================================
  83. # DEPLOY FILES FROM PACKAGE
  84. #=================================================
  85. ynh_print_info --message="Stopping VPN client to apply config changes..."
  86. ynh_systemd_action --action="stop" --service_name="$service_checker_name.timer"
  87. ynh_systemd_action --action="stop" --service_name="$service_name"
  88. # Keep a copy of existing config files before overwriting them
  89. tmp_dir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  90. cp -r /etc/openvpn/client* ${tmp_dir}
  91. # Deploy files from package
  92. vpnclient_deploy_files_and_services
  93. # Generate config file from the uploaded .cube or .ovpn file, if available
  94. if [[ -f "$tmp_dir/client.cube" ]]
  95. then
  96. cp -f "$tmp_dir/client.cube" "$tmp_dir/client.conf"
  97. convert_cube_file "$tmp_dir/client.conf"
  98. elif [[ -f "$tmp_dir/client.ovpn" ]]
  99. then
  100. cp -f "$tmp_dir/client.ovpn" "$tmp_dir/client.conf"
  101. convert_ovpn_file "$tmp_dir/client.conf"
  102. # In case we didn't keep the uploaded .ovpn file, we create one from the current config...
  103. elif [[ -f "$tmp_dir/client.conf" ]]
  104. then
  105. cp -f "$tmp_dir/client.conf" "$tmp_dir/client.ovpn"
  106. convert_ovpn_file "$tmp_dir/client.conf"
  107. fi
  108. # Restore previously existing config files
  109. cp -r ${tmp_dir}/client* /etc/openvpn/
  110. ynh_secure_remove ${tmp_dir}
  111. #=================================================
  112. # SERVICE INTEGRATION IN YUNOHOST
  113. #=================================================
  114. ### Make sure that the yunohost services have a description and need-lock enabled
  115. ynh_print_info "Configuring VPN client services..."
  116. # main service
  117. 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"
  118. # checker service (this service was previously integrated in yunohost but we do not do this anymore)
  119. if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
  120. then
  121. yunohost service remove $service_checker_name
  122. fi
  123. #=================================================
  124. # RESTART RELEVANT SERVICES
  125. #=================================================
  126. ynh_print_info "Restart services..."
  127. # this is meant to propagate the new files and configs
  128. ynh_systemd_action --action="start" --service_name="$service_name"
  129. ynh_systemd_action --action="start" --service_name="$service_checker_name.timer"
  130. #=================================================
  131. # END OF SCRIPT
  132. #=================================================
  133. ynh_print_info "Upgrade of $app completed"