TIP Making portage use /usr/sbin/sendmail to send out ELOG mails

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other



Note: Starting with Portage 2.1.1, it is possible to specify /usr/sbin/sendmail in the PORTAGE_ELOG_MAILURI. This will make Portage use /usr/sbin/sendmail to send out the mail. Because of this, the TIP is now obsolete! See /etc/make.conf.example for further details.
PORTAGE_ELOG_MAILURI="recipient@example.net /usr/sbin/sendmail"



I didn't want to install a full fledged MTA like Postfix, Exim or qmail on my system but have setup ssmtp to send out my mails just fine. As I dislike duplicating configuration, I wanted to have Portage use ssmtp to send out mails generated by the PORTAGE_ELOG feature of Portage 2.1. Or, to put it more general, portage should send out mails using /usr/sbin/sendmail (or /usr/lib/sendmail) instead of SMTP.

To do this, I made sure that PORTAGE_ELOG_SYSTEM does NOT contain "mail" but at least "custom" (an additional "save" is fine as well) in /etc/make.conf. Further, the PORTAGE_ELOG_COMMAND needs to be set.

PORTAGE_ELOG_SYSTEM="custom"
PORTAGE_ELOG_COMMAND="/usr/local/bin/portage-elog-command.sh to@example.com from@example.net '\${PACKAGE}' '\${LOGFILE}'"

Here, to@example.com needs to be replaced by the recipient address (think PORTAGE_ELOG_MAILURI) and from@example.net needs to be replaced by the sender address (think PORTAGE_ELOG_MAILFROM). The backslahes (\) before the ${PACKAGE} and ${LOGFILE} are important - it must read \${PACKAGE} and \${LOGFILE}!

Next, the script referenced by PORTAGE_ELOG_COMMAND needs to be created.

Code: Script called by PORTAGE_ELOG_COMMAND "/usr/local/bin/portage-elog-command.sh"
#! /bin/sh

# Recipient address
to="$1"
# Sender address
from="$2"
# ${PACKAGE} - expands to the cpv entry of the processed
# package (see $PVR in ebuild(5))
pvr="$3"
# ${LOGFILE} - absolute path to the logfile - This will
# make up the e-mail body
log_file="$4"

# Name of the host from which this mail is sent
hostname=`hostname -f`
# Sender "full name"
from_fullname="Portage Log Message"

( printf "From: %s (%s)\nTo: %s\nSubject: [portage] ebuild log for %s on %s\n\n" \
        "$from" "$from_fullname" "$to" "$pvr" "$hostname"
  cat "$log_file"
) | sendmail -bm "$to"


if the e-mails have empty bodies, change the second last line to: "/${log_file#*/}"

Personal tools