* [gentoo-dev] Bashrc mini HOWTO
@ 2005-05-25 6:40 Chris White
2005-05-25 20:02 ` Jonas Geiregat
0 siblings, 1 reply; 8+ messages in thread
From: Chris White @ 2005-05-25 6:40 UTC (permalink / raw
To: gentoo-dev
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-25 6:40 [gentoo-dev] Bashrc mini HOWTO Chris White
@ 2005-05-25 20:02 ` Jonas Geiregat
2005-05-25 22:37 ` Alec Warner
0 siblings, 1 reply; 8+ messages in thread
From: Jonas Geiregat @ 2005-05-25 20:02 UTC (permalink / raw
To: gentoo-dev
Chris White wrote:
>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
>
>
I gave this a quick look, and aren't you talking about bash scripts in
general rather then .bashrc files using /etc/portage/bashrc as reference
for this document.
Also I can't see the real use , that's why I started reading then
quickly scanned through it .. and now I'm writting this email ..
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-25 20:02 ` Jonas Geiregat
@ 2005-05-25 22:37 ` Alec Warner
2005-05-25 22:47 ` Jonas Geiregat
0 siblings, 1 reply; 8+ messages in thread
From: Alec Warner @ 2005-05-25 22:37 UTC (permalink / raw
To: gentoo-dev
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jonas Geiregat wrote:
<snip ChrisWhite>
> I gave this a quick look, and aren't you talking about bash scripts in
> general rather then .bashrc files using /etc/portage/bashrc as reference
> for this document.
> Also I can't see the real use , that's why I started reading then
> quickly scanned through it .. and now I'm writting this email ..
normal bash scripts aren't sourced by portage when ebuilds are being
processed. Only PORTAGE_BASHRC ( current /etc/portage/bashrc ) is
sourced. Thus you can do cool stuff like print debug info, over-ride
default functions, and otherwise other fun stuff that normally would be
a complete PITA, especially if you don't know portage internals well.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iQIVAwUBQpT+LmzglR5RwbyYAQKXWQ/+KjdNLnZlokuD2rKPXwgsYRzeLpmZtMs5
Qm7k+gakIuO9tMlbnYFUm5vaZxif+IaPDWeMRSpshOWA94G7kTx22bytMc7axu5J
xlIrVjajHip96nHrGYNklETUEtbt9tm+1nLYpoLAjfejXby2QnTd8+GANaZ1Lqwz
SzgJA6IYNXtIk6Xu6mZE0V+Fpizmflvii+UueviwH9+UzKR6SKrYjZmBTU5NAjGv
uy4kcTMNkl3LZMKu5P9yKV3NYOX0YABrgxpfhtbgZJsBC4a2a3Y8XLymmKcTeMUS
AIP1o6V/h+dWfU9H5PuQsYvBsmfMK06thWTAZF411FFZLXk+HhKo9De0nQvkaM9H
P+P5UwXgEdlJLk7k2oq1eE09klDRegzZGEVs6mcxk9b6qQ9d8ub/8IUB1Fv68PwI
62lngdKNw7BND1IRwBuyNXD1JOoUHYZuSO1CHyraneij5NunSiwqwLl8sbqsXmqJ
riuvaIuWPce37CS3Pmg55eh42aW8ikHpjusDMmSAGh8ffsdW6ogHi4sHwBMMDpEf
c2/ybSZU5cK13csDaPPcaadhNZWPXFOs1pLphOfCoe+3ia0W2cjQruI1jdL2CG2y
nO7NYLmUZ50xELvawmEPXKu76O6qbV0JB2J2SKFgAExV+GXFSGdpPoZiLyLWnSMF
6r8juJ5CpeE=
=W3Pe
-----END PGP SIGNATURE-----
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-25 22:37 ` Alec Warner
@ 2005-05-25 22:47 ` Jonas Geiregat
2005-05-25 23:41 ` Jason Stubbs
2005-05-25 23:55 ` [gentoo-dev] " Duncan
0 siblings, 2 replies; 8+ messages in thread
From: Jonas Geiregat @ 2005-05-25 22:47 UTC (permalink / raw
To: gentoo-dev
Alec Warner wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Jonas Geiregat wrote:
><snip ChrisWhite>
>
>
>>I gave this a quick look, and aren't you talking about bash scripts in
>>general rather then .bashrc files using /etc/portage/bashrc as reference
>>for this document.
>>Also I can't see the real use , that's why I started reading then
>>quickly scanned through it .. and now I'm writting this email ..
>>
>>
>
>normal bash scripts aren't sourced by portage when ebuilds are being
>processed. Only PORTAGE_BASHRC ( current /etc/portage/bashrc ) is
>sourced. Thus you can do cool stuff like print debug info, over-ride
>default functions, and otherwise other fun stuff that normally would be
>a complete PITA, especially if you don't know portage internals well.
>
>
No such file on my system, is that the reason why I should use the cvs
version of portage, so the new version will source /etc/portage/bashrc
when it comes out of cvs ?
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.1 (GNU/Linux)
>Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
>iQIVAwUBQpT+LmzglR5RwbyYAQKXWQ/+KjdNLnZlokuD2rKPXwgsYRzeLpmZtMs5
>Qm7k+gakIuO9tMlbnYFUm5vaZxif+IaPDWeMRSpshOWA94G7kTx22bytMc7axu5J
>xlIrVjajHip96nHrGYNklETUEtbt9tm+1nLYpoLAjfejXby2QnTd8+GANaZ1Lqwz
>SzgJA6IYNXtIk6Xu6mZE0V+Fpizmflvii+UueviwH9+UzKR6SKrYjZmBTU5NAjGv
>uy4kcTMNkl3LZMKu5P9yKV3NYOX0YABrgxpfhtbgZJsBC4a2a3Y8XLymmKcTeMUS
>AIP1o6V/h+dWfU9H5PuQsYvBsmfMK06thWTAZF411FFZLXk+HhKo9De0nQvkaM9H
>P+P5UwXgEdlJLk7k2oq1eE09klDRegzZGEVs6mcxk9b6qQ9d8ub/8IUB1Fv68PwI
>62lngdKNw7BND1IRwBuyNXD1JOoUHYZuSO1CHyraneij5NunSiwqwLl8sbqsXmqJ
>riuvaIuWPce37CS3Pmg55eh42aW8ikHpjusDMmSAGh8ffsdW6ogHi4sHwBMMDpEf
>c2/ybSZU5cK13csDaPPcaadhNZWPXFOs1pLphOfCoe+3ia0W2cjQruI1jdL2CG2y
>nO7NYLmUZ50xELvawmEPXKu76O6qbV0JB2J2SKFgAExV+GXFSGdpPoZiLyLWnSMF
>6r8juJ5CpeE=
>=W3Pe
>-----END PGP SIGNATURE-----
>
>
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-25 22:47 ` Jonas Geiregat
@ 2005-05-25 23:41 ` Jason Stubbs
2005-05-26 7:03 ` Drake Wyrm
2005-05-25 23:55 ` [gentoo-dev] " Duncan
1 sibling, 1 reply; 8+ messages in thread
From: Jason Stubbs @ 2005-05-25 23:41 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]
On Thursday 26 May 2005 07:47, Jonas Geiregat wrote:
> Alec Warner wrote:
> >-----BEGIN PGP SIGNED MESSAGE-----
> >Hash: SHA1
> >
> >Jonas Geiregat wrote:
> ><snip ChrisWhite>
> >
> >>I gave this a quick look, and aren't you talking about bash scripts in
> >>general rather then .bashrc files using /etc/portage/bashrc as reference
> >>for this document.
> >>Also I can't see the real use , that's why I started reading then
> >>quickly scanned through it .. and now I'm writting this email ..
> >
> >normal bash scripts aren't sourced by portage when ebuilds are being
> >processed. Only PORTAGE_BASHRC ( current /etc/portage/bashrc ) is
> >sourced. Thus you can do cool stuff like print debug info, over-ride
> >default functions, and otherwise other fun stuff that normally would be
> >a complete PITA, especially if you don't know portage internals well.
Not knowning portage internals well means that this file should be off limits.
> No such file on my system, is that the reason why I should use the cvs
> version of portage, so the new version will source /etc/portage/bashrc
> when it comes out of cvs ?
You need to create it yourself.
Regards,
Jason Stubbs
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* [gentoo-dev] Re: Bashrc mini HOWTO
2005-05-25 22:47 ` Jonas Geiregat
2005-05-25 23:41 ` Jason Stubbs
@ 2005-05-25 23:55 ` Duncan
1 sibling, 0 replies; 8+ messages in thread
From: Duncan @ 2005-05-25 23:55 UTC (permalink / raw
To: gentoo-dev
Jonas Geiregat posted <4295006A.7000000@sdf-eu.org>, excerpted below, on
Thu, 26 May 2005 00:47:06 +0200:
> Alec Warner wrote:
>>
>>normal bash scripts aren't sourced by portage when ebuilds are being
>>processed. Only PORTAGE_BASHRC ( current /etc/portage/bashrc ) is
>>sourced. Thus you can do cool stuff like print debug info, over-ride
>>default functions, and otherwise other fun stuff that normally would be a
>>complete PITA, especially if you don't know portage internals well.
>>
> No such file on my system, is that the reason why I should use the cvs
> version of portage, so the new version will source /etc/portage/bashrc
> when it comes out of cvs ?
The purpose is simply to provide a method for local portage users aka
local system admins to modify portage's behavior, if desired, without
delving into its innards. Thus, it won't exist by default, as it then
would be part of the default portage, not simply a method by which the
local Gentoo user can change portage's behavior without digging into
portage itself. <g>
--
Duncan - List replies preferred. No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master." Richard Stallman in
http://www.linuxdevcenter.com/pub/a/linux/2004/12/22/rms_interview.html
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-25 23:41 ` Jason Stubbs
@ 2005-05-26 7:03 ` Drake Wyrm
2005-05-26 15:16 ` Jason Stubbs
0 siblings, 1 reply; 8+ messages in thread
From: Drake Wyrm @ 2005-05-26 7:03 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 652 bytes --]
Jason Stubbs <jstubbs@gentoo.org> wrote:
> > Alec Warner wrote:
[...snip...]
> > >Thus you can do cool stuff like print debug info, over-ride default
> > >functions, and otherwise other fun stuff that normally would be a
> > >complete PITA, especially if you don't know portage internals well.
>
> Not knowning portage internals well means that this file should be off
> limits.
Aww.. That's no fun. How are folks supposed to learn anything without
breaking stuff once in a while?
--
Batou: Hey, Major... You ever hear of "human rights"?
Kusanagi: I understand the concept, but I've never seen it in action.
--Ghost in the Shell
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-dev] Bashrc mini HOWTO
2005-05-26 7:03 ` Drake Wyrm
@ 2005-05-26 15:16 ` Jason Stubbs
0 siblings, 0 replies; 8+ messages in thread
From: Jason Stubbs @ 2005-05-26 15:16 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
On Thursday 26 May 2005 16:03, Drake Wyrm wrote:
> Jason Stubbs <jstubbs@gentoo.org> wrote:
> > > Alec Warner wrote:
>
> [...snip...]
>
> > > >Thus you can do cool stuff like print debug info, over-ride default
> > > >functions, and otherwise other fun stuff that normally would be a
> > > >complete PITA, especially if you don't know portage internals well.
> >
> > Not knowning portage internals well means that this file should be off
> > limits.
>
> Aww.. That's no fun. How are folks supposed to learn anything without
> breaking stuff once in a while?
To reiterate the point, you get to keep the pieces. ;)
Regards,
Jason Stubbs
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-05-26 15:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-25 6:40 [gentoo-dev] Bashrc mini HOWTO Chris White
2005-05-25 20:02 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox