summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haubenwallner <haubi@gentoo.org>2019-03-20 10:35:34 +0100
committerSam James <sam@gentoo.org>2023-05-26 06:59:06 +0100
commita5921f9abc0ff4353907b5c4f879eeff2d0a696f (patch)
tree805883e57891911aa86c444233e3ef9bc1c11857 /startprefix
downloadprefix-toolkit-a5921f9abc0ff4353907b5c4f879eeff2d0a696f.tar.gz
prefix-toolkit-a5921f9abc0ff4353907b5c4f879eeff2d0a696f.tar.bz2
prefix-toolkit-a5921f9abc0ff4353907b5c4f879eeff2d0a696f.zip
app-portage/prefix-toolkit: new packageprefix-toolkit-0
* 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> (cherry picked from commit 84b9f582e8c8db69a3b3677de702c7cc00ac3dab)
Diffstat (limited to 'startprefix')
-rw-r--r--startprefix76
1 files changed, 76 insertions, 0 deletions
diff --git a/startprefix b/startprefix
new file mode 100644
index 0000000..89ce10f
--- /dev/null
+++ b/startprefix
@@ -0,0 +1,76 @@
+#!@GENTOO_PORTAGE_EBASH@
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# Fabian Groffen <grobian@gentoo.org> -- 2007-03-10
+# Enters the prefix environment by starting a login shell from the
+# prefix. The SHELL environment variable is elevated in order to make
+# applications that start login shells to work, such as `screen`.
+
+# if you come from a substantially polluted environment (another
+# Prefix), a cleanup as follows resolves most oddities I've ever seen:
+# env -i HOME=$HOME TERM=$TERM USER=$USER $SHELL -l
+# hence this script starts the Prefix shell like this
+
+if [[ ${SHELL#@GENTOO_PORTAGE_EPREFIX@} != ${SHELL} ]]
+then
+ echo "You appear to be in prefix already (SHELL=${SHELL})" > /dev/stderr
+ exit -1
+elif [[ ${SHELL#@GENTOO_PORTAGE_BPREFIX@} != ${SHELL} ]] &&
+ [[ ${EPREFIX-unset} == '@GENTOO_PORTAGE_EPREFIX@' ]]
+then
+ echo "You appear to be in stacked prefix already (EPREFIX=${EPREFIX})" > /dev/stderr
+ exit -1
+fi
+
+# What is our prefix?
+EPREFIX@=@'@GENTOO_PORTAGE_EPREFIX@'
+BPREFIX@=@'@GENTOO_PORTAGE_BPREFIX@'
+
+# not all systems have the same location for shells, however what it
+# boils down to, is that we need to know what the shell is, and then we
+# can find it in the bin dir of our prefix
+for SHELL in \
+ "${EPREFIX}/bin/${SHELL##*/}" \
+ "${BPREFIX}/bin/${SHELL##*/}" \
+ ${SHELL##*/}
+do
+ [[ ${SHELL} == */* && -x ${SHELL} ]] && break
+done
+
+# check if the shell exists
+if [[ ${SHELL} != */* ]]
+then
+ echo "Failed to find the Prefix shell, this is probably" > /dev/stderr
+ echo "because you didn't emerge the shell ${SHELL}" > /dev/stderr
+ exit 1
+fi
+
+# set the prefix shell in the environment
+export SHELL
+
+# give a small notice
+echo "Entering Gentoo Prefix ${EPREFIX}"
+# start the login shell, clean the entire environment but what's needed
+RETAIN="HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL"
+# PROFILEREAD is necessary on SUSE not to wipe the env on shell start
+[[ -n ${PROFILEREAD} ]] && RETAIN+=" PROFILEREAD=$PROFILEREAD"
+# ssh-agent is handy to keep, of if set, inherit it
+[[ -n ${SSH_AUTH_SOCK} ]] && RETAIN+=" SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
+# if we're on some X terminal, makes sense to inherit that too
+[[ -n ${DISPLAY} ]] && RETAIN+=" DISPLAY=$DISPLAY"
+# do it!
+if [[ ${SHELL#${EPREFIX}} != ${SHELL} ]] ; then
+ '@GENTOO_PORTAGE_EENV@' -i $RETAIN $SHELL -l
+elif [[ ' bash ' == *" ${SHELL##*/} "* ]] ; then
+ # shell coming from different prefix would load it's own
+ # etc/profile upon -l, so we have to override
+ '@GENTOO_PORTAGE_EENV@' -i ${RETAIN} "${SHELL}" --rcfile "${EPREFIX}"/etc/prefix-stack.bash_login -i
+else
+ echo "Only bash is supported with stacked Prefix (you have ${SHELL##*/}), sorry!" > /dev/stderr
+ exit 1
+fi
+# 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 $?"