upgrade 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. domain=$(ynh_app_setting_get $app domain)
  15. path_url=$(ynh_app_setting_get $app path)
  16. is_public=$(ynh_app_setting_get $app is_public)
  17. final_path=$(ynh_app_setting_get $app final_path)
  18. server_name=$(ynh_app_setting_get $app server_name)
  19. service_name=$(ynh_app_setting_get $app service_name)
  20. service_checker_name=$service_name"-checker"
  21. #=================================================
  22. # SPECIAL UPGRADE FOR VERSIONS < 1.2.0
  23. #=================================================
  24. # Apply renaming that occured in v1.2.0 ("vpnadmin" -> "${app}")
  25. if [ -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf ]; then
  26. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  27. ynh_replace_string "vpnadmin.sock" "${app}.sock" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  28. mv /etc/nginx/conf.d/${domain}.d/vpnadmin.conf /etc/nginx/conf.d/${domain}.d/${app}.conf
  29. fi
  30. if [ -f /etc/php5/fpm/pool.d/vpnadmin.conf ]; then
  31. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
  32. ynh_replace_string "vpnadmin.sock" "${app}.sock" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
  33. mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php/7.0/fpm/pool.d/${app}.conf
  34. fi
  35. test -d /var/www/vpnadmin && mv /var/www/vpnadmin /var/www/${app}
  36. if [ -z $service_name ]; then
  37. service_name="ynh-vpnclient"
  38. service_checker_name=$service_name"-checker"
  39. ynh_app_setting_set "$app" service_name "$service_name"
  40. fi
  41. ## Versions known to have a buggy backup script
  42. #buggy_versions="1.0.0 1.0.1 1.1.0"
  43. #curr_version=$(read_manifest version)
  44. #if echo $buggy_versions | grep -w $curr_version > /dev/null; then
  45. # echo "Your current version of ${app} is very old: ${curr_version}. Please ignore the next warning." >&2
  46. #fi
  47. #
  48. ##=================================================
  49. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  50. ##=================================================
  51. #
  52. #ynh_backup_before_upgrade
  53. #ynh_clean_setup () {
  54. # ynh_restore_upgradebackup
  55. #}
  56. ## Exit if an error occurs during the execution of the script
  57. ynh_abort_if_errors
  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 "${domain}" "${app}" "${service_name}"
  73. # Restore previously existing config files
  74. cp -r ${tmpdir}/client* /etc/openvpn/
  75. ynh_secure_remove ${tmpdir}
  76. #=================================================
  77. # RELOAD RELEVANT SERVICES
  78. #=================================================
  79. ynh_print_info "Reload services..."
  80. systemctl reload php7.0-fpm
  81. systemctl reload nginx
  82. ### Make sure that the yunohost services have a description and need-lock enabled
  83. # main service
  84. if service_is_managed_by_yunohost $service_name
  85. then
  86. yunohost service remove $service_name
  87. fi
  88. yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
  89. # checker service
  90. if service_is_managed_by_yunohost $service_checker_name
  91. then
  92. yunohost service remove $service_checker_name
  93. fi
  94. yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
  95. # Reload systemd configuration
  96. systemctl daemon-reload
  97. ### Restart services
  98. # restart main service if needed
  99. if systemctl is-active $service_name >/dev/null;
  100. then
  101. yunohost service restart $service_name
  102. fi
  103. # restart checker service if needed
  104. if systemctl is-active $service_checker_name >/dev/null;
  105. then
  106. yunohost service restart $service_checker_name
  107. fi
  108. # restart checker service timer
  109. if systemctl is-active $service_name.timer >/dev/null;
  110. then
  111. yunohost service restart $service_checker_name.timer
  112. fi
  113. #=================================================
  114. # END OF SCRIPT
  115. #=================================================
  116. ynh_print_info "Upgrade of $app completed"