2024-07-20 16:35:39 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
## 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
|
2024-07-23 00:03:46 +03:00
|
|
|
__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-23 00:03:46 +03:00
|
|
|
\'* | \"* )
|
2024-07-20 16:35:39 +03:00
|
|
|
log "skipping variable (malformed): ${__env}" >&2
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
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
|
2024-07-23 00:03:46 +03:00
|
|
|
unset __env __env_print
|
|
|
|
|
|
|
|
[ -z "${__set}" ] || set -"${__set}"
|
|
|
|
unset __set
|
2024-07-20 16:35:39 +03:00
|
|
|
fi <<-EOF
|
|
|
|
$(
|
2024-07-23 00:03:46 +03:00
|
|
|
set +e
|
2024-07-20 16:35:39 +03:00
|
|
|
cat /proc/self/environ \
|
|
|
|
| sed -zEn '/^([^=]+).*$/s//\1/p' \
|
|
|
|
| xargs -0r printf '%q\n' \
|
|
|
|
| {
|
2024-07-23 00:03:46 +03:00
|
|
|
## 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"
|
|
|
|
} \
|
2024-07-23 00:03:46 +03:00
|
|
|
| {
|
|
|
|
## 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
|