#!/bin/sh set -f . /image-entry.d/00-common.envsh ## 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 [ "${NGX_STRICT_LOAD}" = 0 ] || set -e load_error_delim() { IEP_TRACE=0 log_always ' ----------------------------------- ' } load_error() { [ "${load_error_seen:-}" != 1 ] || return load_error_seen=1 load_error_delim log_always 'tree combine has failed' if [ "${NGX_STRICT_LOAD}" = 1 ] ; then t=15 log_always "injecting delay for $t seconds" load_error_delim sleep $t exit 1 fi load_error_delim } dirs='cache lib log' for n in ${dirs} ; do s="/angie/$n" d="${target_root}/$n" if [ -d "$s" ] ; then ln_s "$s" "$d" else [ -d "$d" ] || install_userdir "$d" fi done ## 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" || load_error [ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log" || load_error ## NB: if any error occurs above then configuration is merely empty and/or broken 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}" ln_cp "${old_path}" "${new_path}" done <<-EOF $( set +e for n in ${NGX_DIRS_MERGE} ; do [ -n "$n" ] || continue [ -d "${merged_root}/$n" ] || continue find "${merged_root}/$n/" ! -type d done \ | grep -Ev \ -e "^${merged_root}/(mod|snip)/.+\.load\$" \ -e "^${merged_root}/mod/[^/]+\.preseed\$" \ | sort -V ) EOF 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 [ -d "$d" ] || continue ln_s "$d" "${target_root}/$n" break done [ -d "${target_root}/$n" ] || { log "missing required directory: ${target_root}/$n" } done ## Angie modules are loaded in [strict] order! combine_modules() { [ -n "$1" ] || return 1 n="$1" ; shift [ $# -ne 0 ] || return 0 old_dir="${merged_root}/mod" new_dir="${target_root}/mod" i=0 for m ; do [ -n "$m" ] || continue old_name="$n-$m.conf" old_path="${old_dir}/${old_name}" if ! [ -f "${old_path}" ] ; then log_always "file ${old_name} is not found in ${old_dir}/" load_error log "file ${old_name} is skipped" continue fi new_name=$(printf "%s-%02d-%s.load" "$n" "$i" "$m") new_path="${new_dir}/${new_name}" ln_cp "${old_path}" "${new_path}" i=$((i+1)) done ; unset m } combine_snippets() { [ -n "$1" ] || return 1 n="$1" ; shift [ $# -ne 0 ] || return 0 old_dir="${merged_root}/snip" new_dir="${target_root}/snip" for s ; do [ -n "$s" ] || continue new_path="${new_dir}/$n-$s.load" if [ -e "${new_path}" ] ; then log "${new_path} already exists, skipping" continue fi old_name="$n-$s.conf" old_path="${old_dir}/${old_name}" if ! [ -f "${old_path}" ] ; then log_always "file ${old_name} is not found in ${old_dir}/" if [ "${NGX_ALLOW_MISSING_SNIPPETS:-}" != 1 ] ; then load_error log "file ${old_name} is skipped" fi continue fi ln_cp "${old_path}" "${new_path}" done ; unset s } combine_modules core ${NGX_CORE_MODULES:-} combine_modules http ${NGX_HTTP_MODULES:-} combine_modules mail ${NGX_MAIL_MODULES:-} combine_modules stream ${NGX_STREAM_MODULES:-} unset NGX_ALLOW_MISSING_SNIPPETS 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:-} ## some modules doesn't have configuration at all NGX_ALLOW_MISSING_SNIPPETS=1 combine_snippets core ${NGX_CORE_MODULES:-} combine_snippets http ${NGX_HTTP_MODULES:-} combine_snippets mail ${NGX_MAIL_MODULES:-} combine_snippets stream ${NGX_STREAM_MODULES:-} exit 0