2024-07-11 13:37:35 +03:00
|
|
|
#!/bin/sh
|
|
|
|
set -f
|
|
|
|
|
|
|
|
. /image-entry.d/00-common.envsh
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
## sanity check
|
|
|
|
t=$(mktemp) || exit 1
|
|
|
|
|
|
|
|
for n in mod snip ; do
|
|
|
|
[ -d "${merged_root}/$n" ] || continue
|
|
|
|
find "${merged_root}/$n/" ! -type d
|
|
|
|
done \
|
|
|
|
| grep -E "^${merged_root}/(mod|snip)/.+\.load\$" \
|
|
|
|
| sort -V > "$t"
|
|
|
|
|
|
|
|
if [ -s "$t" ] ; then
|
|
|
|
log_always 'these files will be EXPLICITLY skipped:'
|
|
|
|
log_file "$t"
|
|
|
|
fi
|
|
|
|
rm -f "$t" ; unset t
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
|
|
|
|
|
|
|
|
load_error() {
|
|
|
|
[ "${load_error_seen:-}" = 1 ] || log_always 'tree combine has failed'
|
|
|
|
load_error_seen=1
|
|
|
|
if [ "${NGX_STRICT_LOAD}" = 1 ] ; then
|
|
|
|
t=10
|
|
|
|
log_always "injecting delay for $t seconds"
|
|
|
|
sleep $t
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
dirs='cache lib log'
|
|
|
|
for n in ${dirs} ; do
|
|
|
|
s="/angie/$n"
|
|
|
|
d="${target_root}/$n"
|
|
|
|
|
|
|
|
if [ -d "$s" ] ; then
|
|
|
|
ln_s "$s" "$d"
|
2024-07-11 13:37:35 +03:00
|
|
|
else
|
2024-07-15 16:15:47 +03:00
|
|
|
[ -d "$d" ] || install_userdir "$d"
|
2024-07-11 13:37:35 +03:00
|
|
|
fi
|
2024-07-15 16:15:47 +03:00
|
|
|
done
|
2024-07-11 13:37:35 +03:00
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
## provide same symlinks as upstream (both Angie and nginx) docker images do
|
|
|
|
d="${target_root}/log"
|
|
|
|
[ -e "$d/access.log" ] || ln_s /dev/stdout "$d/access.log"
|
|
|
|
[ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log"
|
|
|
|
|
|
|
|
## NB: if any error occurs above then configuration is merely empty and/or broken
|
|
|
|
|
|
|
|
dirs='conf mod modules njs site snip'
|
2024-07-11 13:37:35 +03:00
|
|
|
[ "${NGX_PROCESS_STATIC}" = 0 ] || dirs="${dirs} static"
|
|
|
|
while read -r old_path ; do
|
|
|
|
[ -n "${old_path}" ] || continue
|
|
|
|
|
|
|
|
new_path=$(combine_remap_path "${old_path}")
|
|
|
|
[ -n "${new_path}" ]
|
|
|
|
|
|
|
|
new_dir="${new_path%/*}"
|
|
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
ln_cp "${old_path}" "${new_path}"
|
2024-07-11 13:37:35 +03:00
|
|
|
done <<-EOF
|
|
|
|
$(
|
2024-07-15 16:15:47 +03:00
|
|
|
set +e
|
2024-07-11 13:37:35 +03:00
|
|
|
for n in ${dirs} ; do
|
|
|
|
[ -d "${merged_root}/$n" ] || continue
|
|
|
|
find "${merged_root}/$n/" ! -type d
|
2024-07-15 16:15:47 +03:00
|
|
|
done \
|
|
|
|
| grep -Ev \
|
|
|
|
-e "^${merged_root}/(mod|snip)/.+\.load\$" \
|
|
|
|
-e "^${merged_root}/mod/[^/]+\.preseed\$" \
|
|
|
|
| sort -V
|
|
|
|
set -e
|
2024-07-11 13:37:35 +03:00
|
|
|
)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if [ "${NGX_PROCESS_STATIC}" = 0 ] ; then
|
|
|
|
for d in /angie/static /etc/angie/static /etc/angie/static.dist ; do
|
|
|
|
[ -d "$d" ] || continue
|
2024-07-15 16:15:47 +03:00
|
|
|
ln_s "$d" "${target_root}/static"
|
2024-07-11 13:37:35 +03:00
|
|
|
break
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Angie modules are loaded in [strict] order!
|
|
|
|
combine_modules() {
|
|
|
|
[ -n "$1" ] || return 1
|
|
|
|
n="$1" ; shift
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
[ $# -ne 0 ] || return 0
|
|
|
|
|
|
|
|
old_dir="${merged_root}/mod"
|
|
|
|
new_dir="${target_root}/mod"
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
i=0
|
|
|
|
for m ; do
|
|
|
|
[ -n "$m" ] || continue
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
old_name="$n-$m.conf"
|
|
|
|
old_path="${old_dir}/${old_name}"
|
2024-07-11 13:37:35 +03:00
|
|
|
if ! [ -f "${old_path}" ] ; then
|
2024-07-15 16:15:47 +03:00
|
|
|
log_always "file ${old_name} is not found in ${old_dir}/"
|
2024-07-11 13:37:35 +03:00
|
|
|
load_error
|
|
|
|
log "file ${old_name} is skipped"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
new_name=$(printf "%s-%02d-%s.load" "$n" "$i" "$m")
|
|
|
|
new_path="${new_dir}/${new_name}"
|
2024-07-11 13:37:35 +03:00
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
ln_cp "${old_path}" "${new_path}"
|
2024-07-11 13:37:35 +03:00
|
|
|
|
|
|
|
i=$((i+1))
|
2024-07-15 16:15:47 +03:00
|
|
|
done ; unset m
|
2024-07-11 13:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
combine_snippets() {
|
|
|
|
[ -n "$1" ] || return 1
|
|
|
|
n="$1" ; shift
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
[ $# -ne 0 ] || return 0
|
|
|
|
|
|
|
|
old_dir="${merged_root}/snip"
|
|
|
|
new_dir="${target_root}/snip"
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
for s ; do
|
|
|
|
[ -n "$s" ] || continue
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
new_path="${new_dir}/$n-$s.load"
|
|
|
|
if [ -e "${new_path}" ] ; then
|
|
|
|
log "${new_path} already exists, skipping"
|
|
|
|
continue
|
|
|
|
fi
|
2024-07-11 13:37:35 +03:00
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
old_name="$n-$s.conf"
|
|
|
|
old_path="${old_dir}/${old_name}"
|
2024-07-11 13:37:35 +03:00
|
|
|
if ! [ -f "${old_path}" ] ; then
|
2024-07-15 16:15:47 +03:00
|
|
|
log_always "file ${old_name} is not found in ${old_dir}/"
|
2024-07-11 13:37:35 +03:00
|
|
|
load_error
|
|
|
|
log "file ${old_name} is skipped"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
ln_cp "${old_path}" "${new_path}"
|
|
|
|
done ; unset s
|
2024-07-11 13:37:35 +03:00
|
|
|
}
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
combine_modules core ${NGX_CORE_MODULES:-}
|
|
|
|
combine_modules http ${NGX_HTTP_MODULES:-}
|
|
|
|
combine_modules mail ${NGX_MAIL_MODULES:-}
|
|
|
|
combine_modules stream ${NGX_STREAM_MODULES:-}
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
combine_snippets core ${NGX_CORE_SNIPPETS:-}
|
|
|
|
combine_snippets core_ev ${NGX_CORE_EVENTS_SNIPPETS:-}
|
|
|
|
combine_snippets http ${NGX_HTTP_SNIPPETS:-}
|
|
|
|
combine_snippets mail ${NGX_MAIL_SNIPPETS:-}
|
|
|
|
combine_snippets stream ${NGX_STREAM_SNIPPETS:-}
|
|
|
|
|
2024-07-15 16:15:47 +03:00
|
|
|
combine_snippets core ${NGX_CORE_MODULES:-}
|
|
|
|
combine_snippets http ${NGX_HTTP_MODULES:-}
|
|
|
|
combine_snippets mail ${NGX_MAIL_MODULES:-}
|
|
|
|
combine_snippets stream ${NGX_STREAM_MODULES:-}
|
2024-07-11 13:37:35 +03:00
|
|
|
|
|
|
|
exit 0
|