Gentoo Archives: gentoo-dev

From: Jonas Geiregat <yux@××××××.org>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Bashrc mini HOWTO
Date: Wed, 25 May 2005 20:02:49
Message-Id: 4294D9E5.2070304@sdf-eu.org
In Reply to: [gentoo-dev] Bashrc mini HOWTO by Chris White
1 Chris White wrote:
2
3 >Hi guys,
4 >
5 > 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).
6 >
7 >HOW DOES IT WORK
8 >
9 >if [ -f "${PORTAGE_BASHRC}" ]; then
10 > source "${PORTAGE_BASHRC}"
11 >
12 >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.
13 >
14 >LET'S USE IT
15 >
16 > case "$*" in
17 > # stay really quiet here.
18 > depend) : ;;
19 > *)
20 > [ "$*" = "compile" ] && package-pre-compile
21 > [ "$*" = "postinst" ] && package-post-install
22 > ;;
23 > esac
24 >
25 >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.
26 >
27 >ENVIRONMENTAL VARIABLES
28 >
29 >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:
30 >
31 > package-post-install() {
32 > PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
33 >
34 >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:
35 >
36 > if has whatis ${FEATURES} && test -x /usr/sbin/makewhatis ; then
37 > echo "*** whatis enabled. Updating the whatis database..."
38 > # update the whatis database
39 > `makewhatis -u`
40 > fi
41 > }
42 >
43 >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:
44 >
45 >addread
46 >addwrite
47 >adddeny
48 >addpredict
49 >esyslog
50 >use
51 >usev
52 >useq
53 >has
54 >hasv
55 >hasq
56 >has_version
57 >portageq
58 >best_version
59 >use_with
60 >use_enable
61 >diefunc
62 >check_KV
63 >keepdir
64 >unpack
65 >strip_duplicate_slashes
66 >all the stuff described in man 5 ebuild (too lazy to list here)
67 >killparent
68 >remove_path_entry
69 >do_newdepend
70 >inherit (yes.. you can inherit eclasses.. weird ain't it...)
71 >debug-print-function
72 >debug-print-section
73 >
74 >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 ;).
75 >
76 >Chris White
77 >
78 >
79 I gave this a quick look, and aren't you talking about bash scripts in
80 general rather then .bashrc files using /etc/portage/bashrc as reference
81 for this document.
82 Also I can't see the real use , that's why I started reading then
83 quickly scanned through it .. and now I'm writting this email ..
84 --
85 gentoo-dev@g.o mailing list

Replies

Subject Author
Re: [gentoo-dev] Bashrc mini HOWTO Alec Warner <warnera6@×××××××.edu>