Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 673816 - Make scripting prefix creation easy by passing startprefix arguments to bash and keeping the return code
Summary: Make scripting prefix creation easy by passing startprefix arguments to bash ...
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: AMD64 Linux
: Normal enhancement (vote)
Assignee: Gentoo Prefix
URL:
Whiteboard:
Keywords:
: 543714 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-12-27 12:11 UTC by Burak Arslan
Modified: 2021-01-11 20:21 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Burak Arslan 2018-12-27 12:11:04 UTC
We are using prefixed gentoo to create a standard C++ development environment for our team. After bootstrapping the prefix, we need an additional set of commands to be run inside it to install the packages that we need.

However, it's not possible to pass commands to ./startprefix script as it does not pass its arguments to the underlying bash call.

We apply the patch below to startprefix to be able to issue commands in the following way:

./prefix/startprefix -c "emerge -nvt -j2 gst-plugins-meta" || exit 15

The patch also makes sure the return value is propagated so that the parent script can detect errors and act accordingly.

diff --git a/prefix/startprefix b/prefix/startprefix
index fc13dd8..0a0126c 100755
--- a/prefix/startprefix
+++ b/prefix/startprefix
@@ -45,8 +45,10 @@ RETAIN="HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL"
 # if we're on some X terminal, makes sense to inherit that too
 [[ -n ${DISPLAY} ]] && RETAIN+=" DISPLAY=$DISPLAY"
 # do it!
-env -i $RETAIN $SHELL -l
+env -i $RETAIN $SHELL -l "$@"
+retcode=$?
 # and leave a message when we exit... the shell might return non-zero
 # without having real problems, so don't send alarming messages about
 # that
 echo "Leaving Gentoo Prefix with exit status $?"
+exit $?


Reproducible: Always
Comment 1 Fabian Groffen gentoo-dev 2018-12-27 12:35:02 UTC
isn't it sufficient to run EPREFIX/usr/bin/emerge for this purpose?
Comment 2 Benda Xu gentoo-dev 2018-12-28 01:32:52 UTC
Thanks Burak. As pointed out by Fabian, please just call EPREFIX/usr/bin/emerge directly.
Comment 3 Michael Haubenwallner (RETIRED) gentoo-dev 2019-01-07 09:55:27 UTC
Actually, I do second the OP's request - we do have similar requirements here, and a script shebang like '#! /prefix/startprefix' would be nice.
Comment 4 Fabian Groffen gentoo-dev 2019-01-07 10:41:29 UTC
Ok, let's call it "runprefix" for the moment.

I think runprefix
- should be quiet (no echos about what it's going to do, etc)
- possibly prepares a clean environment, not sure
- runs $@ with $EPREFIX/bin/sh -c
Comment 5 Michael Haubenwallner (RETIRED) gentoo-dev 2019-03-19 10:20:47 UTC
*** Bug 543714 has been marked as a duplicate of this bug. ***
Comment 6 Michael Haubenwallner (RETIRED) gentoo-dev 2019-03-19 11:04:00 UTC
I'm about to introduce some app-portage/prefix-toolkit package for things like this.

For now, these utilities come to my mind to provide:
* /runprefix: This very one.
* /startprefix: Extract from bootstrap-prefix.sh, to become updateable.
* /usr/bin/prefix-stack-setup: Set up some Stacked Prefix (EAPI 7 related, formerly called Prefix Chaining).

Thoughts? (category and package name, different/additional content, repo, ...)

For /runprefix:
Maybe this could be /usr/bin/prefixenv or /usr/bin/gentooenv or even /usr/bin/envrun, to be useful even for non-sh scripts (csh, Python, Perl, ...) - with usability similar to /usr/bin/env?

For additional content:
I've seen that we do not use toolchain-prefix-wrapper any more, but maintain the ldwrapper right within prefix-overlay/binutils-config/files/ now.  Maybe that would fit into this prefix-toolkit.git repo, to have binutils-config use the prefix-toolkit distfile instead?

For a repo:
While it may be handy to maintain the scripts right within some FILESDIR, this might not be loved by non-prefix devs at least.  There already is a proj/prefix/ namespace on gitweb.g.o, with 3 empty (sigh!) repos...
Comment 7 Larry the Git Cow gentoo-dev 2019-03-25 14:19:40 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=84b9f582e8c8db69a3b3677de702c7cc00ac3dab

commit 84b9f582e8c8db69a3b3677de702c7cc00ac3dab
Author:     Michael Haubenwallner <haubi@gentoo.org>
AuthorDate: 2019-03-20 09:35:34 +0000
Commit:     Michael Haubenwallner <haubi@gentoo.org>
CommitDate: 2019-03-25 14:18:51 +0000

    app-portage/prefix-toolkit: new package
    
    * For any Gentoo Prefix, provides the 'startprefix' script, and should
    provide some 'runprefix' script later on, as inspired in
    Bug: https://bugs.gentoo.org/673816
    
    * For base Gentoo Prefix (as in "not stacked"), provides the
    'prefix-stack-setup' script, superseding app-portage/prefix-chain-setup,
    does force the prefix-stack implit USE flag in the stacked Prefix.
    * For stacked Gentoo Prefix (set up using 'prefix-stack-setup'),
    provides the toolchain wrapper, superseding sys-apps/prefix-chain-utils.
    Bug: https://bugs.gentoo.org/658572
    
    Closes: https://bugs.gentoo.org/509142
    Package-Manager: Portage-2.3.51, Repoman-2.3.11
    Signed-off-by: Michael Haubenwallner <haubi@gentoo.org>

 app-portage/prefix-toolkit/metadata.xml            |   8 +
 app-portage/prefix-toolkit/prefix-toolkit-0.ebuild | 565 +++++++++++++++++++++
 2 files changed, 573 insertions(+)
Comment 8 Fabian Groffen gentoo-dev 2021-01-11 20:21:46 UTC
a suggestion for a runprefix script is welcome