upgrade 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #=================================================
  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. sudo sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  24. sudo sed "s|vpnadmin.sock|${app}.sock|g" -i "/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. sudo sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
  29. sudo sed "s|vpnadmin.sock|${app}.sock|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
  30. mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php5/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. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  41. #=================================================
  42. ynh_backup_before_upgrade
  43. ynh_clean_setup () {
  44. ynh_restore_upgradebackup
  45. }
  46. # Exit if an error occurs during the execution of the script
  47. ynh_abort_if_errors
  48. #=================================================
  49. # DO UPGRADE
  50. #=================================================
  51. # INSTALL DEPENDENCIES
  52. #=================================================
  53. ynh_install_app_dependencies "$pkg_dependencies"
  54. #=================================================
  55. # DEPLOY FILES FROM PACKAGE
  56. #=================================================
  57. # Keep a copy of existing config files before overwriting them
  58. tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
  59. sudo cp -r /etc/openvpn/client* ${tmpdir}
  60. # Deploy files from package
  61. vpnclient_deploy_files_and_services
  62. # Restore previously existing config files
  63. sudo cp -r ${tmpdir}/client* /etc/openvpn/
  64. sudo rm -rf ${tmpdir}
  65. #=================================================
  66. # RELOAD RELEVANT SERVICES
  67. #=================================================
  68. ynh_systemctl reload php5-fpm
  69. ynh_systemctl reload nginx
  70. ynh_systemctl restart ynh-vpnclient