install 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. set -eu
  3. app=$YNH_APP_INSTANCE_NAME
  4. # Retrieve arguments
  5. domain=$YNH_APP_ARG_DOMAIN
  6. path=$YNH_APP_ARG_PATH
  7. admin=$YNH_APP_ARG_ADMIN
  8. email=$YNH_APP_ARG_EMAIL
  9. # Source YunoHost helpers
  10. . /usr/share/yunohost/helpers
  11. # Check if admin exists
  12. ynh_user_exists $admin \
  13. || ynh_die "Wrong admin"
  14. ynh_app_setting_set "$app" admin "$admin"
  15. ynh_app_setting_set "$app" email "$email"
  16. # Check domain/path availability
  17. sudo yunohost app checkurl "${domain}${path}" -a "$app" \
  18. || ynh_die "Path not available: ${domain}${path}"
  19. # Dependencies
  20. ynh_package_install python3-pip python3-virtualenv
  21. # Delete db and user if exit with an error
  22. function exit_properly
  23. {
  24. set +e
  25. sudo rm -Rf /opt/$app
  26. sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
  27. sudo service nginx reload
  28. sudo yunohost service remove $app
  29. sudo rm -f /etc/systemd/system/$app.service
  30. sudo systemctl daemon-reload
  31. sudo userdel $app
  32. sudo rm -Rf $final_path
  33. exit 1
  34. }
  35. trap exit_properly ERR
  36. # Copy files to the right place
  37. final_path=/opt/$app
  38. sudo mkdir -p $final_path
  39. sudo cp -a ../sources/. $final_path
  40. # Install venv
  41. # It seems that python3.4 venv is broken, we need to setup pip manually to fix that
  42. # http://stackoverflow.com/questions/26215790/venv-doesnt-create-activate-script-python3
  43. python3 -m venv --without-pip $final_path/venv
  44. set +o nounset
  45. source $final_path/venv/bin/activate
  46. set -o nounset
  47. curl https://bootstrap.pypa.io/get-pip.py | python
  48. set +o nounset
  49. deactivate
  50. set -o nounset
  51. alias py='$final_path/venv/bin/python3'
  52. set +o nounset
  53. source $final_path/venv/bin/activate
  54. set -o nounset
  55. $final_path/venv/bin/pip install gunicorn
  56. $final_path/venv/bin/pip install -r $final_path/requirements/base.txt
  57. set +o nounset
  58. deactivate
  59. set -o nounset
  60. # Configuration Django
  61. sed -i "s@YNH_APP_ARG_DOMAIN@$domain@g" ../conf/local.py
  62. sed -i "s@YNH_APP_ARG_PATH@$path@g" ../conf/local.py
  63. sed -i "s@YNH_APP_PREFIX@${path#"/"}@g" ../conf/local.py
  64. sed -i "s#YNH_APP_ARG_EMAIL#$email#g" ../conf/local.py
  65. sed -i "s#YNH_APP_SECRET_KEY#ssss#g" ../conf/local.py #TODO
  66. sed -i "s#YNH_APP_ARG_ISP_NAME#ARN#g" ../conf/local.py #TODO
  67. sed -i "s#YNH_APP_ARG_ISP_LATITUDE#47.218371#g" ../conf/local.py #TODO
  68. sed -i "s#YNH_APP_ARG_ISP_LONGITUDE#-1.553621#g" ../conf/local.py #TODO
  69. sed -i "s#YNH_APP_ARG_ISP_ZOOM#13#g" ../conf/local.py #TODO
  70. sudo cp ../conf/local.py $final_path/wifiwithme/settings/local.py
  71. # Set production
  72. sudo sed -i "s@wifiwithme\.settings\.dev@wifiwithme.settings.prod@g" $final_path/manage.py
  73. sudo sed -i "s@wifiwithme\.settings@wifiwithme.settings.prod@g" $final_path/wifiwithme/wsgi.py
  74. sudo ln -s $final_path/wifiwithme/static $final_path/static
  75. # Set permissions
  76. sudo useradd $app -d $final_path || echo "User already exists"
  77. sudo chown -R $app:www-data $final_path
  78. # Reload Nginx and regenerate SSOwat conf
  79. sudo yunohost app addaccess $app -u $admin
  80. old_pwd=$(pwd)
  81. cd $final_path
  82. set +o nounset
  83. source $final_path/venv/bin/activate
  84. sudo $final_path/venv/bin/python3 manage.py migrate --noinput
  85. set -o nounset
  86. cd $old_pwd
  87. # Modify Nginx configuration file and copy it to Nginx conf directory
  88. sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
  89. sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
  90. sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/nginx.conf
  91. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  92. # Service gunicorn
  93. sudo sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/gunicorn_config.py
  94. sudo sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/gunicorn.service
  95. sudo cp ../conf/gunicorn.service /etc/systemd/system/$app.service
  96. sudo systemctl daemon-reload
  97. sudo cp ../conf/gunicorn_config.py /opt/$app/
  98. # Set permissions to directory
  99. sudo useradd $app -d $final_path || echo "User already exists"
  100. sudo chown $app:www-data -R $final_path
  101. ## Reload Nginx and regenerate SSOwat conf
  102. sudo service nginx reload
  103. sudo systemctl start $app
  104. sudo systemctl enable $app
  105. sudo yunohost service add $app -l /var/log/gunicorn/$app.log
  106. ynh_app_setting_set "$app" skipped_uris "/"
  107. sudo yunohost app ssowatconf