1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/librephotos_ynh.git synced 2024-09-03 19:36:12 +02:00
librephotos_ynh/hooks/post_user_delete
2021-06-11 10:53:57 -04:00

38 lines
895 B
Bash

#!/usr/bin/env bash
set -a
source /usr/share/yunohost/helpers
app="${0//.\/50-}"
user=$1
purge=$2
arch="$(dpkg --print-architecture)"
arm64_test=0
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
backend_path="$final_path/backend"
path_prefix="$backend_path/venv/bin"
if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then
export CONDA_DIR="$backend_path/conda"
path_prefix="$backend_path/cmake/bin:$CONDA_DIR/condabin:$CONDA_DIR/bin:$path_prefix"
fi
pushd "$backend_path"
sudo -u $app bash -c "
set -a
export PATH=\"$path_prefix:"'$PATH'"\"
source \"$final_path\"/librephotos.env
python3 manage.py shell
" <<< "
from django.contrib.auth import get_user_model
User = get_user_model()
try:
user = User.objects.get(username='$user')
user.is_active = False
user.save()
if $purge:
user.delete()
except User.DoesNotExist:
pass
" 2>&1
popd