#!/bin/bash
# version 1.1
hn=$(hostname)
# https://mail.loni.org/mailman/admin/LIST-NAME
# place can be emac3, scusa0, hpc, lonimail
# rsyncDest="rsync://isaac.lsu.edu/mailman-${hn}"
rsyncDest="rsync://mail.si.hpc.lsu.edu"
LISTS='/usr/lib/mailman/bin/list_lists'
MEMBERS='/usr/lib/mailman/bin/list_members'
CONFIG='/usr/lib/mailman/bin/config_list'
VERIFY='/root/bin/verify-file-of-email-addresses.bash'
PARENT='/tmp/mailinglists'
dest="${PARENT}/${hn}"
idx="${dest}/index.html"
allSubscribers="${PARENT}/allBoth.txt"
allEmails="${PARENT}/allUnsorted.txt"
allEmailsS="${PARENT}/all.txt"
users="${PARENT}/people.txt"
usersHtml="${dest}/people.html"
rm -rf ${PARENT}
mkdir -p ${dest}
echo "Generating html..."
echo "" > ${idx}
echo "
" >> ${idx}
echo "" >> ${idx}
echo "List Name | Member addresses | Member Count | Mailman Admin | Text Config | Decription |
" >> ${idx}
${LISTS} | grep -v 'matching mailing lists found' | sort -u | while read line
do
echo " Processing: ${line}"
name=$(echo ${line} | awk '{print $1}')
desc=$(echo ${line} | sed "s/^${name} - //")
cfgName="${name}-config.html"
cfg="${dest}/${cfgName}"
admin="http://${hn}/mailman/admin/${name}"
cnt=$(${MEMBERS} -f ${name} | sort -u | wc -l)
echo "${name} | ${cnt} | members | admin | config | ${desc} |
" >> ${idx}
# now make html file of members of each list
lst="${dest}/${name}.html"
echo "" > ${lst}
echo "" >> ${lst}
echo "${name} on ${hn}
" >> ${lst}
echo "" >> ${lst}
echo "
" >> ${lst}
${MEMBERS} ${name} | sort -u >> ${allEmails}
${MEMBERS} -f ${name} | sort -u | while read line
do
email=$(echo ${line} | sed 's/(/' | sed 's/>/)/')
echo "- ${email}
" >> ${lst}
# write out email and list to all list
echo "${email}|${name}" >> ${allSubscribers}
done
echo "" >> ${lst}
echo "Page generated $(date)
" >> ${lst}
echo "" >> ${lst}
echo "" >> ${lst}
# now dump out config of list
${CONFIG} -o /tmp/${cfgName}.txt ${name}
sed -i 's/&/\&/g' /tmp/${cfgName}.txt
sed -i 's/\</g' /tmp/${cfgName}.txt
sed -i 's/>/\>/g' /tmp/${cfgName}.txt
echo "" > ${cfg}
echo "" >> ${cfg}
echo "${name} config on ${hn}
" >> ${cfg}
echo "" >> ${cfg}
echo "
" >> ${cfg}
cat /tmp/${cfgName}.txt >> ${cfg}
rm -f /tmp/${cfgName}.txt
echo "
" >> ${cfg}
echo "Page generated $(date)
" >> ${cfg}
echo "" >> ${cfg}
echo "" >> ${cfg}
done
echo "
" >> ${idx}
echo "Page generated $(date)
" >> ${idx}
echo "" >> ${idx}
echo "" >> ${idx}
# now make list by subscriber
sort ${allSubscribers} > ${allSubscribers}.sort
cat ${allSubscribers}.sort | awk -F'|' '{print $1}' | sort -u > ${users}
echo "Generating html for people list..."
echo "" > ${usersHtml}
echo "" >> ${usersHtml}
echo "List of all subscribers and the lists they belong to
" >> ${usersHtml}
echo "" >> ${usersHtml}
cat ${users} | while read line
do
printf "- ${line}: " >> ${usersHtml}
tmmp=$(grep "${line}" ${allSubscribers} | awk -F'|' '{print $2}')
tmp=$(echo ${tmmp})
printf "${tmp}
\n" >> ${usersHtml}
done
echo "
" >> ${usersHtml}
echo "
" >> ${usersHtml}
echo "Page generated $(date)
" >> ${usersHtml}
echo "" >> ${usersHtml}
echo "" >> ${usersHtml}
# now do email verification
echo "now do email verification"
${MEMBERS} users | sort -u > ${PARENT}/users.txt
logger "[mail_verification] USERS email verification started"
${VERIFY} users
logger "[mail_verification] USERS email verification completed"
sort -u ${allEmails} > ${allEmailsS}
logger "[mail_verification] ALL email verification started"
${VERIFY} all
logger "[mail_verification] ALL email verification completed"
logger "[mail_verification] RSYNC email verification started"
echo "Pushing html to server"
rsync -avr -4 ${dest}/ ${rsyncDest}/mailman-${hn}/
rsync -avr -4 ${PARENT}/users/ ${rsyncDest}/mail_verification-${hn}/users/
rsync -avr -4 ${PARENT}/all/ ${rsyncDest}/mail_verification-${hn}/all/
logger "[mail_verification] RSYNC email verification completed"
# rm -rf ${PARENT}