upgrade 4.5 KB

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