restore 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # This restore script is adapted to Yunohost >=2.4
  3. # Exit on command errors and treat unset variables as an error
  4. set -eu
  5. # Source app helpers
  6. source /usr/share/yunohost/helpers
  7. # The parameter $2 is the id of the app instance ex: ynhexample__2
  8. app=$YNH_APP_INSTANCE_NAME
  9. # Get old parameter of the app
  10. domain=$(ynh_app_setting_get $app domain)
  11. path=$(ynh_app_setting_get $app path)
  12. is_public=$(ynh_app_setting_get $app is_public)
  13. # with_mysql=$(ynh_app_setting_get "$app" with_mysql)
  14. # Check domain/path availability
  15. sudo yunohost app checkurl "${domain}${path}" -a "$app" \
  16. || ynh_die "Path not available: ${domain}${path}"
  17. # Check $final_path
  18. final_path="/var/www/${app}"
  19. if [ -d $final_path ]; then
  20. ynh_die "There is already a directory: $final_path"
  21. fi
  22. # Check configuration files nginx
  23. nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
  24. if [ -f $nginx_conf ]; then
  25. ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
  26. fi
  27. # Check configuration files php-fpm
  28. phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
  29. if [ -f $phpfpm_conf ]; then
  30. ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'. You should safely delete it before restoring this app."
  31. fi
  32. phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini"
  33. if [ -f $phpfpm_ini ]; then
  34. ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app."
  35. fi
  36. # Restore sources & data
  37. sudo cp -a ./sources "${final_path}"
  38. # Set permissions
  39. sudo chown -R www-data: "${final_path}"
  40. # Restore db
  41. # if [[ $with_mysql -eq 1 ]]; then
  42. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  43. db_user=$app
  44. ynh_mysql_create_db $db_user $db_user $db_pwd
  45. sudo su -c "mysql -u $db_user -p$db_pwd $app < ./db.sql"
  46. sudo rm -f "./db.sql"
  47. #fi
  48. # Restore nginx configuration files
  49. sudo cp -a ./nginx.conf "${nginx_conf}"
  50. # Restore php-fpm configuration files
  51. sudo cp -a ./php-fpm.conf "${phpfpm_conf}"
  52. sudo cp -a ./php-fpm.ini "${phpfpm_ini}"
  53. # Set ssowat config
  54. if [ "$is_public" = "No" ];
  55. then
  56. ynh_app_setting_delete $app skipped_uris
  57. fi
  58. # Reload services
  59. sudo systemctl reload php5-fpm
  60. sudo systemctl reload nginx
  61. sudo yunohost app ssowatconf