#!/bin/sh set -ef [ $# -gt 0 ] || exit 1 if [ -z "${NGX_DEBUG:-}" ] ; then cat >&2 <<-EOF $0: NGX_DEBUG is not set - defaulting to NGX_DEBUG=0 EOF NGX_DEBUG=0 fi # ANGIE_MODULES_DIR=/usr/lib/angie/modules d=/etc/angie/mod.dist ## produce package list p= for i ; do [ -n "$i" ] || continue p="$p${p:+ }angie-module-$i" done [ -n "$p" ] || exit 0 dirs='cache lib log' for n in ${dirs} ; do d="/run/angie/$n" [ -d "$d" ] || install -d "$d" done apt-install.sh $p [ -d "$d" ] || install -d "$d" list_ngx_modules() { set +e dpkg-query -L "$1" \ | grep -F -e "${ANGIE_MODULES_DIR}/" \ | grep -E -e '/[^/]+_module(-debug)?\.so$' \ | sort -V \ | xargs -r ls -U1d 2>/dev/null set -e } gen_mod_config() { if [ -s "$2" ] ; then printf '%s: configuration already exists: %s\n' "$1" "$2" >&2 return fi [ -n "$3" ] || return for __m in $3 ; do echo "load_module ${__m};" done > "$2" } for i ; do [ -n "$i" ] || continue p="angie-module-$i" ## adjust modules: ## - remove debug module if not in debug image ## - move debug module to usual location otherwise while read -r fmod ; do case "${fmod}" in *-debug.so ) ;; * ) continue ;; esac if [ "${NGX_DEBUG}" = 0 ] ; then rm -fv "${fmod}" else fmod_nodebug="${fmod%-debug.so}.so" rm -fv "${fmod_nodebug}" mv -fv "${fmod}" "${fmod_nodebug}" fi done <<-EOF $(list_ngx_modules "$p") EOF if [ -e "$d/.$i.preseed" ] ; then printf '%s: skipping generation of attachable module configs\n' "$p" >&2 continue fi ## produce attachable module configs http_modules= mail_modules= stream_modules= while read -r fmod ; do fmod_short="modules.d/${fmod#"${ANGIE_MODULES_DIR}/"}" fname=${fmod##*/} case "${fname}" in ngx_http_* ) http_modules="${http_modules}${http_modules:+ }${fmod_short}" ;; ngx_mail_* ) mail_modules="${mail_modules}${mail_modules:+ }${fmod_short}" ;; ngx_stream_* ) stream_modules="${stream_modules}${stream_modules:+ }${fmod_short}" ;; ## damn NDK ndk_http_* ) http_modules="${http_modules}${http_modules:+ }${fmod_short}" ;; * ) env printf '%s: unable to determine module type for file (skipping): %q\n' "$p" "${fmod}" >&2 continue ;; esac done <<-EOF $(list_ngx_modules "$p") EOF [ -z "${http_modules}" ] || gen_mod_config "$p" "$d/http-$i.conf" "${http_modules}" [ -z "${mail_modules}" ] || gen_mod_config "$p" "$d/mail-$i.conf" "${mail_modules}" [ -z "${stream_modules}" ] || gen_mod_config "$p" "$d/stream-$i.conf" "${stream_modules}" done