1
0
angie-conv-image/image-entry.d/99-cleanup-env.envsh

65 lines
1.4 KiB
Plaintext
Raw Normal View History

2024-07-20 16:35:39 +03:00
#!/bin/sh
## Angie: unset core variable
unset ANGIE ANGIE_BPF_MAPS
if [ "${IEP_RETAIN_ENV}" = 1 ] ; then
log_always "NOT removing following variables:"
sed -E '/^./s,^, ,' >&2
echo >&2
2024-07-20 16:35:39 +03:00
else
__set="$-"
set +e
unset __env __env_print
2024-07-20 16:35:39 +03:00
while read -r __env ; do
[ -n "${__env}" ] || continue
case "${__env}" in
\'* | \"* )
2024-07-20 16:35:39 +03:00
log "skipping variable (malformed): ${__env}" >&2
continue
;;
esac
if [ "${IEP_DEBUG}" = 1 ] ; then
__env_print="${__env}="$(printenv "${__env}")
__env_print=$(env printf '%q' "${__env_print}")
log_always "unsetting variable: ${__env_print}"
else
log "unsetting variable: ${__env}"
fi
2024-07-20 16:35:39 +03:00
unset "${__env}"
done
unset __env __env_print
[ -z "${__set}" ] || set -"${__set}"
unset __set
2024-07-20 16:35:39 +03:00
fi <<-EOF
$(
set +e
2024-07-20 16:35:39 +03:00
cat /proc/self/environ \
| sed -zEn '/^([^=]+).*$/s//\1/p' \
| xargs -0r printf '%q\n' \
| {
## retain variables defined in ".core_worker_env" configuration key
## (if it was specified somewhere in dictionaries - either yaml or json)
f="${target_root}/j2cfg/core-worker-env.txt"
2024-07-20 16:35:39 +03:00
[ -s "$f" ] || exec cat
grep -Fxv -f "$f"
} \
| {
## remove environment variables:
## 1. variables starting with "NGX" as they are used by configuration templates
## 2. variables containing "_SERVICE" or "_PORT" as they are came from
## container orchestration
grep -E \
-e '^NGX' \
-e '_(SERVICE|PORT)' \
} \
2024-07-20 16:35:39 +03:00
| sort -uV
)
EOF