Update cleanup_friendica.sh

removed bashisms and actually tested the process with protecteduser
This script works so far (for me)
This commit is contained in:
ingoj 2020-04-06 21:02:13 +02:00 committed by ingoj
parent 4ddb8a72c3
commit 1d0ce4b9e7
1 changed files with 24 additions and 9 deletions

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
set -f
# set the following variables accordingly to your site # set the following variables accordingly to your site
# the admin will get a notification mail in BCC # the admin will get a notification mail in BCC
@ -11,7 +12,7 @@
#sitefrom="no-reply@domain.tld" #sitefrom="no-reply@domain.tld"
#protectedusers="admin1 admin2 admin3" #protectedusers="admin1 admin2 admin3"
source /usr/local/etc/cleanup_friendica.conf . /usr/local/etc/cleanup_friendica.conf
cd ${friendicapath} || exit 0 cd ${friendicapath} || exit 0
@ -22,10 +23,17 @@ cd ${friendicapath} || exit 0
# same should apply to "month" and "months", but untested. # same should apply to "month" and "months", but untested.
for username in $( ${friendicapath}/bin/console user list active -c 10000 | grep 'never.*never' | grep weeks | awk '{print $2}') ; do for username in $( ${friendicapath}/bin/console user list active -c 10000 | grep 'never.*never' | grep weeks | awk '{print $2}') ; do
# if username is a protected user do nothing, else delete user # if username is a protected user do nothing, else delete user
if [[ "${protectedusers}" == *"${username}"* ]]; then if [ -n "${protectedusers}" ]; then
: pcheck=0
else for s in $(echo ${protectedusers}) ; do
${friendicapath}/bin/console user delete "${username}" -q if [ "${s}" = "${username}" ]; then
pcheck=1
fi
done
if [ ${pcheck} -eq 0 ]; then
#echo "Delete user ${username}"
${friendicapath}/bin/console user delete "${username}" -q
fi
fi fi
done done
@ -63,10 +71,17 @@ your ${site} admins
EOF EOF
) | sed 's/_/\ /g' | /usr/bin/mail -s "The Fediverse misses you, ${username}!" -r "${sitefrom}" -b "$siteadmin" -- "${usermail}" ) | sed 's/_/\ /g' | /usr/bin/mail -s "The Fediverse misses you, ${username}!" -r "${sitefrom}" -b "$siteadmin" -- "${usermail}"
# if username is a protected user do nothing, else delete user # if username is a protected user do nothing, else delete user
if [[ "${protectedusers}" == *"${username}"* ]]; then if [ -n "${protectedusers}" ]; then
: pcheck=0
else for s in $(echo ${protectedusers}) ; do
# ${friendicapath}/bin/console user delete "${u}" -q if [ "${s}" = "${username}" ]; then
pcheck=1
fi
done
if [ ${pcheck} -eq 0 ]; then
echo "Delete user ${username}"
#${friendicapath}/bin/console user delete "${username}" -q
fi
fi fi
elif [ ${num_months} -eq 6 ]; then elif [ ${num_months} -eq 6 ]; then
# mail the user and ask to re-login # mail the user and ask to re-login