If you want to continue to keep your Mastodon account on Nerdculture then please log in at least every 6 months via web browser to keep your account alive. Otherwise we assume that you don't want to use it anymore and will deactivate your account 7 months after your last login (and delete it later).
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}" -- "${usermail}"
# add '-b "$siteadmin"' before the "--" above to receive BCC mails
# notify user that the account has been deleted because of inactivity
notifyUserDisable (){
( cat <<EOF
Dear ${dispname},
you have registered your account on ${siteurl} at ${registered} and last time you logged in was at ${lastlogin}.
Since you haven't reacted to the previous mails and didn't login again, your account including all your data has now been deactivated and will be deleted at a (random) later time.
Sincerely,
your ${site} admins
EOF
)| sed 's/_/\ /g'| /usr/bin/mail -s "Your account ${username} on ${site} has been deleted!" -r "${sitefrom}" -- "${usermail}"
# add '-b "$siteadmin"' before the "--" above to receive BCC mails
# 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.
#for username in $( ${mastodonpath}/bin/tootctl user list active -c 10000 | grep 'never.*never' | grep weeks | awk '{print $2}') ; do
# select a.id, username, email, current_sign_in_at from accounts a, users u where domain is null and a.id=u.account_id and current_sign_in_at <'2019-01-01'
case${mode} in
"cron")
# get the total number of deactivated accounts
# the intention is that you can better judge how often you need to invoke the cron option
# or by increasing the limit_delete variable
# the backlog queue shouldn't pile up but also not run empty to fast to reduce the load
num_deactivated_overgrace=$(psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select count(username) from accounts a, users u where disabled is true and a.id=u.account_id and current_sign_in_at < now()-'${DELDELIMIT}'::interval and username not in ($sqlprotectedusers)"| tr -d " ")
num_deactivated_total=$(psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select count(username) from accounts a, users u where disabled is true and a.id=u.account_id and username not in ($sqlprotectedusers)"| tr -d " ")
for u in $(psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select concat(username||';'||display_name||';'||email||';'||to_char(a.created_at, 'YYYY-MM-DD')||';'||to_char(current_sign_in_at,'YYYY-MM-DD')) from accounts a, users u where disabled is true and a.id=u.account_id and current_sign_in_at < now()-'${DELDELIMIT}'::interval and username not in ($sqlprotectedusers) order by current_sign_in_at limit ${limit_delete}"| tr -d " ");do
# find & notify users that didn't logged in >6 months and send mail to log in again#psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select concat(username||';'||email) from accounts a, users u where domain is null and a.id=u.account_id and current_sign_in_at is null and u.created_at < now()-'2 weeks'::interval" | tr -d " "
#for username in $(psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select a.id, username, email, current_sign_in_at from accounts a, users u where domain is null and a.id=u.account_id and current_sign_in_at <'2019-01-01'" )
for line in $(psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select concat(username||','||email) from accounts a, users u where domain is null and a.id=u.account_id and current_sign_in_at is null and u.created_at < now()-'2 weeks'::interval and username not in (${sqlprotectedusers})"| tr -d " ");do
#echo ${line}
username=$(echo${line}| cut -f1 -d",")
mail=$(echo${line}| cut -f2 -d",")
# if username is a protected user do nothing, else delete user
#for u in $( ${mastodonpath}/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 | grep -i -v -E ${protected} ); do
for mode2 in $(echo"warn disable");do
#echo "mode2: $mode2"
case${mode2} in
"warn")
#echo "in warn"
SQLSTATE="current_sign_in_at between now()-'${UPPERLIMIT}'::interval and now()-'${LOWERLIMIT}'::interval"
for u in $( psql -U ${DB_USER} -w -h ${DB_HOST} -p ${DB_PORT} -t ${DB_NAME} -c "select concat(username||';'||display_name||';'||email||';'||to_char(a.created_at, 'YYYY-MM-DD')||';'||to_char(current_sign_in_at,'YYYY-MM-DD')) from accounts a, users u where domain is null and a.id=u.account_id and ${SQLSTATE} and username not in ($sqlprotectedusers) order by current_sign_in_at"| tr -d " ");do
#echo ${u}
username=$(echo"${u}"| awk -F ";"'{print $1}')
dispname=$(echo"${u}"| awk -F ";"'{print $2}')
profileurl="https://nerdculture.de/@${username}"
usermail=$(echo"${u}"| awk -F ";"'{print $3}')
registered=$(echo"${u}"| awk -F ";"'{print $4}')
lastlogin=$(echo"${u}"| awk -F ";"'{print $5}')
case${mode2} in
"warn")
if["${mode}"="hotrun"];then
#echo -n "hotrun "
notifyUser
elif["${mode}"="dryrun"];then
echo"Check ${username}: notify skipped because of dryrun."
fi
num_notified=$((num_notified+1))
;;
"disable")
# 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.
# if username is a protected user do nothing, else delete user