mirror of
https://github.com/YunoHost-Apps/coin_ynh.git
synced 2024-09-03 18:16:26 +02:00
144 lines
4.2 KiB
Bash
144 lines
4.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
# Source YunoHost helpers
|
|
source /usr/share/yunohost/helpers
|
|
source future.sh
|
|
source common.sh
|
|
|
|
readonly app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Retrieve arguments
|
|
readonly domain=$YNH_APP_ARG_DOMAIN
|
|
#readonly path=$YNH_APP_ARG_PATH
|
|
readonly path=/
|
|
|
|
readonly admin=$YNH_APP_ARG_ADMIN
|
|
readonly email=$YNH_APP_ARG_EMAIL
|
|
|
|
|
|
readonly isp_name=$YNH_APP_ARG_ISP_NAME
|
|
readonly isp_site=$YNH_APP_ARG_ISP_SITE
|
|
readonly secret=$(ynh_string_random 24) # A bug don't allow to do random string bigger than 24
|
|
|
|
|
|
# Check if admin exists
|
|
ynh_user_exists $admin \
|
|
|| ynh_die "Wrong admin"
|
|
|
|
function configure_app()
|
|
{
|
|
# Check domain/path availability
|
|
ynh_webpath_register "$app" "$domain" "$path"
|
|
|
|
ynh_app_setting_set "$app" admin "$admin"
|
|
ynh_app_setting_set "$app" email "$email"
|
|
ynh_app_setting_set "$app" isp_name "$isp_name"
|
|
ynh_app_setting_set "$app" isp_site "$isp_site"
|
|
ynh_app_setting_set "$app" secret "$secret"
|
|
}
|
|
|
|
function install_from_sources()
|
|
{
|
|
$final_path/venv/bin/pip install "pip>=1.5.6"
|
|
|
|
$final_path/venv/bin/pip install gunicorn
|
|
echo "django-auth-ldap<1.4" >> $final_path/requirements.txt
|
|
$final_path/venv/bin/pip install -r $final_path/requirements.txt
|
|
#$final_path/venv/bin/pip install mysqlclient
|
|
|
|
prefix="${path#"/"}/"
|
|
prefix=${prefix%"/"}
|
|
# Configuration Django
|
|
sed -i "s@YNH_APP_ARG_ADMIN@$admin@g" ../conf/local.py
|
|
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@$prefix@g" ../conf/local.py
|
|
sed -i "s#YNH_APP_ARG_EMAIL#$email#g" ../conf/local.py
|
|
sed -i "s#YNH_APP_SECRET_KEY#$secret#g" ../conf/local.py
|
|
sed -i "s#YNH_APP_ARG_ISP_NAME#$isp_name#g" ../conf/local.py
|
|
sed -i "s#YNH_APP_ARG_ISP_SITE#$isp_site#g" ../conf/local.py
|
|
sed -i "s#YNH_APP_STATIC_ROOT#$final_path/static#g" ../conf/local.py
|
|
sed -i "s#YNH_DB_NAME#$db_name#g" ../conf/local.py
|
|
sed -i "s#YNH_DB_USER#$db_user#g" ../conf/local.py
|
|
sed -i "s#YNH_DB_PASSWORD#$db_pwd#g" ../conf/local.py
|
|
sudo cp ../conf/local.py $final_path/$app/settings_local.py
|
|
|
|
# Set production
|
|
sudo ln -s $final_path/$app/static $final_path/static
|
|
|
|
# Set permissions
|
|
sudo useradd $app -d $final_path || echo "User already exists"
|
|
sudo chown -R $app:www-data $final_path
|
|
|
|
|
|
pushd $final_path
|
|
$final_path/venv/bin/python manage.py migrate --noinput
|
|
$final_path/venv/bin/python manage.py collectstatic --noinput
|
|
popd
|
|
# Set permissions to directory
|
|
sudo chown $app:www-data -R $final_path
|
|
}
|
|
|
|
function configure_log()
|
|
{
|
|
# Log folder
|
|
sudo mkdir -p /var/log/$app
|
|
sudo chown -R $app /var/log/$app
|
|
sudo chgrp -R www-data /var/log/$app
|
|
}
|
|
|
|
function configure_gunicorn()
|
|
{
|
|
# 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/
|
|
}
|
|
|
|
function configure_nginx_and_ssowat()
|
|
{
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
sudo yunohost app addaccess $app -u $admin
|
|
|
|
# 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
|
|
|
|
## 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
|
|
}
|
|
|
|
configure_app
|
|
install_dependencies
|
|
init_db
|
|
|
|
|
|
# Copy files to the right place
|
|
final_path=/opt/$app
|
|
ynh_setup_source $final_path
|
|
|
|
# Install venv
|
|
pip install virtualenv
|
|
virtualenv $final_path/venv
|
|
set +o nounset
|
|
source $final_path/venv/bin/activate
|
|
set -o nounset
|
|
|
|
|
|
install_from_sources
|
|
configure_log
|
|
configure_gunicorn
|
|
configure_nginx_and_ssowat
|