-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys, os | ||
|
||
if len(sys.argv) >= 2 and sys.argv[1] in ('-h', '--help'): | ||
print('bv_unenv [command [command_arg [...]]]') | ||
print('Reset original environment (that was active before using bv_env)') | ||
print('Without arguments, print the runtime environment to be used ' | ||
'on the standard output') | ||
print('With arguments, set the runtime environment, and run the ' | ||
'command passed in arguments in this environment.') | ||
sys.exit(0) | ||
|
||
unenv = [ i for i in os.environ if i.startswith( 'BRAINVISA_UNENV_' ) ] | ||
if len( sys.argv ) > 1: | ||
for n in unenv: | ||
v = os.environ.get(n) | ||
if v: | ||
os.environ[n[16:]] = os.environ[n] | ||
else: | ||
del os.environ[n[16:]] | ||
del os.environ[n] | ||
os.execvpe( sys.argv[1], sys.argv[ 1: ], os.environ ) | ||
else: | ||
for n in unenv: | ||
v = os.environ.get(n) | ||
if v: | ||
print(f"export {n[16:]}='{v}'") | ||
else: | ||
print(f'unset {n[16:]}') | ||
print('unset', n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# bv_unenv.sh: unset the environment which was set up by bv_env.sh in a shell. | ||
# | ||
# Usage: | ||
# . bv_unenv.sh | ||
|
||
# Create a temporary file with mktemp if available | ||
bv_env_tempfile=$(mktemp -t bv_env.XXXXXXXXXX 2>/dev/null) | ||
|
||
# Fall back to making up a file name | ||
if ! [ -w "$bv_env_tempfile" ] | ||
then | ||
bv_env_i=0 | ||
bv_env_tempfile=${TMPDIR:-/tmp}/bv_env-$$-$bv_env_i | ||
while [ -e "$bv_env_tempfile" ]; do | ||
bv_env_i=$(($bv_env_i+1)) | ||
bv_env_tempfile=${TMPDIR:-/tmp}/bv_env-$$-$bv_env_i | ||
done | ||
unset bv_env_i | ||
# Create the temporary file, making sure not to overwrite an existing file | ||
(umask 077 && set -C && : > "$bv_env_tempfile") || { | ||
echo "bv_unenv.sh: error creating $bv_env_tempfile, aborting" >&2 | ||
unset bv_env_tempfile | ||
return 1 | ||
} | ||
fi | ||
|
||
bv_env_cleanup() { | ||
rm -f "$bv_env_tempfile" | ||
unset bv_env_tempfile | ||
} | ||
|
||
|
||
# Contrary to bv_env.sh, we know that bv_unenv is in the PATH so we do not have | ||
# to guess its location. | ||
bv_unenv >| "$bv_env_tempfile" || { | ||
echo "bv_unenv.sh: error while using bv_unenv, aborting" >&2 | ||
bv_env_cleanup | ||
return 1 | ||
} | ||
|
||
. "$bv_env_tempfile" || { | ||
echo "bv_unenv.sh: error while sourcing the output of $bv_env" >&2 | ||
bv_env_cleanup | ||
hash -r | ||
return 1 | ||
} | ||
|
||
bv_env_cleanup | ||
|
||
# Empty the cache of known command locations, which is necessary to take | ||
# changes of $PATH into account under some shells. | ||
hash -r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters