restore 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # Exit on command errors and treat unset variables as an error
  3. set -eu
  4. # See comments in install script
  5. app=$YNH_APP_INSTANCE_NAME
  6. # Source YunoHost helpers
  7. . /usr/share/yunohost/helpers
  8. # Retrieve old app settings
  9. domain=$(ynh_app_setting_get "$app" domain)
  10. path=$(ynh_app_setting_get "$app" path)
  11. admin=$(ynh_app_setting_get "$app" admin)
  12. email=$(ynh_app_setting_get "$app" email)
  13. # Check domain/path availability
  14. sudo yunohost app checkurl $domain$path -a $app \
  15. || ynh_die "Path not available: ${domain}${path}"
  16. final_path=/opt/$app
  17. if [ -d $final_path ]; then
  18. ynh_die "There is already a directory: $final_path "
  19. fi
  20. conf=/etc/nginx/conf.d/$domain.d/$app.conf
  21. if [ -f $conf ]; then
  22. ynh_die "There is already a nginx conf file at this path: $conf "
  23. fi
  24. gunicorn_path=/etc/systemd/system/$app.service
  25. if [ -f $gunicorn_path ]; then
  26. ynh_die "There is already a gunicorn service file at this path: $gunicorn_path "
  27. fi
  28. # Dependences
  29. ynh_package_install python3-pip python3-virtualenv
  30. # Restore sources & data
  31. sudo cp -a ./sources $final_path
  32. # Set permissions
  33. sudo chown -R www-data:www-data $final_path
  34. # Restore conf files
  35. sudo cp -a ./nginx.conf $conf
  36. sudo cp -a ./gunicorn.service $gunicorn_path
  37. sudo chown root: $gunicorn_path
  38. sudo chmod 644 $gunicorn_path
  39. # Set Administrator
  40. if ynh_user_exists $admin; then
  41. sudo yunohost app addaccess $app -u $admin
  42. fi
  43. # Reload Nginx
  44. sudo service nginx reload
  45. sudo systemctl start $app
  46. sudo systemctl enable $app
  47. sudo yunohost service add $app -l /var/log/gunicorn/$app.log
  48. ynh_app_setting_set "$app" skipped_uris "/"
  49. sudo yunohost app ssowatconf