1
0
Fork 0
mirror of synced 2024-12-22 14:41:07 -05:00

Rename the alt variables local_* to YADM_* and export them

local_class -> YADM_CLASS
local_system -> YADM_OS
local_host -> YADM_HOSTNAME
local_user -> YADM_USER
local_distro -> YADM_DISTRO

The new names match the names used for j2/esh templates.
This commit is contained in:
Erik Flodin 2021-01-17 22:00:39 +01:00 committed by Erik Flodin
parent 2f00dabcdb
commit 650644cfb8
No known key found for this signature in database
GPG key ID: 420A7C865EE3F85F
7 changed files with 119 additions and 141 deletions

View file

@ -2,11 +2,6 @@
import pytest import pytest
INIT_VARS = """ INIT_VARS = """
score=0
local_class=testclass
local_system=testsystem
local_host=testhost
local_user=testuser
alt_scores=() alt_scores=()
alt_targets=() alt_targets=()
alt_sources=() alt_sources=()

View file

@ -10,7 +10,7 @@ CONDITION = {
'labels': ['a', 'arch', 'architecture'], 'labels': ['a', 'arch', 'architecture'],
'modifier': 1, 'modifier': 1,
}, },
'system': { 'os': {
'labels': ['o', 'os'], 'labels': ['o', 'os'],
'modifier': 2, 'modifier': 2,
}, },
@ -54,9 +54,9 @@ def calculate_score(filename):
else: else:
score = 0 score = 0
break break
elif label in CONDITION['system']['labels']: elif label in CONDITION['os']['labels']:
if value == 'testsystem': if value == 'testos':
score += 1000 + CONDITION['system']['modifier'] score += 1000 + CONDITION['os']['modifier']
else: else:
score = 0 score = 0
break break
@ -95,7 +95,7 @@ def calculate_score(filename):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'arch', ['arch', None], ids=['arch', 'no-arch']) 'arch', ['arch', None], ids=['arch', 'no-arch'])
@pytest.mark.parametrize( @pytest.mark.parametrize(
'system', ['system', None], ids=['system', 'no-system']) 'system', ['os', None], ids=['os', 'no-os'])
@pytest.mark.parametrize( @pytest.mark.parametrize(
'distro', ['distro', None], ids=['distro', 'no-distro']) 'distro', ['distro', None], ids=['distro', 'no-distro'])
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -110,9 +110,9 @@ def test_score_values(
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
local_class = 'testclass' local_class = 'testclass'
local_arch = 'testarch' local_arch = 'testarch'
local_system = 'testsystem' local_os = 'testos'
local_distro = 'testdistro' local_distro = 'testdistro'
local_host = 'testhost' local_hostname = 'testhost'
local_user = 'testuser' local_user = 'testuser'
filenames = {'filename##': 0} filenames = {'filename##': 0}
@ -145,7 +145,7 @@ def test_score_values(
newfile += ',' newfile += ','
newfile += '.'.join([ newfile += '.'.join([
label, label,
local_system if match else 'badsys' local_os if match else 'bados'
]) ])
filenames[newfile] = calculate_score(newfile) filenames[newfile] = calculate_score(newfile)
if distro: if distro:
@ -181,7 +181,7 @@ def test_score_values(
newfile += ',' newfile += ','
newfile += '.'.join([ newfile += '.'.join([
label, label,
local_host if match else 'badhost' local_hostname if match else 'badhost'
]) ])
filenames[newfile] = calculate_score(newfile) filenames[newfile] = calculate_score(newfile)
if user: if user:
@ -200,12 +200,12 @@ def test_score_values(
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
score=0 score=0
local_class={local_class} YADM_CLASS={local_class}
local_arch={local_arch} YADM_ARCH={local_arch}
local_system={local_system} YADM_OS={local_os}
local_distro={local_distro} YADM_DISTRO={local_distro}
local_host={local_host} YADM_HOSTNAME={local_hostname}
local_user={local_user} YADM_USER={local_user}
""" """
expected = '' expected = ''
for filename in filenames: for filename in filenames:
@ -233,7 +233,7 @@ def test_extensions(runner, yadm, ext):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
score=0 score=0
local_user={local_user} YADM_USER={local_user}
score_file "{filename}" score_file "{filename}"
echo "$score" echo "$score"
""" """
@ -248,9 +248,9 @@ def test_score_values_templates(runner, yadm):
"""Test score results""" """Test score results"""
local_class = 'testclass' local_class = 'testclass'
local_arch = 'arch' local_arch = 'arch'
local_system = 'testsystem' local_os = 'testos'
local_distro = 'testdistro' local_distro = 'testdistro'
local_host = 'testhost' local_hostname = 'testhost'
local_user = 'testuser' local_user = 'testuser'
filenames = {'filename##': 0} filenames = {'filename##': 0}
@ -265,12 +265,12 @@ def test_score_values_templates(runner, yadm):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
score=0 score=0
local_class={local_class} YADM_CLASS={local_class}
local_arch={local_arch} YADM_ARCH={local_arch}
local_system={local_system} YADM_OS={local_os}
local_distro={local_distro} YADM_DISTRO={local_distro}
local_host={local_host} YADM_HOSTNAME={local_hostname}
local_user={local_user} YADM_USER={local_user}
""" """
expected = '' expected = ''
for filename in filenames: for filename in filenames:

View file

@ -1,4 +1,4 @@
"""Unit tests: set_local_alt_values""" """Unit tests: set_alt_values"""
import pytest import pytest
import utils import utils
@ -20,18 +20,18 @@ import utils
] ]
) )
@pytest.mark.usefixtures('ds1_copy') @pytest.mark.usefixtures('ds1_copy')
def test_set_local_alt_values( def test_set_alt_values(
runner, yadm, paths, tst_sys, tst_host, tst_user, override): runner, yadm, paths, tst_sys, tst_host, tst_user, override):
"""Use issue_legacy_path_warning""" """Use issue_legacy_path_warning"""
script = f""" script = f"""
YADM_TEST=1 source {yadm} && YADM_TEST=1 source {yadm} &&
set_operating_system && set_operating_system &&
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths && YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
set_local_alt_values set_alt_values
echo "class='$local_class'" echo "class='$YADM_CLASS'"
echo "os='$local_system'" echo "os='$YADM_OS'"
echo "host='$local_host'" echo "host='$YADM_HOSTNAME'"
echo "user='$local_user'" echo "user='$YADM_USER'"
""" """
if override: if override:
@ -69,8 +69,8 @@ def test_distro(runner, yadm):
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
function config() {{ echo "$1"; }} function config() {{ echo "$1"; }}
function query_distro() {{ echo "testdistro"; }} function query_distro() {{ echo "testdistro"; }}
set_local_alt_values set_alt_values
echo "distro='$local_distro'" echo "distro='$YADM_DISTRO'"
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.success assert run.success

View file

@ -6,8 +6,8 @@ FILE_MODE = 0o754
# these values are also testing the handling of bizarre characters # these values are also testing the handling of bizarre characters
LOCAL_CLASS = "default_Test+@-!^Class" LOCAL_CLASS = "default_Test+@-!^Class"
LOCAL_ARCH = "default_Test+@-!^Arch" LOCAL_ARCH = "default_Test+@-!^Arch"
LOCAL_SYSTEM = "default_Test+@-!^System" LOCAL_OS = "default_Test+@-!^System"
LOCAL_HOST = "default_Test+@-!^Host" LOCAL_HOSTNAME = "default_Test+@-!^Host"
LOCAL_USER = "default_Test+@-!^User" LOCAL_USER = "default_Test+@-!^User"
LOCAL_DISTRO = "default_Test+@-!^Distro" LOCAL_DISTRO = "default_Test+@-!^Distro"
TEMPLATE = f''' TEMPLATE = f'''
@ -47,7 +47,7 @@ wrong arch 2
{{% if yadm.os == "wrongos1" %}} {{% if yadm.os == "wrongos1" %}}
wrong os 1 wrong os 1
{{% endif %}} {{% endif %}}
{{% if yadm.os == "{LOCAL_SYSTEM}" %}} {{% if yadm.os == "{LOCAL_OS}" %}}
Included section for os = {{{{yadm.os}}}} ({{{{yadm.os}}}} repeated) Included section for os = {{{{yadm.os}}}} ({{{{yadm.os}}}} repeated)
{{% endif %}} {{% endif %}}
{{% if yadm.os == "wrongos2" %}} {{% if yadm.os == "wrongos2" %}}
@ -56,7 +56,7 @@ wrong os 2
{{% if yadm.hostname == "wronghost1" %}} {{% if yadm.hostname == "wronghost1" %}}
wrong host 1 wrong host 1
{{% endif %}} {{% endif %}}
{{% if yadm.hostname == "{LOCAL_HOST}" %}} {{% if yadm.hostname == "{LOCAL_HOSTNAME}" %}}
Included section for host = {{{{yadm.hostname}}}} ({{{{yadm.hostname}}}} again) Included section for host = {{{{yadm.hostname}}}} ({{{{yadm.hostname}}}} again)
{{% endif %}} {{% endif %}}
{{% if yadm.hostname == "wronghost2" %}} {{% if yadm.hostname == "wronghost2" %}}
@ -86,16 +86,16 @@ EXPECTED = f'''
start of template start of template
default class = >{LOCAL_CLASS}< default class = >{LOCAL_CLASS}<
default arch = >{LOCAL_ARCH}< default arch = >{LOCAL_ARCH}<
default os = >{LOCAL_SYSTEM}< default os = >{LOCAL_OS}<
default host = >{LOCAL_HOST}< default host = >{LOCAL_HOSTNAME}<
default user = >{LOCAL_USER}< default user = >{LOCAL_USER}<
default distro = >{LOCAL_DISTRO}< default distro = >{LOCAL_DISTRO}<
Included section from else Included section from else
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Multiple lines Multiple lines
Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated)
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for os = {LOCAL_OS} ({LOCAL_OS} repeated)
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for host = {LOCAL_HOSTNAME} ({LOCAL_HOSTNAME} again)
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
end of template end of template
@ -149,12 +149,12 @@ def test_template_default(runner, yadm, tmpdir):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
set_awk set_awk
local_class="{LOCAL_CLASS}" YADM_CLASS="{LOCAL_CLASS}"
local_arch="{LOCAL_ARCH}" YADM_ARCH="{LOCAL_ARCH}"
local_system="{LOCAL_SYSTEM}" YADM_OS="{LOCAL_OS}"
local_host="{LOCAL_HOST}" YADM_HOSTNAME="{LOCAL_HOSTNAME}"
local_user="{LOCAL_USER}" YADM_USER="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}" YADM_DISTRO="{LOCAL_DISTRO}"
template_default "{input_file}" "{output_file}" template_default "{input_file}" "{output_file}"
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
@ -193,7 +193,7 @@ def test_include(runner, yadm, tmpdir):
basic_file = tmpdir.join('basic') basic_file = tmpdir.join('basic')
basic_file.write(INCLUDE_BASIC) basic_file.write(INCLUDE_BASIC)
variables_file = tmpdir.join(f'variables.{LOCAL_SYSTEM}') variables_file = tmpdir.join(f'variables.{LOCAL_OS}')
variables_file.write(INCLUDE_VARIABLES) variables_file.write(INCLUDE_VARIABLES)
nested_file = tmpdir.join('dir').join('nested') nested_file = tmpdir.join('dir').join('nested')
@ -207,8 +207,8 @@ def test_include(runner, yadm, tmpdir):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
set_awk set_awk
local_class="{LOCAL_CLASS}" YADM_CLASS="{LOCAL_CLASS}"
local_system="{LOCAL_SYSTEM}" YADM_OS="{LOCAL_OS}"
template_default "{input_file}" "{output_file}" template_default "{input_file}" "{output_file}"
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)

View file

@ -5,8 +5,8 @@ FILE_MODE = 0o754
LOCAL_CLASS = "esh_Test+@-!^Class" LOCAL_CLASS = "esh_Test+@-!^Class"
LOCAL_ARCH = "esh_Test+@-!^Arch" LOCAL_ARCH = "esh_Test+@-!^Arch"
LOCAL_SYSTEM = "esh_Test+@-!^System" LOCAL_OS = "esh_Test+@-!^System"
LOCAL_HOST = "esh_Test+@-!^Host" LOCAL_HOSTNAME = "esh_Test+@-!^Host"
LOCAL_USER = "esh_Test+@-!^User" LOCAL_USER = "esh_Test+@-!^User"
LOCAL_DISTRO = "esh_Test+@-!^Distro" LOCAL_DISTRO = "esh_Test+@-!^Distro"
TEMPLATE = f''' TEMPLATE = f'''
@ -38,7 +38,7 @@ wrong arch 2
<% if [ "$YADM_OS" = "wrongos1" ]; then -%> <% if [ "$YADM_OS" = "wrongos1" ]; then -%>
wrong os 1 wrong os 1
<% fi -%> <% fi -%>
<% if [ "$YADM_OS" = "{LOCAL_SYSTEM}" ]; then -%> <% if [ "$YADM_OS" = "{LOCAL_OS}" ]; then -%>
Included section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated) Included section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated)
<% fi -%> <% fi -%>
<% if [ "$YADM_OS" = "wrongos2" ]; then -%> <% if [ "$YADM_OS" = "wrongos2" ]; then -%>
@ -47,7 +47,7 @@ wrong os 2
<% if [ "$YADM_HOSTNAME" = "wronghost1" ]; then -%> <% if [ "$YADM_HOSTNAME" = "wronghost1" ]; then -%>
wrong host 1 wrong host 1
<% fi -%> <% fi -%>
<% if [ "$YADM_HOSTNAME" = "{LOCAL_HOST}" ]; then -%> <% if [ "$YADM_HOSTNAME" = "{LOCAL_HOSTNAME}" ]; then -%>
Included section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again) Included section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again)
<% fi -%> <% fi -%>
<% if [ "$YADM_HOSTNAME" = "wronghost2" ]; then -%> <% if [ "$YADM_HOSTNAME" = "wronghost2" ]; then -%>
@ -77,14 +77,14 @@ EXPECTED = f'''
start of template start of template
esh class = >{LOCAL_CLASS}< esh class = >{LOCAL_CLASS}<
esh arch = >{LOCAL_ARCH}< esh arch = >{LOCAL_ARCH}<
esh os = >{LOCAL_SYSTEM}< esh os = >{LOCAL_OS}<
esh host = >{LOCAL_HOST}< esh host = >{LOCAL_HOSTNAME}<
esh user = >{LOCAL_USER}< esh user = >{LOCAL_USER}<
esh distro = >{LOCAL_DISTRO}< esh distro = >{LOCAL_DISTRO}<
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated)
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for os = {LOCAL_OS} ({LOCAL_OS} repeated)
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for host = {LOCAL_HOSTNAME} ({LOCAL_HOSTNAME} again)
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
end of template end of template
@ -107,12 +107,12 @@ def test_template_esh(runner, yadm, tmpdir):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
local_class="{LOCAL_CLASS}" export YADM_CLASS="{LOCAL_CLASS}"
local_arch="{LOCAL_ARCH}" export YADM_ARCH="{LOCAL_ARCH}"
local_system="{LOCAL_SYSTEM}" export YADM_OS="{LOCAL_OS}"
local_host="{LOCAL_HOST}" export YADM_HOSTNAME="{LOCAL_HOSTNAME}"
local_user="{LOCAL_USER}" export YADM_USER="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}" export YADM_DISTRO="{LOCAL_DISTRO}"
template_esh "{input_file}" "{output_file}" template_esh "{input_file}" "{output_file}"
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)

View file

@ -6,8 +6,8 @@ FILE_MODE = 0o754
LOCAL_CLASS = "j2_Test+@-!^Class" LOCAL_CLASS = "j2_Test+@-!^Class"
LOCAL_ARCH = "j2_Test+@-!^Arch" LOCAL_ARCH = "j2_Test+@-!^Arch"
LOCAL_SYSTEM = "j2_Test+@-!^System" LOCAL_OS = "j2_Test+@-!^System"
LOCAL_HOST = "j2_Test+@-!^Host" LOCAL_HOSTNAME = "j2_Test+@-!^Host"
LOCAL_USER = "j2_Test+@-!^User" LOCAL_USER = "j2_Test+@-!^User"
LOCAL_DISTRO = "j2_Test+@-!^Distro" LOCAL_DISTRO = "j2_Test+@-!^Distro"
TEMPLATE = f''' TEMPLATE = f'''
@ -39,7 +39,7 @@ wrong arch 2
{{%- if YADM_OS == "wrongos1" %}} {{%- if YADM_OS == "wrongos1" %}}
wrong os 1 wrong os 1
{{%- endif %}} {{%- endif %}}
{{%- if YADM_OS == "{LOCAL_SYSTEM}" %}} {{%- if YADM_OS == "{LOCAL_OS}" %}}
Included section for os = {{{{YADM_OS}}}} ({{{{YADM_OS}}}} repeated) Included section for os = {{{{YADM_OS}}}} ({{{{YADM_OS}}}} repeated)
{{%- endif %}} {{%- endif %}}
{{%- if YADM_OS == "wrongos2" %}} {{%- if YADM_OS == "wrongos2" %}}
@ -48,7 +48,7 @@ wrong os 2
{{%- if YADM_HOSTNAME == "wronghost1" %}} {{%- if YADM_HOSTNAME == "wronghost1" %}}
wrong host 1 wrong host 1
{{%- endif %}} {{%- endif %}}
{{%- if YADM_HOSTNAME == "{LOCAL_HOST}" %}} {{%- if YADM_HOSTNAME == "{LOCAL_HOSTNAME}" %}}
Included section for host = {{{{YADM_HOSTNAME}}}} ({{{{YADM_HOSTNAME}}}} again) Included section for host = {{{{YADM_HOSTNAME}}}} ({{{{YADM_HOSTNAME}}}} again)
{{%- endif %}} {{%- endif %}}
{{%- if YADM_HOSTNAME == "wronghost2" %}} {{%- if YADM_HOSTNAME == "wronghost2" %}}
@ -78,14 +78,14 @@ EXPECTED = f'''
start of template start of template
j2 class = >{LOCAL_CLASS}< j2 class = >{LOCAL_CLASS}<
j2 arch = >{LOCAL_ARCH}< j2 arch = >{LOCAL_ARCH}<
j2 os = >{LOCAL_SYSTEM}< j2 os = >{LOCAL_OS}<
j2 host = >{LOCAL_HOST}< j2 host = >{LOCAL_HOSTNAME}<
j2 user = >{LOCAL_USER}< j2 user = >{LOCAL_USER}<
j2 distro = >{LOCAL_DISTRO}< j2 distro = >{LOCAL_DISTRO}<
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated)
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for os = {LOCAL_OS} ({LOCAL_OS} repeated)
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for host = {LOCAL_HOSTNAME} ({LOCAL_HOSTNAME} again)
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
end of template end of template
@ -109,12 +109,12 @@ def test_template_j2(runner, yadm, tmpdir, processor):
script = f""" script = f"""
YADM_TEST=1 source {yadm} YADM_TEST=1 source {yadm}
local_class="{LOCAL_CLASS}" export YADM_CLASS="{LOCAL_CLASS}"
local_arch="{LOCAL_ARCH}" export YADM_ARCH="{LOCAL_ARCH}"
local_system="{LOCAL_SYSTEM}" export YADM_OS="{LOCAL_OS}"
local_host="{LOCAL_HOST}" export YADM_HOSTNAME="{LOCAL_HOSTNAME}"
local_user="{LOCAL_USER}" export YADM_USER="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}" export YADM_DISTRO="{LOCAL_DISTRO}"
template_{processor} "{input_file}" "{output_file}" template_{processor} "{input_file}" "{output_file}"
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)

95
yadm
View file

@ -190,42 +190,42 @@ function score_file() {
score=$((score + 0)) score=$((score + 0))
# variable conditions # variable conditions
elif [[ "$label" =~ ^(a|arch|architecture)$ ]]; then elif [[ "$label" =~ ^(a|arch|architecture)$ ]]; then
if [ "$value" = "$local_arch" ]; then if [ "$value" = "$YADM_ARCH" ]; then
score=$((score + 1)) score=$((score + 1))
else else
score=0 score=0
return return
fi fi
elif [[ "$label" =~ ^(o|os)$ ]]; then elif [[ "$label" =~ ^(o|os)$ ]]; then
if [ "$value" = "$local_system" ]; then if [ "$value" = "$YADM_OS" ]; then
score=$((score + 2)) score=$((score + 2))
else else
score=0 score=0
return return
fi fi
elif [[ "$label" =~ ^(d|distro)$ ]]; then elif [[ "$label" =~ ^(d|distro)$ ]]; then
if [ "$value" = "$local_distro" ]; then if [ "$value" = "$YADM_DISTRO" ]; then
score=$((score + 4)) score=$((score + 4))
else else
score=0 score=0
return return
fi fi
elif [[ "$label" =~ ^(c|class)$ ]]; then elif [[ "$label" =~ ^(c|class)$ ]]; then
if [ "$value" = "$local_class" ]; then if [ "$value" = "$YADM_CLASS" ]; then
score=$((score + 8)) score=$((score + 8))
else else
score=0 score=0
return return
fi fi
elif [[ "$label" =~ ^(h|hostname)$ ]]; then elif [[ "$label" =~ ^(h|hostname)$ ]]; then
if [ "$value" = "$local_host" ]; then if [ "$value" = "$YADM_HOSTNAME" ]; then
score=$((score + 16)) score=$((score + 16))
else else
score=0 score=0
return return
fi fi
elif [[ "$label" =~ ^(u|user)$ ]]; then elif [[ "$label" =~ ^(u|user)$ ]]; then
if [ "$value" = "$local_user" ]; then if [ "$value" = "$YADM_USER" ]; then
score=$((score + 32)) score=$((score + 32))
else else
score=0 score=0
@ -367,7 +367,7 @@ BEGIN {
c["class"] = class c["class"] = class
c["arch"] = arch c["arch"] = arch
c["os"] = os c["os"] = os
c["hostname"] = host c["hostname"] = hostname
c["user"] = user c["user"] = user
c["distro"] = distro c["distro"] = distro
c["source"] = source c["source"] = source
@ -431,12 +431,12 @@ function conditions() {
EOF EOF
"${AWK_PROGRAM[0]}" \ "${AWK_PROGRAM[0]}" \
-v class="$local_class" \ -v class="$YADM_CLASS" \
-v arch="$local_arch" \ -v arch="$YADM_ARCH" \
-v os="$local_system" \ -v os="$YADM_OS" \
-v host="$local_host" \ -v hostname="$YADM_HOSTNAME" \
-v user="$local_user" \ -v user="$YADM_USER" \
-v distro="$local_distro" \ -v distro="$YADM_DISTRO" \
-v source="$input" \ -v source="$input" \
-v source_dir="$(dirname "$input")" \ -v source_dir="$(dirname "$input")" \
"$awk_pgm" \ "$awk_pgm" \
@ -450,12 +450,6 @@ function template_j2cli() {
output="$2" output="$2"
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \
YADM_SOURCE="$input" \ YADM_SOURCE="$input" \
"$J2CLI_PROGRAM" "$input" -o "$temp_file" "$J2CLI_PROGRAM" "$input" -o "$temp_file"
@ -467,12 +461,6 @@ function template_envtpl() {
output="$2" output="$2"
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \
YADM_SOURCE="$input" \ YADM_SOURCE="$input" \
"$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file" "$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file"
@ -484,14 +472,8 @@ function template_esh() {
output="$2" output="$2"
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
"$ESH_PROGRAM" -o "$temp_file" "$input" \ YADM_SOURCE="$input" \
YADM_CLASS="$local_class" \ "$ESH_PROGRAM" -o "$temp_file" "$input"
YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \
YADM_SOURCE="$input"
move_file "$input" "$output" "$temp_file" move_file "$input" "$output" "$temp_file"
} }
@ -520,13 +502,7 @@ function alt() {
parse_encrypt parse_encrypt
# gather values for processing alternates # gather values for processing alternates
local local_class set_alt_values
local local_arch
local local_system
local local_host
local local_user
local local_distro
set_local_alt_values
# only be noisy if the "alt" command was run directly # only be noisy if the "alt" command was run directly
local loud= local loud=
@ -618,32 +594,39 @@ function remove_stale_links() {
fi fi
} }
function set_local_alt_values() { function set_alt_values() {
local_class="$(config local.class)" export YADM_CLASS
export YADM_ARCH
export YADM_OS
export YADM_HOSTNAME
export YADM_USER
export YADM_DISTRO
local_arch="$(config local.arch)" YADM_CLASS="$(config local.class)"
if [ -z "$local_arch" ] ; then
local_arch=$(uname -m) YADM_ARCH="$(config local.arch)"
if [ -z "$YADM_ARCH" ] ; then
YADM_ARCH=$(uname -m)
fi fi
local_system="$(config local.os)" YADM_OS="$(config local.os)"
if [ -z "$local_system" ] ; then if [ -z "$YADM_OS" ] ; then
local_system="$OPERATING_SYSTEM" YADM_OS="$OPERATING_SYSTEM"
fi fi
local_host="$(config local.hostname)" YADM_HOSTNAME="$(config local.hostname)"
if [ -z "$local_host" ] ; then if [ -z "$YADM_HOSTNAME" ] ; then
local_host=$(uname -n) YADM_HOSTNAME=$(uname -n)
local_host=${local_host%%.*} # trim any domain from hostname YADM_HOSTNAME=${YADM_HOSTNAME%%.*} # trim any domain from hostname
fi fi
local_user="$(config local.user)" YADM_USER="$(config local.user)"
if [ -z "$local_user" ] ; then if [ -z "$YADM_USER" ] ; then
local_user=$(id -u -n) YADM_USER=$(id -u -n)
fi fi
local_distro="$(query_distro)" YADM_DISTRO="$(query_distro)"
} }