1
0
angie-conv-image/image-entry.d/54-combine-tree.sh

189 lines
4.1 KiB
Bash
Raw Normal View History

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
2024-07-17 13:50:13 +03:00
load_error_delim() {
IEP_DEBUG=0 log_always ' ----------------------------------- '
2024-07-17 13:50:13 +03:00
}
2024-07-11 13:37:35 +03:00
load_error() {
2024-07-17 13:50:13 +03:00
[ "${load_error_seen:-}" != 1 ] || return
2024-07-11 13:37:35 +03:00
load_error_seen=1
2024-07-17 13:50:13 +03:00
load_error_delim
log_always 'tree combine has failed'
2024-07-11 13:37:35 +03:00
if [ "${NGX_STRICT_LOAD}" = 1 ] ; then
2024-07-20 16:35:39 +03:00
t=15
2024-07-11 13:37:35 +03:00
log_always "injecting delay for $t seconds"
2024-07-17 13:50:13 +03:00
load_error_delim
2024-07-11 13:37:35 +03:00
sleep $t
exit 1
fi
2024-07-17 13:50:13 +03:00
load_error_delim
2024-07-11 13:37:35 +03:00
}
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"
2024-07-20 16:35:39 +03:00
[ -e "$d/access.log" ] || ln_s /dev/stdout "$d/access.log" || load_error
[ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log" || load_error
2024-07-15 16:15:47 +03:00
## NB: if any error occurs above then configuration is merely empty and/or broken
2024-07-11 13:37:35 +03:00
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-20 16:35:39 +03:00
for n in ${NGX_DIRS_MERGE} ; do
[ -n "$n" ] || continue
2024-07-11 13:37:35 +03:00
[ -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
2024-07-11 13:37:35 +03:00
)
EOF
2024-07-20 16:35:39 +03:00
for n in ${NGX_DIRS_LINK} ; do
[ -n "$n" ] || continue
if [ -e "${target_root}/$n" ] ; then continue ; fi
for d in "/angie/$n" "/etc/angie/$n" "/etc/angie/$n.dist" ; do
2024-07-11 13:37:35 +03:00
[ -d "$d" ] || continue
2024-07-20 16:35:39 +03:00
ln_s "$d" "${target_root}/$n"
2024-07-11 13:37:35 +03:00
break
done
2024-07-20 16:35:39 +03:00
[ -d "${target_root}/$n" ] || {
log "missing required directory: ${target_root}/$n"
}
done
2024-07-11 13:37:35 +03:00
## 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-17 13:50:13 +03:00
if [ "${NGX_ALLOW_MISSING_SNIPPETS:-}" != 1 ] ; then
load_error
log "file ${old_name} is skipped"
fi
2024-07-11 13:37:35 +03:00
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-17 13:50:13 +03:00
unset NGX_ALLOW_MISSING_SNIPPETS
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-17 13:50:13 +03:00
## some modules doesn't have configuration at all
NGX_ALLOW_MISSING_SNIPPETS=1
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