Using interactive commands during emerge ebuild phases

Gentoo Portage’s primary tool emerge is largely meant to run as a non-interactive process. Meaning aside from the –ask flag making it get user confirmation before beginning operations, rest of the process is supposed to finish without any further user input.

This mostly makes sense, because compiling software can be a lengthy process. Even more so when you’re possibly emerging tens of packages at a time. It makes no sense for the user to guard the terminal and stare at the Matrix, waiting to answer the occasional, usually trivial Yes/No prompt.

But in this particular use case I have, I’ve discovered I’d like to run an interactive command etc-update after every package finishes installing (ebuild postinst phase). My goal is to have a firm grip on a vserver bootstrap template configuration with the help of git. Portage’s configuration protection litters /etc with ._cfg* files and I would rather not spread the litter to the git repo by just blindly committing everything in postinst. Also, maintaining the bootstrap template is usually a rare and short operation (few packages at a time) where I can monitor the build and act on request.

Your ${ROOT}/etc/portage/bashrc could have something like this:

echo Phase: $EBUILD_PHASE

case "$EBUILD_PHASE" in
        STATUS=$(eval $GITCMD status -uno -s)
        [ -n "${STATUS}" ] && die "Error: $ETC is not clean"
        eval $GITCMD add $ETC
        eval $GITCMD commit -q -a -m \"emerge $CATEGORY/$P\"

Problem is that emerge pipes everything to its logfiles and won’t let etc-update get any input from you. Some googling revealed a solution by redirecting stdin and stdout. /dev/tty is magic that always has the right answer, google it yourself for details.


        etc-update 0</dev/tty 1>/dev/tty