Mercurial > hg > aboriginal
comparison sources/utility_functions.sh @ 1624:c654511d227c
Move environment variable whitelisting functions to new variables.sh.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 24 Aug 2013 06:38:10 -0500 |
parents | 84bd3248fad8 |
children | 191dfad915ba |
comparison
equal
deleted
inserted
replaced
1623:6cef85eefede | 1624:c654511d227c |
---|---|
1 #!/bin/echo "This file is sourced, not run" | 1 #!/bin/echo "This file is sourced, not run" |
2 | 2 |
3 # This file contains generic functions, presumably reusable in other contexts. | 3 # This file contains generic functions, presumably reusable in other contexts. |
4 | |
5 # Unset all environment variables that we don't know about, in case some crazy | |
6 # person already exported $CROSS_COMPILE, $ARCH, $CDPATH, or who knows what | |
7 # else. It's hard to know what might drive some package crazy, so use a | |
8 # whitelist. | |
9 | |
10 sanitize_environment() | |
11 { | |
12 # Which variables are set in config? | |
13 | |
14 TEMP=$(echo $(sed -n 's/.*export[ \t]*\([^=]*\)=.*/\1/p' config) | sed 's/ /,/g') | |
15 | |
16 # What other variables should we keep? | |
17 | |
18 TEMP="$TEMP,LANG,PATH,SHELL,TERM,USER,USERNAME,LOGNAME,PWD,EDITOR,HOME,DISPLAY,_" | |
19 TEMP="$TEMP,TOPSHELL,START_TIME,STAGE_NAME,TOOLCHAIN_PREFIX,HOST_ARCH,WRAPPY_LOGPATH,OLDPATH" | |
20 TEMP="$TEMP,http_proxy,ftp_proxy,https_proxy,no_proxy,TEMP,TMPDIR,FORK" | |
21 | |
22 # Unset any variable we don't recognize. It can screw up the build. | |
23 | |
24 for i in $(env | sed -n 's/=.*//p') | |
25 do | |
26 is_in_list $i "$TEMP" && continue | |
27 [ "${i:0:7}" == "DISTCC_" ] && continue | |
28 [ "${i:0:7}" == "CCACHE_" ] && continue | |
29 | |
30 unset $i 2>/dev/null | |
31 done | |
32 } | |
33 | |
34 # Assign (export) a variable only if current value is blank | |
35 | |
36 export_if_blank() | |
37 { | |
38 [ -z "$(eval "echo \"\${${1/=*/}}\"")" ] && export "$1" | |
39 } | |
40 | 4 |
41 # Create a blank directory at first argument, deleting existing contents if any | 5 # Create a blank directory at first argument, deleting existing contents if any |
42 | 6 |
43 blank_tempdir() | 7 blank_tempdir() |
44 { | 8 { |