upgrade 4.4 KB

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