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
|
|
|
#=================================================
|
2022-06-21 00:05:59 +02:00
|
|
|
|
2019-03-05 23:17:15 +01:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-04-27 22:37:37 +02:00
|
|
|
function set_permissions {
|
2024-03-04 12:04:56 +01:00
|
|
|
mkdir -p $data_dir
|
2021-04-27 22:37:37 +02:00
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
env_path=$install_dir/envs/prod
|
2021-04-27 22:37:37 +02:00
|
|
|
mkdir -p $env_path
|
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
chown -R $app:$app $data_dir
|
|
|
|
chmod o-rwx $data_dir
|
|
|
|
setfacl -n -R -m u:www-data:rx -m d:u:www-data:rx $data_dir
|
2021-04-27 22:37:37 +02:00
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
chown -R root:$app $install_dir
|
|
|
|
chmod -R g=u,g-w,o-rwx $install_dir
|
|
|
|
setfacl -n -R -m user:www-data:rx -m default:user:www-data:rx $install_dir
|
|
|
|
setfacl -n -R -m user:www-data:- -m default:user:www-data:- $install_dir/envs
|
2021-04-27 22:37:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_up_virtualenv {
|
2024-03-04 12:04:56 +01:00
|
|
|
env_path=$install_dir/envs/prod
|
2021-04-27 22:37:37 +02:00
|
|
|
mkdir -p $env_path
|
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
pushd $install_dir || ynh_die
|
|
|
|
chown -R $app:$app $install_dir
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app python3 -m venv $install_dir/venv
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/pip --cache-dir $install_dir/.cache/pip install -U wheel pip --cache-dir $install_dir/.cache/pip setuptools
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/pip --cache-dir $install_dir/.cache/pip install -U --requirement $install_dir/requirements.txt
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/pip --cache-dir $install_dir/.cache/pip install -U --requirement $install_dir/requirements-setup.txt
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/pip --cache-dir $install_dir/.cache/pip install -U --requirement $install_dir/requirements-ynh.txt
|
2021-04-27 22:37:37 +02:00
|
|
|
set_permissions
|
|
|
|
popd || ynh_dies
|
|
|
|
}
|
|
|
|
|
|
|
|
function initialize_db {
|
2024-03-04 12:04:56 +01:00
|
|
|
pushd $install_dir || ynh_die
|
|
|
|
chown -R $app:$app $install_dir
|
2021-04-27 22:37:37 +02:00
|
|
|
perform_db_migrations
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/envdir $env_path $install_dir/venv/bin/python $install_dir/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 {
|
2024-03-04 12:04:56 +01:00
|
|
|
pushd $install_dir || ynh_die
|
|
|
|
chown -R $app:$app $install_dir
|
2021-04-27 22:37:37 +02:00
|
|
|
perform_db_migrations
|
|
|
|
set_permissions
|
|
|
|
popd || ynh_die
|
|
|
|
}
|
|
|
|
|
|
|
|
function perform_db_migrations {
|
2024-03-04 12:04:56 +01:00
|
|
|
echo "y" | ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/envdir $env_path $install_dir/venv/bin/python $install_dir/manage.py makemigrations --merge
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/envdir $env_path $install_dir/venv/bin/python $install_dir/manage.py migrate
|
2021-04-27 22:37:37 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
#=================================================
|