upgrade 4.0 KB

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