#!/bin/bash
# version 1.1
hn=$(hostname)
place=$(hostname | awk -F'.' '{print $1}')
# https://mail.loni.org/mailman/admin/LIST-NAME
# place can be emac3, scusa0, hpc, lonimail
rsyncDest="rsync://isaac.lsu.edu/mailman-${place}"
LISTS='/usr/lib/mailman/bin/list_lists'
MEMBERS='/usr/lib/mailman/bin/list_members'
CONFIG='/usr/lib/mailman/bin/config_list'
PARENT='/tmp/html'
dest="${PARENT}/${place}"
idx="${dest}/index.html"
allSubscribers="${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 "Mailing List Reports for ${place}" >> ${idx}
echo "
People and the mailing lists they are subscribed to
" >> ${idx}
echo "" >> ${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}"
echo " - admin config ${name} - ${desc}
" >> ${idx}
# now make html file of members of each list
lst="${dest}/${name}.html"
echo "" > ${lst}
echo "" >> ${lst}
echo "${name} on ${place}
" >> ${lst}
echo "" >> ${lst}
echo "
" >> ${lst}
${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 ${place}
" >> ${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}
echo "Pushing html to server"
rsync -avr -4 ${dest}/ ${rsyncDest}/