diff --git a/image-entry.d/00-common.envsh b/image-entry.d/00-common.envsh index 9449983..1e683ce 100644 --- a/image-entry.d/00-common.envsh +++ b/image-entry.d/00-common.envsh @@ -47,7 +47,6 @@ log_always() { log() { [ "${IEP_VERBOSE}" = 0 ] || log_always "$@" } -log_file() { sed -E '/^./s,^, ,' < "$1" >&2 ; } ln_s() { if [ "${IEP_VERBOSE}" = 0 ] ; then @@ -76,39 +75,6 @@ have_cmd() { command -v "$1" >/dev/null 2>&1 || return ; } strip_suffix() { printf '%s' "${1%"$2"}" | tr -s '/' ; } -untemplate_path() { - case "$1" in - ## inplace - "${volume_root}"/* | /etc/angie/run/* ) - strip_suffix "$1" "$2" - ;; - /etc/angie/autoconf.d/* | /etc/angie/conf.d/* | /etc/angie/j2cfg.d/* | /etc/angie/mod.d/* | /etc/angie/modules.d/* | /etc/angie/site.d/* | /etc/angie/snip.d/* ) - strip_suffix "$1" "$2" - ;; - /etc/angie/static.d/* ) - strip_suffix "$1" "$2" - ;; - ## set appropriate location - /etc/angie/* ) - strip_suffix "${volume_root}${1#/etc/angie}" "$2" - ;; - /tmp/* ) - log_always "untemplate_path() shouldn't work with /tmp/: $1" - strip_suffix "$1" "$2" - ;; - ## last resort - STRONGLY AVOID - /* ) - log_always "untemplate_path() does uncommon/last-resort mapping for: $1" - strip_suffix "${tmp_dir}$1" "$2" - ;; - ## misbehavior! - * ) - log_always "untemplate_path() doesn't work with relative paths: $1" - return 1 - ;; - esac -} - install_userdir() { if [ "${IEP_ROOT}" = 1 ] ; then install -d -o "${NGX_USER}" -g "${NGX_GROUP}" "$@" @@ -208,69 +174,6 @@ expand_dir_j2cfg() { return ${__ret} } -remap_path() { - [ -n "$1" ] || return - - case "$1" in - ## autoconf - /etc/angie/autoconf.dist/* ) echo "${2:-/etc/angie/autoconf.d}${1#/etc/angie/autoconf.dist}" ;; - /etc/angie/autoconf/* ) echo "${2:-/etc/angie/autoconf.d}${1#/etc/angie/autoconf}" ;; - /angie/autoconf/* ) echo "${2:-/etc/angie/autoconf.d}${1#/angie/autoconf}" ;; - ## conf - /etc/angie/conf.dist/* ) echo "${2:-/etc/angie/conf.d}${1#/etc/angie/conf.dist}" ;; - /etc/angie/conf/* ) echo "${2:-/etc/angie/conf.d}${1#/etc/angie/conf}" ;; - /angie/conf/* ) echo "${2:-/etc/angie/conf.d}${1#/angie/conf}" ;; - ## j2cfg - /etc/angie/j2cfg.dist/* ) echo "${2:-/etc/angie/j2cfg.d}${1#/etc/angie/j2cfg.dist}" ;; - /etc/angie/j2cfg/* ) echo "${2:-/etc/angie/j2cfg.d}${1#/etc/angie/j2cfg}" ;; - /angie/j2cfg/* ) echo "${2:-/etc/angie/j2cfg.d}${1#/angie/j2cfg}" ;; - ## mod - /etc/angie/mod.dist/* ) echo "${2:-/etc/angie/mod.d}${1#/etc/angie/mod.dist}" ;; - /etc/angie/mod/* ) echo "${2:-/etc/angie/mod.d}${1#/etc/angie/mod}" ;; - /angie/mod/* ) echo "${2:-/etc/angie/mod.d}${1#/angie/mod}" ;; - ## modules - /etc/angie/modules.dist/* ) echo "${2:-/etc/angie/modules.d}${1#/etc/angie/modules.dist}" ;; - /etc/angie/modules/* ) echo "${2:-/etc/angie/modules.d}${1#/etc/angie/modules}" ;; - /angie/modules/* ) echo "${2:-/etc/angie/modules.d}${1#/angie/modules}" ;; - ## site - /etc/angie/site.dist/* ) echo "${2:-/etc/angie/site.d}${1#/etc/angie/site.dist}" ;; - /etc/angie/site/* ) echo "${2:-/etc/angie/site.d}${1#/etc/angie/site}" ;; - /angie/site/* ) echo "${2:-/etc/angie/site.d}${1#/angie/site}" ;; - ## snip - /etc/angie/snip.dist/* ) echo "${2:-/etc/angie/snip.d}${1#/etc/angie/snip.dist}" ;; - /etc/angie/snip/* ) echo "${2:-/etc/angie/snip.d}${1#/etc/angie/snip}" ;; - /angie/snip/* ) echo "${2:-/etc/angie/snip.d}${1#/angie/snip}" ;; - - ## static - /etc/angie/static.dist/* ) echo "${2:-/etc/angie/static.d}${1#/etc/angie/static.dist}" ;; - /etc/angie/static/* ) echo "${2:-/etc/angie/static.d}${1#/etc/angie/static}" ;; - /angie/static/* ) echo "${2:-/etc/angie/static.d}${1#/angie/static}" ;; - - ## log - /etc/angie/log.dist/* ) echo "${2:-/etc/angie/log.d}${1#/etc/angie/log.dist}" ;; - /angie/log/* ) echo "${2:-/etc/angie/log.d}${1#/angie/log}" ;; - - ## misbehavior! - * ) - log_always "remap_path() doesn't know how to handle this path: $1" - return 1 - ;; - esac -} - -combine_remap_path() { - [ -n "$1" ] || return - - case "$1" in - "${merged_root}"/* ) echo "${2:-${target_root}}${1#"${merged_root}"}" ;; - ## misbehavior! - * ) - log_always "combine_remap_path() doesn't know how to handle this path: $1" - return 1 - ;; - esac -} - is_builtin_module() { [ -n "${1:-}" ] || return 1 [ -n "${2:-}" ] || return 1 @@ -281,6 +184,30 @@ is_builtin_module() { grep -Fxq -e "$2" "/etc/angie/builtin.$1" || return 1 } +append_list() { + if [ -n "$2" ] ; then + printf '%s' "${1:-}${1:+ }$2" + else + printf '%s' "$1" + fi +} + +prepend_list() { + if [ -n "$2" ] ; then + printf '%s' "$2${1:+ }${1:-}" + else + printf '%s' "$1" + fi +} + +list_have_item() { + [ -n "$2" ] || return 1 + case " $1 " in + *" $2 "* ) return 0 ;; + * ) return 1 ;; + esac +} + normalize_list() { [ -n "$1" ] || return 0 @@ -296,3 +223,7 @@ sort_dedup_list() { | tr -s '[:space:]' '\n' | sort -uV | paste -sd ' ' \ | sed -zE 's/^\s+//;s/\s+$//' } + +float_div() { + mawk -v "a=$1" -v "b=$2" 'BEGIN{print a/b;exit;}'