|
@@ -211,7 +211,7 @@ function score_file() {
|
|
return
|
|
return
|
|
fi
|
|
fi
|
|
elif [[ "$label" =~ ^(c|class)$ ]]; then
|
|
elif [[ "$label" =~ ^(c|class)$ ]]; then
|
|
- if [ "$value" = "$local_class" ]; then
|
|
|
|
|
|
+ if in_list "$value" "${local_classes[@]}"; then
|
|
score=$((score + 8))
|
|
score=$((score + 8))
|
|
else
|
|
else
|
|
score=0
|
|
score=0
|
|
@@ -418,12 +418,22 @@ function replace_vars() {
|
|
gsub(("{{" blank "*yadm\\." label blank "*}}"), c[label])
|
|
gsub(("{{" blank "*yadm\\." label blank "*}}"), c[label])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+function condition_helper(label, value) {
|
|
|
|
+ gsub(/[\\.^$(){}\[\]|*+?]/, "\\\\&", value)
|
|
|
|
+ return sprintf("yadm\\.%s" blank "*==" blank "*\"%s\"", label, value)
|
|
|
|
+}
|
|
function conditions() {
|
|
function conditions() {
|
|
pattern = ifs blank "+("
|
|
pattern = ifs blank "+("
|
|
for (label in c) {
|
|
for (label in c) {
|
|
- value = c[label]
|
|
|
|
- gsub(/[\\.^$(){}\[\]|*+?]/, "\\\\&", value)
|
|
|
|
- pattern = sprintf("%syadm\\.%s" blank "*==" blank "*\"%s\"|", pattern, label, value)
|
|
|
|
|
|
+ if (label != "class") {
|
|
|
|
+ value = c[label]
|
|
|
|
+ pattern = sprintf("%s%s|", pattern, condition_helper(label, value));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ split(classes, cls_array, "\n")
|
|
|
|
+ for (idx in cls_array) {
|
|
|
|
+ value = cls_array[idx]
|
|
|
|
+ pattern = sprintf("%s%s|", pattern, condition_helper("class", value));
|
|
}
|
|
}
|
|
sub(/\|$/, ")" blank "*%}$", pattern)
|
|
sub(/\|$/, ")" blank "*%}$", pattern)
|
|
return pattern
|
|
return pattern
|
|
@@ -439,6 +449,7 @@ EOF
|
|
-v distro="$local_distro" \
|
|
-v distro="$local_distro" \
|
|
-v source="$input" \
|
|
-v source="$input" \
|
|
-v source_dir="$(dirname "$input")" \
|
|
-v source_dir="$(dirname "$input")" \
|
|
|
|
+ -v classes="$(join_string $'\n' "${local_classes[@]}")" \
|
|
"$awk_pgm" \
|
|
"$awk_pgm" \
|
|
"$input" > "$temp_file" || rm -f "$temp_file"
|
|
"$input" > "$temp_file" || rm -f "$temp_file"
|
|
|
|
|
|
@@ -457,6 +468,7 @@ function template_j2cli() {
|
|
YADM_USER="$local_user" \
|
|
YADM_USER="$local_user" \
|
|
YADM_DISTRO="$local_distro" \
|
|
YADM_DISTRO="$local_distro" \
|
|
YADM_SOURCE="$input" \
|
|
YADM_SOURCE="$input" \
|
|
|
|
+ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
|
|
"$J2CLI_PROGRAM" "$input" -o "$temp_file"
|
|
"$J2CLI_PROGRAM" "$input" -o "$temp_file"
|
|
|
|
|
|
move_file "$input" "$output" "$temp_file"
|
|
move_file "$input" "$output" "$temp_file"
|
|
@@ -474,6 +486,7 @@ function template_envtpl() {
|
|
YADM_USER="$local_user" \
|
|
YADM_USER="$local_user" \
|
|
YADM_DISTRO="$local_distro" \
|
|
YADM_DISTRO="$local_distro" \
|
|
YADM_SOURCE="$input" \
|
|
YADM_SOURCE="$input" \
|
|
|
|
+ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
|
|
"$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file"
|
|
"$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file"
|
|
|
|
|
|
move_file "$input" "$output" "$temp_file"
|
|
move_file "$input" "$output" "$temp_file"
|
|
@@ -484,6 +497,7 @@ function template_esh() {
|
|
output="$2"
|
|
output="$2"
|
|
temp_file="${output}.$$.$RANDOM"
|
|
temp_file="${output}.$$.$RANDOM"
|
|
|
|
|
|
|
|
+ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
|
|
"$ESH_PROGRAM" -o "$temp_file" "$input" \
|
|
"$ESH_PROGRAM" -o "$temp_file" "$input" \
|
|
YADM_CLASS="$local_class" \
|
|
YADM_CLASS="$local_class" \
|
|
YADM_ARCH="$local_arch" \
|
|
YADM_ARCH="$local_arch" \
|
|
@@ -521,6 +535,7 @@ function alt() {
|
|
|
|
|
|
# gather values for processing alternates
|
|
# gather values for processing alternates
|
|
local local_class
|
|
local local_class
|
|
|
|
+ local -a local_classes
|
|
local local_arch
|
|
local local_arch
|
|
local local_system
|
|
local local_system
|
|
local local_host
|
|
local local_host
|
|
@@ -620,7 +635,12 @@ function remove_stale_links() {
|
|
|
|
|
|
function set_local_alt_values() {
|
|
function set_local_alt_values() {
|
|
|
|
|
|
- local_class="$(config local.class)"
|
|
|
|
|
|
+ local -a all_classes
|
|
|
|
+ all_classes=$(config --get-all local.class)
|
|
|
|
+ while IFS='' read -r local_class; do
|
|
|
|
+ local_classes+=("$local_class")
|
|
|
|
+ done <<< "$all_classes"
|
|
|
|
+ local_class="${local_classes[-1]:-}"
|
|
|
|
|
|
local_arch="$(config local.arch)"
|
|
local_arch="$(config local.arch)"
|
|
if [ -z "$local_arch" ] ; then
|
|
if [ -z "$local_arch" ] ; then
|
|
@@ -2032,6 +2052,16 @@ function join_string {
|
|
printf "%s" "${*:2}"
|
|
printf "%s" "${*:2}"
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function in_list {
|
|
|
|
+ local element="$1"
|
|
|
|
+ shift
|
|
|
|
+
|
|
|
|
+ for e in "$@"; do
|
|
|
|
+ [[ "$e" = "$element" ]] && return 0
|
|
|
|
+ done
|
|
|
|
+ return 1
|
|
|
|
+}
|
|
|
|
+
|
|
function get_mode {
|
|
function get_mode {
|
|
local filename="$1"
|
|
local filename="$1"
|
|
local mode
|
|
local mode
|