1
0
angie-conv-image/image-entry.d/04-detect-local-ip-addresses.envsh
Konstantin Demin a69d6c2920
refactor environment handling
also:
- drop "njs" directories (not actually used nor useful)
- rework jinja filters: more functions, shorter names, etc.
2024-07-23 00:03:46 +03:00

26 lines
663 B
Bash
Executable File

#!/bin/sh
## allow these addresses to be provided in case of:
## - local development/testing
## - `hostname -I' random failures or misbehavior
if [ -z "${NGX_IP_ADDRESSES:-}" ] ; then
NGX_IP_ADDRESSES=$(hostname -I)
fi
NGX_IP_ADDRESSES=$(printf '%s' "${NGX_IP_ADDRESSES}" | sed -zE 's/^\s+//;s/\s+$//;s/\s+/ /g')
export NGX_IP_ADDRESSES
unset NGX_IPV4_ADDRESSES NGX_IPV6_ADDRESSES
for i in ${NGX_IP_ADDRESSES} ; do
case "$i" in
*:* )
NGX_IPV6_ADDRESSES="${NGX_IPV6_ADDRESSES:-}${NGX_IPV6_ADDRESSES:+ }$i"
;;
* )
NGX_IPV4_ADDRESSES="${NGX_IPV4_ADDRESSES:-}${NGX_IPV4_ADDRESSES:+ }$i"
;;
esac
done
unset i
export NGX_IPV4_ADDRESSES NGX_IPV6_ADDRESSES