1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Merge pull request #203 from jameshclrk/arch-alternative

This commit is contained in:
Tim Byrne
2021-12-21 16:50:41 -06:00
6 changed files with 70 additions and 13 deletions

26
yadm
View File

@@ -189,37 +189,44 @@ function score_file() {
if [[ "$label" =~ ^(default)$ ]]; then
score=$((score + 0))
# variable conditions
elif [[ "$label" =~ ^(a|arch|architecture)$ ]]; then
if [ "$value" = "$local_arch" ]; then
score=$((score + 1))
else
score=0
return
fi
elif [[ "$label" =~ ^(o|os)$ ]]; then
if [ "$value" = "$local_system" ]; then
score=$((score + 1))
score=$((score + 2))
else
score=0
return
fi
elif [[ "$label" =~ ^(d|distro)$ ]]; then
if [ "$value" = "$local_distro" ]; then
score=$((score + 2))
score=$((score + 4))
else
score=0
return
fi
elif [[ "$label" =~ ^(c|class)$ ]]; then
if [ "$value" = "$local_class" ]; then
score=$((score + 4))
score=$((score + 8))
else
score=0
return
fi
elif [[ "$label" =~ ^(h|hostname)$ ]]; then
if [ "$value" = "$local_host" ]; then
score=$((score + 8))
score=$((score + 16))
else
score=0
return
fi
elif [[ "$label" =~ ^(u|user)$ ]]; then
if [ "$value" = "$local_user" ]; then
score=$((score + 16))
score=$((score + 32))
else
score=0
return
@@ -424,6 +431,7 @@ EOF
"${AWK_PROGRAM[0]}" \
-v class="$local_class" \
-v arch="$local_arch" \
-v os="$local_system" \
-v host="$local_host" \
-v user="$local_user" \
@@ -442,6 +450,7 @@ function template_j2cli() {
temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
@@ -458,6 +467,7 @@ function template_envtpl() {
temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
@@ -509,6 +519,7 @@ function alt() {
# gather values for processing alternates
local local_class
local local_arch
local local_system
local local_host
local local_user
@@ -609,6 +620,11 @@ function set_local_alt_values() {
local_class="$(config local.class)"
local_arch="$(config local.arch)"
if [ -z "$local_arch" ] ; then
local_arch=$(uname -m)
fi
local_system="$(config local.os)"
if [ -z "$local_system" ] ; then
local_system="$OPERATING_SYSTEM"