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
ETC="${ROOT}etc"
GITCMD="GIT_DIR=$ETC/.git GIT_WORK_TREE=$ETC git"

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

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.

${ROOT}/etc/portage/bashrc:

...
    "postinst")
        etc-update 0</dev/tty 1>/dev/tty
...

Version control for Gentoo make.conf, USE flags

Introduction

I have recently implemented etckeeper and metastore to keep my Gentoo server:/etc directory under version control. Object of interest today is how to make a good git commit message regarding Gentoo’s /etc/make.conf and the long long USE flags (possibly multi-)line in there. Usually these USE flag changes happen in the process of reconfiguring some packages. I often don’t commit make.conf changes immediately and then after a few days can’t remember anymore what USE flags have changed and why to make a meaningful commit message.
(more…)

less is also tail, who knew?

Can’t believe I hadn’t come across this one before anywhere. You know the scenario when you’re debugging some wack crash or non-functionality in your Linux box and doing this over and over again:

less /var/log/messages

for reviewing what happened, then CTRL+C and:

tail -f /var/log/messages

to monitor what happens when you changed something.

Well how about just staying in less and pressing F. Discovered from less’ very own help page.

F Forward forever; like "tail -f"