upgrade 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #=================================================
  19. # SPECIAL UPGRADE FOR VERSIONS < 1.2.0
  20. #=================================================
  21. # Apply renaming that occured in v1.2.0 ("vpnadmin" -> "${app}")
  22. if [ -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf ]; then
  23. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  24. ynh_replace_string "vpnadmin.sock" "${app}.sock" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  25. mv /etc/nginx/conf.d/${domain}.d/vpnadmin.conf /etc/nginx/conf.d/${domain}.d/${app}.conf
  26. fi
  27. if [ -f /etc/php5/fpm/pool.d/vpnadmin.conf ]; then
  28. ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
  29. ynh_replace_string "vpnadmin.sock" "${app}.sock" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
  30. mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php/7.0/fpm/pool.d/${app}.conf
  31. fi
  32. test -d /var/www/vpnadmin && mv /var/www/vpnadmin /var/www/${app}
  33. ## Versions known to have a buggy backup script
  34. #buggy_versions="1.0.0 1.0.1 1.1.0"
  35. #curr_version=$(read_manifest version)
  36. #if echo $buggy_versions | grep -w $curr_version > /dev/null; then
  37. # echo "Your current version of ${app} is very old: ${curr_version}. Please ignore the next warning." >&2
  38. #fi
  39. #
  40. ##=================================================
  41. ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  42. ##=================================================
  43. #
  44. #ynh_backup_before_upgrade
  45. #ynh_clean_setup () {
  46. # ynh_restore_upgradebackup
  47. #}
  48. ## Exit if an error occurs during the execution of the script
  49. ynh_abort_if_errors
  50. #=================================================
  51. # DO UPGRADE
  52. #=================================================
  53. # INSTALL DEPENDENCIES
  54. #=================================================
  55. ynh_print_info "Installing dependencies..."
  56. ynh_install_app_dependencies "$pkg_dependencies"
  57. #=================================================
  58. # DEPLOY FILES FROM PACKAGE
  59. #=================================================
  60. # Keep a copy of existing config files before overwriting them
  61. tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  62. cp -r /etc/openvpn/client* ${tmpdir}
  63. # Deploy files from package
  64. vpnclient_deploy_files_and_services "${domain}" "${app}" "${service_name}"
  65. # Restore previously existing config files
  66. cp -r ${tmpdir}/client* /etc/openvpn/
  67. ynh_secure_remove ${tmpdir}
  68. #=================================================
  69. # RELOAD RELEVANT SERVICES
  70. #=================================================
  71. ynh_print_info "Reload services..."
  72. systemctl reload php7.0-fpm
  73. systemctl reload nginx
  74. ### Make sure that the yunohost services have a description and need-lock enabled
  75. # main service
  76. yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
  77. # checker service
  78. yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
  79. # Reload systemd configuration
  80. systemctl daemon-reload
  81. ### Restart services
  82. # restart main service if needed
  83. if systemctl is-active $service_name >/dev/null;
  84. then
  85. yunohost service restart $service_name
  86. fi
  87. # restart checker service if needed
  88. if systemctl is-active $service_checker_name >/dev/null;
  89. then
  90. yunohost service restart $service_checker_name
  91. fi
  92. # restart checker service timer
  93. if systemctl is-active $service_name.timer >/dev/null;
  94. then
  95. yunohost service restart $service_checker_name.timer
  96. fi
  97. #=================================================
  98. # END OF SCRIPT
  99. #=================================================
  100. ynh_print_info "Upgrade of $app completed"