#!/bin/sh # v0.3.1 - "try to force Github to accept this change"-release set -f # set the following variables accordingly to your site # the admin will get a notification mail in BCC # 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" #protectedusers="admin1 admin2 admin3" . /usr/local/etc/cleanup_friendica.conf cd ${friendicapath} || exit 0 # notify the user that s/he needs to re-login after 6 months to prevent account deletion notifyUser () { ( cat <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 username=$(echo "${u}" | awk -F ";" '{print $1}') 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}') res=$(echo "${lastlogin}" | grep -e'[6-9]\ months.*' -e '1[012]\ months.*' -e 'year') if [ -n "${res}" ]; then num_months=$(echo "${res}" | awk -F "_" '{ print $1}') monthyear=$(echo "${res}" | awk -F "_" '{ print $2}' | sed -e 's/s//g') # remove the "s" in months and years if [ "${monthyear}" = "month" ] ; then if [ ${num_months} -ge 7 ] ; then DELUSER=true elif [ ${num_months} -eq 6 ]; then # mail the user and ask to re-login DELUSER=false notifyUser fi elif [ "${monthyear}" = "year" ]; then DELUSER=true fi if [ "${DELUSER}" = "true" ]; 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. # if username is a protected user do nothing, else delete user 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 notifyUserDeletion fi fi fi fi done