restore 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # The parameter $2 is the id of the app instance ex: ynhexample__2
  6. app=$YNH_APP_INSTANCE_NAME
  7. # Source app helpers
  8. source /usr/share/yunohost/helpers
  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. # Check configuration files php-fpm
  27. phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
  28. if [ -f $phpfpm_conf ]; then
  29. ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'. You should safely delete it before restoring this app."
  30. fi
  31. phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini"
  32. if [ -f $phpfpm_ini ]; then
  33. ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app."
  34. fi
  35. # Restore sources & data
  36. sudo cp -a ./sources "$final_path"
  37. # Set permissions
  38. sudo chown -R www-data: $final_path
  39. # Restore db
  40. # if [[ $with_mysql -eq 1 ]]; then
  41. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  42. db_user=$app
  43. ynh_mysql_create_db $db_user $db_user $db_pwd
  44. sudo su -c "mysql -u $db_user -p$db_pwd $app < ./db.sql"
  45. sudo rm -f "./db.sql"
  46. #fi
  47. # Restore nginx configuration files
  48. sudo cp -a ./nginx.conf "$nginx_conf"
  49. # Restore php-fpm configuration files
  50. sudo cp -a ./php-fpm.conf "$phpfpm_conf"
  51. sudo cp -a ./php-fpm.ini "$phpfpm_ini"
  52. # Reload services
  53. sudo service php5-fpm reload || true
  54. sudo service nginx reload || true