diff --git a/hooks/post_user_delete b/hooks/post_user_delete index 549f52b..5fc0224 100644 --- a/hooks/post_user_delete +++ b/hooks/post_user_delete @@ -11,7 +11,7 @@ env_path=$final_path/envs/prod pushd $final_path source $final_path/venv/bin/activate - envdir $env_path python3 $final_path/manage.py shell <<< " + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py shell <<< " from django.contrib.auth import get_user_model User = get_user_model() try: diff --git a/scripts/install b/scripts/install index d64332d..8ba34b6 100755 --- a/scripts/install +++ b/scripts/install @@ -150,24 +150,24 @@ echo $staff_token > $env_path/STAFF_TOKEN ynh_script_progression --message="Initializing Python virtualenv..." --weight=20 pushd $final_path || ynh_die - python3 -m venv $final_path/venv - source $final_path/venv/bin/activate - python3 -m pip install -U wheel pip setuptools - python3 -m pip install --requirement $final_path/requirements.txt - python3 -m pip install --requirement $final_path/requirements-setup.txt - python3 -m pip install --requirement $final_path/requirements-ynh.txt - deactivate 'dummy_arg' + chown -R $app:$app $final_path + sudo -u $app python3 -m venv $final_path/venv + sudo -u $app $final_path/venv/bin/python -m pip install -U wheel pip setuptools + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements.txt + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements-setup.txt + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements-ynh.txt + chown -R root:root $final_path popd || ynh_die #================================================= # INITIALIZE DATABASE #================================================= pushd $final_path || ynh_die - source $final_path/venv/bin/activate - envdir $env_path python3 $final_path/manage.py makemigrations - envdir $env_path python3 $final_path/manage.py migrate - envdir $env_path python3 $final_path/manage.py createsuperuser --username "$admin" --email "$admin_email" --noinput -v 0 - deactivate 'dummy_arg' + chown -R root:$app $final_path + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py makemigrations + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py migrate + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py createsuperuser --username "$admin" --email "$admin_email" --noinput -v 0 + chown -R root:root $final_path popd || ynh_die #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 5ce914f..8b65935 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -98,12 +98,13 @@ ynh_system_user_create --username=$app ynh_script_progression --message="Upgrading Python virtualenv..." --weight=2 pushd $final_path || ynh_die - source $final_path/venv/bin/activate - python3 -m pip install -U wheel pip setuptools - python3 -m pip install -U --requirement $final_path/requirements.txt - python3 -m pip install -U --requirement $final_path/requirements-setup.txt - python3 -m pip install -U --requirement $final_path/requirements-ynh.txt - deactivate 'dummy_arg' + chown -R $app:$app $final_path + sudo -u $app python3 -m venv $final_path/venv + sudo -u $app $final_path/venv/bin/python -m pip install -U wheel pip setuptools + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements.txt + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements-setup.txt + sudo -u $app $final_path/venv/bin/python -m pip install -U --requirement $final_path/requirements-ynh.txt + chown -R root:root $final_path popd || ynh_die #================================================= @@ -112,10 +113,10 @@ popd || ynh_die ynh_script_progression --message="Performing database migrations..." --weight=2 pushd $final_path || ynh_die - source $final_path/venv/bin/activate - envdir $final_path/envs/prod python3 $final_path/manage.py makemigrations - envdir $final_path/envs/prod python3 $final_path/manage.py migrate - deactivate 'dummy_arg' + chown -R root:$app $final_path + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py makemigrations + sudo -u $app $final_path/venv/bin/envdir $env_path python3 $final_path/manage.py migrate + chown -R root:root $final_path popd || ynh_die #=================================================