-
Notifications
You must be signed in to change notification settings - Fork 15
/
activate
108 lines (88 loc) · 3.12 KB
/
activate
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# This file must be used with "source activate" *from bash*
# you cannot run it directly
if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi
deactivate () {
# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
# -n is logically identical to ! -z
# Restore the PATH variable and remove aliases
if [ -n "${_OLD_VIRTUAL_PATH:+_}" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
unalias ld-sudo
fi
# Restore LD_LIBRARY_PATH variable
if [ -n "${_OLD_LD_PATH:+_}" ] ; then
LD_LIBRARY_PATH="$_OLD_LD_PATH"
export LD_LIBRARY_PATH
unset _OLD_LD_PATH
else
unset LD_LIBRARY_PATH
fi
# Restore PKG_CONFIG_PATH variable
if [ -n "${_OLD_PKG_CONFIG_PATH:+_}" ] ; then
PKG_CONFIG_PATH="$_OLD_PKG_CONFIG_PATH"
export PKG_CONFIG_PATH
unset _OLD_PKG_CONFIG_PATH
else
unset PKG_CONFIG_PATH
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi
if [ -n "${_OLD_VIRTUAL_PS1+_}" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
}
# Always use the directory of the script as root for the virtual environment!
VIRTUAL_ENV="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Save current PATH variable and setup new PATH
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# Indicate virtualenv is active by modifying PS1 prompt
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1-}"
PS1="($(basename "$VIRTUAL_ENV")) ${PS1-}"
export PS1
fi
# Configure new LD_LIBRARY_PATH
if [ -z ${LD_LIBRARY_PATH+x} ]; then
LD_LIBRARY_PATH="$VIRTUAL_ENV/lib"
else
_OLD_LD_PATH="$LD_LIBRARY_PATH"
LD_LIBRARY_PATH="$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH"
fi
export LD_LIBRARY_PATH;
# Configure new PKG_CONFIG_PATH
if [ -z ${PKG_CONFIG_PATH+x} ]; then
PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig"
else
_OLD_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig"
fi
export PKG_CONFIG_PATH;
# Create special alias to perform sudo operations with variables set
alias ld-sudo='sudo PATH="$PATH" HOME="$HOME" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH"'
# Check fusermount permissions and prompt to configure properly
if [ -z "$(find "$VIRTUAL_ENV"/bin/fusermount3 -user root)" ]; then
sudo chown root:root "$VIRTUAL_ENV"/bin/fusermount3
sudo chmod u+s "$VIRTUAL_ENV"/bin/fusermount3
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi