-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment-generate
executable file
·45 lines (39 loc) · 1.61 KB
/
environment-generate
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
##
# Generate the `environment` file based on the `environment.d` files.
#
# Generally this script concatenations the files,
# then does some simple transformation to flatten calculations.
##
set -o nounset
set -o errexit
set -o pipefail
# Concatenate the files
awk 'FNR==1 && NR!=1 {print "\n##########################################################################\n"}{print}' environment.d/*.sh > environment
# Now that we have the concatenated environment,
# we source it, to create various environment variables.
# Caveat: this changes the current system environment.
#
# We conclude by setting any env vars that are calculated,
# and writing the setting into the output environment file.
# This is because /etc/environment does not do subsititutions.
#
# We trim any leading colon or space from each calculated var,
# because the characters are merely artifacts of the calculation.
#
# TODO: parse these files, without needing to `source environment`;
# this upgrade will enable us to create the environment file
# without needed to change the current system environment.
source environment
echo "
OPT=\"${OPT/#:/}\"
PATH=\"${PATH/#:/}\"
MANPATH=\"${MANPATH/#:/}\"
LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH/#:/}\"
LD_RUN_PATH=\"${LD_RUN_PATH/#:/}\"
LDFLAGS=\"${LDFLAGS/# //}\"
CPPFLAGS=\"${CPPFLAGS/# /}\"
PKG_CONFIG_PATH=\"${PKG_CONFIG_PATH/#:/}\"
DYLD_LIBRARY_PATH=\"${DYLD_LIBRARY_PATH/#://}\"
" >> environment
# Comment-out lines that are known calculations
sed -i.tmp 's/^[ \t]*\(OPT\|PATH\|MANPATH\|LD_LIBRARY_PATH\|LD_RUN_PATH\|LDFLAGS\|CPPFLAGS\|PKG_CONFIG_PATH\|DYLD_LIBRARY_PATH\)[ \t]*=.*\$/#&/g' environment && rm environment.tmp