public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Chris White <chriswhite@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] Bashrc mini HOWTO
Date: Wed, 25 May 2005 15:40:25 +0900	[thread overview]
Message-ID: <20050525154025.6d897c9f@localhost> (raw)

Hi guys,

	Well, I was working on my bashrc one day and thought, "gee, would be nice for other people to know what the heck is going on too!".  Well, I decided to go ahead and do that :P.  So, here we go, a mini bashrc HOWTO (note this only works on the latest stable of portage.  You go grab cvs head and try this, you can kiss yer but goodbye! :D).

HOW DOES IT WORK

if [ -f "${PORTAGE_BASHRC}" ]; then
        source "${PORTAGE_BASHRC}"

This little code in ebuild.sh pretty much sums it up.  Basically, when ebuild.sh is run with various ebuild stages (unpack, compile, postinst, etc.. etc.. etc.), it sources the bashrc file (located in /etc/portage/bashrc), giving it the exact same environment as ebuild.sh has.  So, your bashrc file pretty much ends up like a mini ebuild.  Now that we've explained that, let's get down and dirty.

LET'S USE IT

        case "$*"  in
                # stay really quiet here.
                depend) : ;;
                *)
                        [ "$*" = "compile" ] && package-pre-compile
                        [ "$*" = "postinst" ] && package-post-install
                ;;
        esac

Here's some sample code for my small bashrc file.  This is something I pulled from solar's bashrc and adjusted it a bit.  "$*" is all parameters passed to the program.  This means the ebuild stage in this particular case.  So package-pre-compile is run when the compile stage is hit, and package-post-install is run when the postinst stage is hit.  Here, depend is silenced, as ebuilds get depend'ed a LOT, things get kind of noisy.  Now that we know what stages we can run stuff at, let's see what we can do with environmental variables.

ENVIRONMENTAL VARIABLES

Well, first off portage is kind of restrictive.  That said, anything you need to pull from /usr/bin  you're probably going to have to add it to PATH:

        package-post-install() {
                        PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin

As such.  If you have program not found errors, chances are you didn't do this.  So now, what about FEATURES.  That's right,  you can actually use FEATURES as well to cook up some nice stuff.  In my case, I had portage update the whatis database when it's done installing.  This is nice because I'm horribly lazy and wouldn't have the guts to do it manually/add a cron job.  Here we go:

                        if has whatis ${FEATURES} && test -x /usr/sbin/makewhatis ; then
                                echo "*** whatis enabled.  Updating the whatis database..."
                                # update the whatis database
                                `makewhatis -u`
                        fi
        }

Alright so, remember how I said that bashrc is a mini-ebuild?  Note how you can use the same "has" command that ebuilds can.  This is because we're being sourced from ebuild.sh, and therefore have all its functions.  What does that mean?  That means you get this:

addread
addwrite
adddeny
addpredict
esyslog
use
usev
useq
has
hasv
hasq
has_version
portageq
best_version
use_with
use_enable
diefunc
check_KV
keepdir
unpack
strip_duplicate_slashes
all the stuff described in man 5 ebuild (too lazy to list here)
killparent
remove_path_entry
do_newdepend
inherit (yes.. you can inherit eclasses.. weird ain't it...)
debug-print-function
debug-print-section

And you also notice FEATURES.  It can even do all the nifty portage variables too (default and in /etc/make.conf).  So that's it, with this nice little touch you can do cool customizations to the portage process, without messing with portage code ;).

Chris White
-- 
gentoo-dev@gentoo.org mailing list


             reply	other threads:[~2005-05-25  6:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-25  6:40 Chris White [this message]
2005-05-25 20:02 ` [gentoo-dev] Bashrc mini HOWTO Jonas Geiregat
2005-05-25 22:37   ` Alec Warner
2005-05-25 22:47     ` Jonas Geiregat
2005-05-25 23:41       ` Jason Stubbs
2005-05-26  7:03         ` Drake Wyrm
2005-05-26 15:16           ` Jason Stubbs
2005-05-25 23:55       ` [gentoo-dev] " Duncan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050525154025.6d897c9f@localhost \
    --to=chriswhite@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox