restore 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. isp_name=$(ynh_app_setting_get "$app" isp_name)
  14. isp_site=$(ynh_app_setting_get "$app" isp_site)
  15. isp_zone=$(ynh_app_setting_get "$app" isp_zone)
  16. latitude=$(ynh_app_setting_get "$app" latitude)
  17. longitude=$(ynh_app_setting_get "$app" longitude)
  18. zoom=$(ynh_app_setting_get "$app" zoom)
  19. cnil_link=$(ynh_app_setting_get "$app" cnil_link)
  20. cnil_number=$(ynh_app_setting_get "$app" cnil_number)
  21. url_contact=$(ynh_app_setting_get "$app" url_contact)
  22. secret=$(ynh_app_setting_get "$app" secret)
  23. # Check domain/path availability
  24. sudo yunohost app checkurl $domain$path -a $app \
  25. || ynh_die "Path not available: ${domain}${path}"
  26. final_path=/opt/$app
  27. if [ -d $final_path ]; then
  28. ynh_die "There is already a directory: $final_path "
  29. fi
  30. conf=/etc/nginx/conf.d/$domain.d/$app.conf
  31. if [ -f $conf ]; then
  32. ynh_die "There is already a nginx conf file at this path: $conf "
  33. fi
  34. gunicorn_path=/etc/systemd/system/$app.service
  35. if [ -f $gunicorn_path ]; then
  36. ynh_die "There is already a gunicorn service file at this path: $gunicorn_path "
  37. fi
  38. # Dependences
  39. ynh_package_install python3-pip python3-virtualenv
  40. # Restore sources & data
  41. sudo cp -a ./sources $final_path
  42. # Set permissions
  43. sudo chown -R www-data:www-data $final_path
  44. # Restore conf files
  45. sudo cp -a ./nginx.conf $conf
  46. sudo cp -a ./gunicorn.service $gunicorn_path
  47. sudo chown root: $gunicorn_path
  48. sudo chmod 644 $gunicorn_path
  49. # Set Administrator
  50. if ynh_user_exists $admin; then
  51. sudo yunohost app addaccess $app -u $admin
  52. fi
  53. # Log folder
  54. sudo mkdir -p /var/log/$app
  55. sudo chown -R $app /var/log/$app
  56. sudo chgrp -R www-data /var/log/$app
  57. # Reload Nginx
  58. sudo service nginx reload
  59. sudo systemctl start $app
  60. sudo systemctl enable $app
  61. sudo yunohost service add $app -l /var/log/gunicorn/$app.log
  62. ynh_app_setting_set "$app" skipped_uris "/"
  63. sudo yunohost app ssowatconf