summaryrefslogtreecommitdiff
blob: aafd04d7105d2f1b161930ffee4b54a6149c6b36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!@GENTOO_PORTAGE_EPREFIX@/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 <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


# What is our prefix?
EPREFIX="@GENTOO_PORTAGE_EPREFIX@"

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##*/}
# 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 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 $?"