1
0
angie-conv-image/scripts/apt-install-angie-mod.sh

170 lines
3.8 KiB
Bash
Raw Normal View History

2024-07-11 13:37:35 +03:00
#!/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
2024-07-24 22:47:53 +03:00
set -a
ANGIE_MODULES_DIR="${ANGIE_MODULES_DIR:-/usr/lib/angie/modules}"
set +a
2024-07-11 13:37:35 +03:00
## produce package list
2024-07-24 22:47:53 +03:00
pkgs=
2024-07-11 13:37:35 +03:00
for i ; do
[ -n "$i" ] || continue
2024-07-24 22:47:53 +03:00
i="angie-module-$i"
printf '%s' "$i" | grep -zEq '^[a-z0-9.+-]+$' || {
env printf 'package name %q is not legal, quitting!\n' "$i" >&2
exit 1
}
pkgs="${pkgs}${pkgs:+ }$i"
2024-07-11 13:37:35 +03:00
done
2024-07-24 22:47:53 +03:00
[ -n "${pkgs}" ] || exit 0
normalize_list() {
[ -n "$1" ] || return 0
printf '%s' "$1" \
| tr -s '[:space:]' ' ' \
| sed -zE 's/^ //;s/ $//'
}
sort_dedup_list() {
[ -n "$1" ] || return 0
printf '%s' "$1" \
| tr -s '[:space:]' '\n' | sort -uV | paste -sd ' ' \
| sed -zE 's/^\s+//;s/\s+$//'
}
pkgs=$(sort_dedup_list "${pkgs}")
2024-07-11 13:37:35 +03:00
2024-07-23 22:43:52 +03:00
dirs='cache lib log'
for n in ${dirs} ; do
d="/run/angie/$n"
[ -d "$d" ] || install -d "$d"
done
2024-07-24 22:47:53 +03:00
apt-install.sh ${pkgs}
2024-07-11 13:37:35 +03:00
2024-07-24 22:47:53 +03:00
ANGIE_MODCONF_DIR=/etc/angie/mod.dist
[ -d "${ANGIE_MODCONF_DIR}" ] || install -d "${ANGIE_MODCONF_DIR}"
2024-07-11 13:37:35 +03:00
list_ngx_modules() {
set +e
dpkg-query -L "$1" \
| grep -F -e "${ANGIE_MODULES_DIR}/" \
| grep -E -e '/[^/]+_module(-debug)?\.so$' \
2024-07-24 22:47:53 +03:00
| sed -E '\,^(.+)-debug\.so$,{p;s//\1.so/;p;d}' \
| sort -uV \
2024-07-11 13:37:35 +03:00
| xargs -r ls -U1d 2>/dev/null
set -e
}
2024-07-24 22:47:53 +03:00
is_same_file() {
find -L "$1" -samefile "$2" -printf . -quit 2>/dev/null | grep -Fq . || return 1
}
2024-07-11 13:37:35 +03:00
gen_mod_config() {
if [ -s "$2" ] ; then
printf '%s: configuration already exists: %s\n' "$1" "$2" >&2
return
fi
[ -n "$3" ] || return
2024-07-24 22:47:53 +03:00
local __m
2024-07-11 13:37:35 +03:00
for __m in $3 ; do
2024-07-17 13:50:13 +03:00
echo "load_module ${__m};"
done > "$2"
2024-07-11 13:37:35 +03:00
}
2024-07-24 22:47:53 +03:00
for p in ${pkgs} ; do
[ -n "$p" ] || continue
i="${p#angie-module-}"
2024-07-11 13:37:35 +03:00
## adjust modules:
## - remove debug module if not in debug image
## - move debug module to usual location otherwise
2024-07-24 22:47:53 +03:00
while read -r fmod_debug ; do
# [ -n "${fmod_debug}" ] || continue
case "${fmod_debug}" in
2024-07-11 13:37:35 +03:00
*-debug.so ) ;;
* ) continue ;;
esac
2024-07-24 22:47:53 +03:00
fmod="${fmod_debug%-debug.so}.so"
2024-07-11 13:37:35 +03:00
2024-07-24 22:47:53 +03:00
fmod_tmp=$(mktemp -u "${fmod}.XXXXXXXXXX")
2024-07-11 13:37:35 +03:00
if [ "${NGX_DEBUG}" = 0 ] ; then
2024-07-24 22:47:53 +03:00
if [ -f "${fmod}" ] ; then
fmod_real=$(readlink -f "${fmod}")
else
env printf 'missing (non-debug) file: %q\n' "${fmod}" >&2
env printf 'falling back to (debug) file: %q\n' "${fmod_debug}" >&2
fmod_real=$(readlink -f "${fmod_debug}")
fi
2024-07-11 13:37:35 +03:00
else
2024-07-24 22:47:53 +03:00
fmod_real=$(readlink -f "${fmod_debug}")
2024-07-11 13:37:35 +03:00
fi
2024-07-24 22:47:53 +03:00
[ -n "${fmod_real}" ] || exit 1
ln -v "${fmod_real}" "${fmod_tmp}"
rm -fv "${fmod}" "${fmod_debug}"
mv -fv "${fmod_tmp}" "${fmod}"
2024-07-11 13:37:35 +03:00
done <<-EOF
$(list_ngx_modules "$p")
EOF
2024-07-24 22:47:53 +03:00
if [ -e "${ANGIE_MODCONF_DIR}/.$i.preseed" ] ; then
printf '%s: skipping generation of module load config (preseed is in effect)\n' "$p" >&2
2024-07-11 13:37:35 +03:00
continue
fi
## produce attachable module configs
http_modules=
mail_modules=
stream_modules=
while read -r fmod ; do
2024-07-24 22:47:53 +03:00
[ -n "${fmod}" ] || continue
2024-07-17 13:50:13 +03:00
fmod_short="modules.d/${fmod#"${ANGIE_MODULES_DIR}/"}"
2024-07-11 13:37:35 +03:00
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
2024-07-24 22:47:53 +03:00
[ -z "${http_modules}" ] || gen_mod_config "$p" "${ANGIE_MODCONF_DIR}/http-$i.conf" "${http_modules}"
[ -z "${mail_modules}" ] || gen_mod_config "$p" "${ANGIE_MODCONF_DIR}/mail-$i.conf" "${mail_modules}"
[ -z "${stream_modules}" ] || gen_mod_config "$p" "${ANGIE_MODCONF_DIR}/stream-$i.conf" "${stream_modules}"
2024-07-11 13:37:35 +03:00
done