Commit 517fde3c authored by Claudemir Todo Bom's avatar Claudemir Todo Bom

* helper script to rename maildir and adjust databases

parent ea9341d9
Pipeline #197 passed with stage
in 1 minute and 52 seconds
#!/bin/bash
cat /etc/default/wwmail | sed -e 's/: /=/g' > /tmp/wwmail.$$.tmp
source /tmp/wwmail.$$.tmp
rm /tmp/wwmail.$$.tmp
echo "select address,maildir from users" | mysql -N -u ${WW_ISP_USER} -p${WW_ISP_PASS} ${WW_ISP_DB} | while read USER MAILDIR ; do
DOMAIN="$(echo ${USER} | sed -e 's/^.*@//')"
LOCALPART="$(echo ${USER} | sed -e 's/@.*$//')"
DOMAINDIR="/var/spool/maildir/${DOMAIN}"
if [ -e "${DOMAINDIR}" ] && ! [ -d "${DOMAINDIR}" ] ; then
echo "${DOMAINDIR} / ${USER} existe e não é um diretório - abort" 1>&2
exit 1
fi
if ! [ -e "${DOMAINDIR}" ] ; then
mkdir -p "${DOMAINDIR}"
chown mail.mail "${DOMAINDIR}"
fi
ORIG="$(dirname ${MAILDIR})/$(basename ${MAILDIR})"
DEST="/var/spool/maildir/${DOMAIN}/${LOCALPART}"
if ! [ -e "${MAILDIR}" ] ; then
echo "nao existe: ${MAILDIR}" 1>&2
if ! [ -e "${DEST}" ] ; then
echo "alterado" 1>&2
echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
continue
fi
fi
if [ "${ORIG}" == "${DEST}" ] ; then
continue
fi
if [ -e "${ORIG}" ] ; then
if [ -e "${DEST}" ] ; then
#echo "origem: ${ORIG} -> ${DEST} destino já existe: ${DEST}" 1>&2
mv "${DEST}" /var/spool/maildir/backup/
fi
mv "${ORIG}" "${DEST}"
echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
fi
done | mysql -f -N -u ${WW_ISP_USER} -p${WW_ISP_PASS} ${WW_ISP_DB}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment