2020-04-01 21:38:44 +02:00
#!/bin/sh
2020-04-09 21:48:20 +02:00
# v0.3.1 - "try to force Github to accept this change"-release
2020-04-06 21:02:13 +02:00
set -f
2020-04-01 21:38:44 +02:00
# set the following variables accordingly to your site
# the admin will get a notification mail in BCC
2020-04-02 21:50:23 +02:00
# the following lines should be moved to a config file, eg. /usr/local/etc/cleanup_friendica.conf
#friendicapath="/var/www/net/nerdica.net/friendica"
#site="SITE"
#siteurl="https://domain.tld/"
#siteadmin="admin@domain.tld"
#sitefrom="no-reply@domain.tld"
2020-04-03 00:11:24 +02:00
#protectedusers="admin1 admin2 admin3"
2020-04-02 21:50:23 +02:00
2020-04-06 21:02:13 +02:00
. /usr/local/etc/cleanup_friendica.conf
2020-04-02 21:50:23 +02:00
2020-04-01 21:38:44 +02:00
cd ${ friendicapath } || exit 0
# delete users that never logged in and never posted content
# filtering for "weeks" will result in accounts with 2 weeks old accounts,
# filter for just "week" will do the same after 1 week.
# same should apply to "month" and "months", but untested.
2020-04-03 00:11:24 +02:00
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
2020-04-06 21:02:13 +02:00
if [ -n " ${ protectedusers } " ] ; then
pcheck = 0
for s in $( echo ${ protectedusers } ) ; do
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
2020-04-03 00:11:24 +02:00
fi
2020-04-01 21:38:44 +02:00
done
# find & notify users that didn't logged in >6 months and send mail to log in again
for u in $( ${ friendicapath } /bin/console user list active -c 10000 | grep -v '.*---.*' | sed 's/|/;/g' | tr -s "\ " | sed 's/^;\ //g' | sed 's/\ ;\ /;/g' | sed 's/\ /_/g' | tail -n +2 ) ; do
2020-04-01 23:06:09 +02:00
username = $( echo " ${ u } " | awk -F ";" '{print $1}' )
2020-04-01 21:38:44 +02:00
dispname = $( echo " ${ u } " | awk -F ";" '{print $2}' )
profileurl = $( echo " ${ u } " | awk -F ";" '{print $3}' )
usermail = $( echo " ${ u } " | awk -F ";" '{print $4}' )
registered = $( echo " ${ u } " | awk -F ";" '{print $5}' )
lastlogin = $( echo " ${ u } " | awk -F ";" '{print $6}' )
lastpost = $( echo " ${ u } " | awk -F ";" '{print $7}' )
#echo "Userinfo: ${username},${dispname},${profileurl},${usermail},${registered},${lastlogin},${lastpost}"
res = $( echo " ${ lastlogin } " | grep '[6-9]_months.*' )
if [ -n " ${ res } " ] ; then
num_months = $( echo " ${ res } " | awk -F "_" '{ print $1}' )
#echo "months: ${num_months}"
if [ ${ num_months } -ge 7 ] ; then
# delete account when last login is older than 7 months and send mail about deletion
# you should copy & paste the text from 6 months for the first runs of this script
# and later change the text to a notification that the account has been deleted.
( cat <<EOF
Dear ${ dispname } ,
2020-04-09 21:48:20 +02:00
you have registered on ${ siteurl } ${ registered } and last time you logged in was ${ lastlogin } .
2020-04-01 21:38:44 +02:00
Your latest post - if any - was ${ lastpost } .
2020-04-09 21:48:20 +02:00
Since you haven't reacted to the previous mails and didn' t login again, your account including all your data has now been deleted.
2020-04-01 21:38:44 +02:00
Sincerely,
your ${ site } admins
EOF
2020-04-09 21:48:20 +02:00
) | sed 's/_/\ /g' | /usr/bin/mail -s " Your account ${ username } on ${ site } has been deleted! " -r " ${ sitefrom } " -b " $siteadmin " -- " ${ usermail } "
2020-04-03 00:11:24 +02:00
# if username is a protected user do nothing, else delete user
2020-04-06 21:02:13 +02:00
if [ -n " ${ protectedusers } " ] ; then
pcheck = 0
for s in $( echo ${ protectedusers } ) ; do
if [ " ${ s } " = " ${ username } " ] ; then
pcheck = 1
fi
done
if [ ${ pcheck } -eq 0 ] ; then
echo " Delete user ${ username } "
2020-04-09 21:48:20 +02:00
${ friendicapath } /bin/console user delete " ${ username } " -q
2020-04-06 21:02:13 +02:00
fi
2020-04-03 00:11:24 +02:00
fi
2020-04-01 21:38:44 +02:00
elif [ ${ num_months } -eq 6 ] ; then
# mail the user and ask to re-login
( cat <<EOF
Dear ${ dispname } ,
2020-04-09 21:48:20 +02:00
you have registered on ${ siteurl } ${ registered } and last time you logged in was ${ lastlogin } .
2020-04-01 21:38:44 +02:00
Your latest post - if any - was ${ lastpost } .
If you want to continue to keep your account on Nerdica then please log in at least every 6 months to keep your account alive. Otherwise we assume that you don' t want to use it anymore and will cancel your account 7 months after your last login.
You can access your profile at ${ profileurl } or you can cancel your account on your own when logged in at ${ siteurl } /removeme - however we would like to see you become an active user again and contribute to the Fediverse, but of course it' s up to you.
Sincerely,
your ${ site } admins
EOF
) | sed 's/_/\ /g' | /usr/bin/mail -s " The Fediverse misses you, ${ username } ! " -r " ${ sitefrom } " -b " $siteadmin " -- " ${ usermail } "
fi
fi
done