2017-06-05 13:04:03 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
2019-03-05 23:17:15 +01:00
|
|
|
# COMMON VARIABLES
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
2019-03-05 23:11:52 +01:00
|
|
|
# dependencies used by the app
|
2021-05-29 21:22:52 +02:00
|
|
|
pkg_dependencies="acl python3 python3-dev python3-pip python3-venv postgresql postgresql-contrib libpq-dev redis-server libldap2-dev libsasl2-dev"
|
2019-03-05 23:11:52 +01:00
|
|
|
|
2019-03-05 23:17:15 +01:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-04-27 22:37:37 +02:00
|
|
|
function set_permissions {
|
2022-02-02 21:42:33 +01:00
|
|
|
mkdir -p $datadir
|
2021-04-27 22:37:37 +02:00
|
|
|
|
|
|
|
env_path=$final_path/envs/prod
|
|
|
|
mkdir -p $env_path
|
|
|
|
|
2022-02-02 21:42:33 +01:00
|
|
|
chown -R $app:$app $datadir
|
|
|
|
chmod o-rwx $datadir
|
|
|
|
setfacl -n -R -m u:www-data:rx -m d:u:www-data:rx $datadir
|
2021-04-27 22:37:37 +02:00
|
|
|
|
|
|
|
chown -R root:$app $final_path
|
|
|
|
chmod -R g=u,g-w,o-rwx $final_path
|
|
|
|
setfacl -n -R -m user:www-data:rx -m default:user:www-data:rx $final_path
|
|
|
|
setfacl -n -R -m user:www-data:- -m default:user:www-data:- $final_path/envs
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_up_virtualenv {
|
|
|
|
env_path=$final_path/envs/prod
|
|
|
|
mkdir -p $env_path
|
|
|
|
|
|
|
|
pushd $final_path || ynh_die
|
|
|
|
chown -R $app:$app $final_path
|
2022-02-02 21:42:33 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app python3 -m venv $final_path/venv
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U wheel pip --cache-dir $final_path/.cache/pip setuptools
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements.txt
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements-setup.txt
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements-ynh.txt
|
2021-04-27 22:37:37 +02:00
|
|
|
set_permissions
|
|
|
|
popd || ynh_dies
|
|
|
|
}
|
|
|
|
|
|
|
|
function initialize_db {
|
|
|
|
pushd $final_path || ynh_die
|
|
|
|
chown -R $app:$app $final_path
|
|
|
|
perform_db_migrations
|
2022-02-02 21:42:33 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py createsuperuser --username "$admin" --email "$admin_email" --noinput -v 0
|
2021-04-27 22:37:37 +02:00
|
|
|
set_permissions
|
|
|
|
popd || ynh_die
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_db {
|
|
|
|
pushd $final_path || ynh_die
|
|
|
|
chown -R $app:$app $final_path
|
|
|
|
perform_db_migrations
|
|
|
|
set_permissions
|
|
|
|
popd || ynh_die
|
|
|
|
}
|
|
|
|
|
|
|
|
function perform_db_migrations {
|
2022-02-02 21:42:33 +01:00
|
|
|
echo "y" | ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py makemigrations --merge
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py migrate
|
2021-04-27 22:37:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_app_settings {
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2022-02-02 21:42:33 +01:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2021-04-27 22:37:37 +02:00
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
secret_key=$(ynh_app_setting_get --app=$app --key=secret_key)
|
|
|
|
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user="$db_name"
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
}
|
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
|
|
|
# EXPERIMENTAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
2019-02-10 20:04:23 +01:00
|
|
|
# FUTURE OFFICIAL HELPERS
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|