#!@GENTOO_PORTAGE_EBASH@ # Copyright 1999-2019 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # Fabian Groffen -- 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" if [[ -d /proc/registry ]]; then # we're on Cygwin # crucial to Windows but cannot be restored, see # https://cygwin.com/ml/cygwin/2019-08/msg00072.html [[ -n ${SYSTEMDRIVE} ]] && RETAIN+=" SYSTEMDRIVE=$SYSTEMDRIVE" # COMSPEC is to native Windows what SHELL is to *nix [[ -n ${COMSPEC} ]] && RETAIN+=" COMSPEC=$COMSPEC" # some Windows programs (e.g. devenv.exe) need TMP or TEMP [[ -n ${TEMP} ]] && RETAIN+=" TEMP=$TEMP" fi # 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 $?"