-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_vars_global.sh
66 lines (60 loc) · 1.56 KB
/
make_vars_global.sh
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
#!/bin/ash
set -e
# add an element to the pseudobuffer
function append_val() {
offset=$buf0
let "offset=offset + 1"
eval buf$offset="\$1"
buf0=$offset
}
# splits the string using the delimiter provided and
# stores the chunks found into the pseudobufer named
# buf
function split() {
str=$1
del=$2
chunk=""
i=0
len=${#str}
eval buf0=0
while true; do
if [ $i -ge $len ]; then
append_val $chunk
break
fi
c=${str:$i:1}
if [ $c = $del ]; then
append_val $chunk
chunk=""
else
chunk="$chunk$c"
fi
let "i = i + 1"
done
}
function print_buf() {
i=1
while [ $i -le $buf0 ]; do
eval assign="\$buf$i"
eval echo "$assign=\$$assign"
let "i=i+1"
done
}
function output_vars() {
i=1
while [ $i -le $buf0 ]; do
eval assign="\$buf$i"
eval echo "export $assign=\$$assign" >> /etc/profile.d/env_vars.sh
let "i=i+1"
done
}
echo "#!/bin/ash" > /etc/profile.d/env_vars.sh
echo "" >> /etc/profile.d/env_vars.sh
echo "export NGINX_ENV_VARS=$NGINX_ENV_VARS" >> /etc/profile.d/env_vars.sh
split $NGINX_ENV_VARS ","
chunks="$buf0"
output_vars
chmod 0777 /etc/profile
for i in $(ls /etc/profile.d/); do
chmod 0777 "/etc/profile.d/$i"
done