123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #!/bin/bash
- set -eu
- app=$YNH_APP_INSTANCE_NAME
- # Retrieve arguments
- domain=$YNH_APP_ARG_DOMAIN
- path=$YNH_APP_ARG_PATH
- admin=$YNH_APP_ARG_ADMIN
- email=$YNH_APP_ARG_EMAIL
- # Source YunoHost helpers
- . /usr/share/yunohost/helpers
- # Check if admin exists
- ynh_user_exists $admin \
- || ynh_die "Wrong admin"
- ynh_app_setting_set "$app" admin "$admin"
- ynh_app_setting_set "$app" email "$email"
- # Check domain/path availability
- sudo yunohost app checkurl "${domain}${path}" -a "$app" \
- || ynh_die "Path not available: ${domain}${path}"
- # Dependencies
- ynh_package_install python3-pip python3-virtualenv
- # Delete db and user if exit with an error
- function exit_properly
- {
- set +e
- sudo rm -Rf /opt/$app
- sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
- sudo service nginx reload
- sudo yunohost service remove $app
- sudo rm -f /etc/systemd/system/$app.service
- sudo systemctl daemon-reload
- sudo userdel $app
- sudo rm -Rf $final_path
- exit 1
- }
- trap exit_properly ERR
- # Copy files to the right place
- final_path=/opt/$app
- sudo mkdir -p $final_path
- sudo cp -a ../sources/. $final_path
- # Install venv
- # It seems that python3.4 venv is broken, we need to setup pip manually to fix that
- # http://stackoverflow.com/questions/26215790/venv-doesnt-create-activate-script-python3
- python3 -m venv --without-pip $final_path/venv
- set +o nounset
- source $final_path/venv/bin/activate
- set -o nounset
- curl https://bootstrap.pypa.io/get-pip.py | python
- set +o nounset
- deactivate
- set -o nounset
- alias py='$final_path/venv/bin/python3'
- set +o nounset
- source $final_path/venv/bin/activate
- set -o nounset
- $final_path/venv/bin/pip install gunicorn
- $final_path/venv/bin/pip install -r $final_path/requirements/base.txt
- set +o nounset
- deactivate
- set -o nounset
- # Configuration Django
- sed -i "s@YNH_APP_ARG_DOMAIN@$domain@g" ../conf/local.py
- sed -i "s@YNH_APP_ARG_PATH@$path@g" ../conf/local.py
- sed -i "s@YNH_APP_PREFIX@${path#"/"}@g" ../conf/local.py
- sed -i "s#YNH_APP_ARG_EMAIL#$email#g" ../conf/local.py
- sed -i "s#YNH_APP_SECRET_KEY#ssss#g" ../conf/local.py #TODO
- sed -i "s#YNH_APP_ARG_ISP_NAME#ARN#g" ../conf/local.py #TODO
- sed -i "s#YNH_APP_ARG_ISP_LATITUDE#47.218371#g" ../conf/local.py #TODO
- sed -i "s#YNH_APP_ARG_ISP_LONGITUDE#-1.553621#g" ../conf/local.py #TODO
- sed -i "s#YNH_APP_ARG_ISP_ZOOM#13#g" ../conf/local.py #TODO
- sudo cp ../conf/local.py $final_path/wifiwithme/settings/local.py
- # Set production
- sudo sed -i "s@wifiwithme\.settings\.dev@wifiwithme.settings.prod@g" $final_path/manage.py
- sudo sed -i "s@wifiwithme\.settings@wifiwithme.settings.prod@g" $final_path/wifiwithme/wsgi.py
- sudo ln -s $final_path/wifiwithme/static $final_path/static
- # Set permissions
- sudo useradd $app -d $final_path || echo "User already exists"
- sudo chown -R $app:www-data $final_path
- # Reload Nginx and regenerate SSOwat conf
- sudo yunohost app addaccess $app -u $admin
- old_pwd=$(pwd)
- cd $final_path
- set +o nounset
- source $final_path/venv/bin/activate
- sudo $final_path/venv/bin/python3 manage.py migrate --noinput
- set -o nounset
- cd $old_pwd
- # Modify Nginx configuration file and copy it to Nginx conf directory
- sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
- sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
- sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/nginx.conf
- sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
- # Service gunicorn
- sudo sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/gunicorn_config.py
- sudo sed -i "s@YNH_APP_INSTANCE_NAME@$app@g" ../conf/gunicorn.service
- sudo cp ../conf/gunicorn.service /etc/systemd/system/$app.service
- sudo systemctl daemon-reload
- sudo cp ../conf/gunicorn_config.py /opt/$app/
- # Set permissions to directory
- sudo useradd $app -d $final_path || echo "User already exists"
- sudo chown $app:www-data -R $final_path
- ## Reload Nginx and regenerate SSOwat conf
- sudo service nginx reload
- sudo systemctl start $app
- sudo systemctl enable $app
- sudo yunohost service add $app -l /var/log/gunicorn/$app.log
- ynh_app_setting_set "$app" skipped_uris "/"
- sudo yunohost app ssowatconf
|