Skip to content

Instantly share code, notes, and snippets.

@furu
Created March 2, 2014 12:36
Show Gist options
  • Save furu/9305937 to your computer and use it in GitHub Desktop.
Save furu/9305937 to your computer and use it in GitHub Desktop.
#!/Users/furu/Gentoo/bin/bash
# Copyright 2006-2014 Gentoo Foundation; Distributed under the GPL v2
# $Id: startprefix.in 61219 2012-09-04 19:05:55Z grobian $
# Fabian Groffen <[email protected]> -- 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
# What is our prefix?
EPREFIX="/Users/furu/Gentoo"
if [[ ${SHELL#${EPREFIX}} != ${SHELL} ]] ; then
echo "You appear to be in prefix already (SHELL=$SHELL)" > /dev/stderr
exit -1
fi
# 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
# SHELL=${SHELL##*/}
SHELL=zsh
# set the prefix shell in the environment
export SHELL=${EPREFIX}/bin/${SHELL}
# check if the shell exists
if [[ ! -x $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
# give a small notice
echo "Entering Gentoo Prefix ${EPREFIX}"
# start the login shell, clean the entire environment but what's needed
# PROFILEREAD is necessary on SUSE not to wipe the env on shell start
[[ -n ${PROFILEREAD} ]] && DOPROFILEREAD="PROFILEREAD=${PROFILEREAD}"
env -i EPREFIX=$EPREFIX LANG=en_US.UTF-8 HOME=$HOME TERM=$TERM USER=$USER SHELL=$SHELL $DOPROFILEREAD $SHELL -l
# 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 $?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment