From 77d2da4e9b286afc6061f7c2ff5813e17e3bb275 Mon Sep 17 00:00:00 2001 From: James Clark Date: Sat, 22 Feb 2020 01:10:39 +0000 Subject: [PATCH 01/32] Support architecture in alternates (#202) --- pylintrc | 2 +- test/conftest.py | 6 ++++++ test/test_alt.py | 4 +++- test/test_unit_score_file.py | 40 ++++++++++++++++++++++++++++++------ yadm | 27 +++++++++++++++++++----- yadm.1 | 5 +++++ 6 files changed, 71 insertions(+), 13 deletions(-) diff --git a/pylintrc b/pylintrc index 13f768e..1034736 100644 --- a/pylintrc +++ b/pylintrc @@ -8,7 +8,7 @@ max-attributes=8 max-statements=65 [SIMILARITIES] -min-similarity-lines=6 +min-similarity-lines=7 [MESSAGES CONTROL] disable=redefined-outer-name diff --git a/test/conftest.py b/test/conftest.py index 845f3e2..49b13d1 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -74,6 +74,12 @@ def tst_sys(): return platform.system() +@pytest.fixture(scope='session') +def tst_arch(): + """Test session's uname value""" + return platform.machine() + + @pytest.fixture(scope='session') def supported_commands(): """List of supported commands diff --git a/test/test_alt.py b/test/test_alt.py index 359f32d..3b95c01 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -81,6 +81,7 @@ def test_relative_link(runner, paths, yadm_alt): @pytest.mark.usefixtures('ds1_copy') @pytest.mark.parametrize('suffix', [ '##default', + '##a.$tst_arch', '##arch.$tst_arch', '##architecture.$tst_arch', '##o.$tst_sys', '##os.$tst_sys', '##d.$tst_distro', '##distro.$tst_distro', '##c.$tst_class', '##class.$tst_class', @@ -89,7 +90,7 @@ def test_relative_link(runner, paths, yadm_alt): ]) def test_alt_conditions( runner, paths, - tst_sys, tst_distro, tst_host, tst_user, suffix): + tst_arch, tst_sys, tst_distro, tst_host, tst_user, suffix): """Test conditions supported by yadm alt""" yadm_dir = setup_standard_yadm_dir(paths) @@ -98,6 +99,7 @@ def test_alt_conditions( utils.set_local(paths, 'class', tst_class) suffix = string.Template(suffix).substitute( + tst_arch=tst_arch, tst_sys=tst_sys, tst_distro=tst_distro, tst_class=tst_class, diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index 679229f..7c98093 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -6,25 +6,29 @@ CONDITION = { 'labels': ['default'], 'modifier': 0, }, + 'arch': { + 'labels': ['a', 'arch', 'architecture'], + 'modifier': 1, + }, 'system': { 'labels': ['o', 'os'], - 'modifier': 1, + 'modifier': 2, }, 'distro': { 'labels': ['d', 'distro'], - 'modifier': 2, + 'modifier': 4, }, 'class': { 'labels': ['c', 'class'], - 'modifier': 4, + 'modifier': 8, }, 'hostname': { 'labels': ['h', 'hostname'], - 'modifier': 8, + 'modifier': 16, }, 'user': { 'labels': ['u', 'user'], - 'modifier': 16, + 'modifier': 32, }, } TEMPLATE_LABELS = ['t', 'template', 'yadm'] @@ -44,6 +48,12 @@ def calculate_score(filename): label, value = condition.split('.', 1) if label in CONDITION['default']['labels']: score += 1000 + elif label in CONDITION['arch']['labels']: + if value == 'testarch': + score += 1000 + CONDITION['arch']['modifier'] + else: + score = 0 + break elif label in CONDITION['system']['labels']: if value == 'testsystem': score += 1000 + CONDITION['system']['modifier'] @@ -82,6 +92,8 @@ def calculate_score(filename): @pytest.mark.parametrize( 'default', ['default', None], ids=['default', 'no-default']) +@pytest.mark.parametrize( + 'arch', ['arch', None], ids=['arch', 'no-arch']) @pytest.mark.parametrize( 'system', ['system', None], ids=['system', 'no-system']) @pytest.mark.parametrize( @@ -93,10 +105,11 @@ def calculate_score(filename): @pytest.mark.parametrize( 'user', ['user', None], ids=['user', 'no-user']) def test_score_values( - runner, yadm, default, system, distro, cla, host, user): + runner, yadm, default, arch, system, distro, cla, host, user): """Test score results""" # pylint: disable=too-many-branches local_class = 'testclass' + local_arch = 'testarch' local_system = 'testsystem' local_distro = 'testdistro' local_host = 'testhost' @@ -111,6 +124,18 @@ def test_score_values( newfile += ',' newfile += label filenames[newfile] = calculate_score(newfile) + if arch: + for filename in list(filenames): + for match in [True, False]: + for label in CONDITION[arch]['labels']: + newfile = filename + if not newfile.endswith('##'): + newfile += ',' + newfile += '.'.join([ + label, + local_arch if match else 'badarch' + ]) + filenames[newfile] = calculate_score(newfile) if system: for filename in list(filenames): for match in [True, False]: @@ -176,6 +201,7 @@ def test_score_values( YADM_TEST=1 source {yadm} score=0 local_class={local_class} + local_arch={local_arch} local_system={local_system} local_distro={local_distro} local_host={local_host} @@ -199,6 +225,7 @@ def test_score_values( def test_score_values_templates(runner, yadm): """Test score results""" local_class = 'testclass' + local_arch = 'arch' local_system = 'testsystem' local_distro = 'testdistro' local_host = 'testhost' @@ -217,6 +244,7 @@ def test_score_values_templates(runner, yadm): YADM_TEST=1 source {yadm} score=0 local_class={local_class} + local_arch={local_arch} local_system={local_system} local_distro={local_distro} local_host={local_host} diff --git a/yadm b/yadm index f3a2343..aa4d6da 100755 --- a/yadm +++ b/yadm @@ -175,37 +175,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 @@ -367,6 +374,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" \ @@ -383,6 +391,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" \ @@ -398,6 +407,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" \ @@ -416,6 +426,7 @@ function alt() { # gather values for processing alternates local local_class + local local_arch local local_system local local_host local local_user @@ -527,6 +538,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" @@ -656,6 +672,7 @@ function alt_past_linking() { [ -n "$loud" ] && echo "Creating $real_file from template $tracked_file" temp_file="${real_file}.$$.$RANDOM" YADM_CLASS="$local_class" \ + YADM_ARCH="$local_arch" \ YADM_OS="$local_system" \ YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ diff --git a/yadm.1 b/yadm.1 index 49b200c..121a269 100644 --- a/yadm.1 +++ b/yadm.1 @@ -513,6 +513,11 @@ Valid if the value matches the OS. OS is calculated by running .BR "uname -s" . .TP +.BR architecture , " arch" , " a +Valid if the value matches the architecture. +Architecture is calculated by running +.BR "uname -m" . +.TP .BR class , " c Valid if the value matches the .B local.class From 73af4216675ac24283d08c8f80d5c3090d022860 Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Sun, 6 Jun 2021 10:37:14 -0700 Subject: [PATCH 02/32] feat: Add support for env vars in templates --- yadm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yadm b/yadm index 21d4d7c..24ef080 100755 --- a/yadm +++ b/yadm @@ -409,6 +409,9 @@ function replace_vars() { for (label in c) { gsub(("{{" blank "*yadm\\." label blank "*}}"), c[label]) } + for (label in ENVIRON) { + gsub(("{{" blank "*env\\." label blank "*}}"), ENVIRON[label]) + } } function conditions() { pattern = ifs blank "+(" From 9beed3307f2edd88ff479cf239d4dc320d445d71 Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 10 Sep 2021 10:49:27 +0200 Subject: [PATCH 03/32] Fix arch-badge Obviously yadm was moved from AUR to Community repository :-) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a9a6adb..410d270 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version][releases-badge]][releases-link] [![Homebrew Version][homebrew-badge]][homebrew-link] [![OBS Version][obs-badge]][obs-link] -[![Arch Version][aur-badge]][aur-link] +[![Arch Version][arch-badge]][arch-link] [![License][license-badge]][license-link]
[![Master Update][master-date]][master-commits] [![Develop Update][develop-date]][develop-commits] @@ -56,8 +56,8 @@ The star count helps others discover yadm. [Git]: https://git-scm.com/ [GnuPG]: https://gnupg.org/ [OpenSSL]: https://www.openssl.org/ -[aur-badge]: https://img.shields.io/aur/version/yadm.svg -[aur-link]: https://aur.archlinux.org/packages/yadm +[arch-badge]: https://img.shields.io/archlinux/v/community/any/yadm +[arch-link]: https://archlinux.org/packages/community/any/yadm/ [dev-pages-badge]: https://img.shields.io/github/workflow/status/TheLocehiliosan/yadm/Test%20Site/dev-pages?label=dev-pages [develop-badge]: https://img.shields.io/github/workflow/status/TheLocehiliosan/yadm/Tests/develop?label=develop [develop-commits]: https://github.com/TheLocehiliosan/yadm/commits/develop From ed4a60257d721227e1a037a8e4d1559c21677bab Mon Sep 17 00:00:00 2001 From: dessert1 <2664162+dessert1@users.noreply.github.com> Date: Fri, 22 Oct 2021 16:03:23 +0200 Subject: [PATCH 04/32] =?UTF-8?q?fix=20=E2=80=9CMackbook=E2=80=9D=20typo?= =?UTF-8?q?=20in=20manpage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yadm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yadm.md b/yadm.md index d7140e4..6b2257a 100644 --- a/yadm.md +++ b/yadm.md @@ -450,7 +450,7 @@ $HOME/path/example.txt -> $HOME/path/example.txt##os.Darwin,host- name.host2 - However, on another Mackbook named "host3", yadm will create a symbolic + However, on another Macbook named "host3", yadm will create a symbolic link which looks like this: $HOME/path/example.txt -> $HOME/path/example.txt##os.Darwin From 344b740d9b59ee55a7adbca2ff500c21161be28b Mon Sep 17 00:00:00 2001 From: Nicolas stig124 FORMICHELLA Date: Thu, 25 Nov 2021 22:19:53 +0100 Subject: [PATCH 05/32] Fix Makefile portability OBS *among others* need to copy files from the build folder to the package folder. With the old version, that wasn't possible, as it would try to install the software in the worker folder, of course something denied on public instances. Adding $(DESTDIR) before all paths ensure that you can install to another folder --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d9020f9..3bae5e8 100644 --- a/Makefile +++ b/Makefile @@ -192,9 +192,9 @@ install: @[ -n "$(PREFIX)" ] || { echo "PREFIX is not set"; exit 1; } @{\ set -e ;\ - bin="$(PREFIX)/bin" ;\ - doc="$(PREFIX)/share/doc/yadm" ;\ - man="$(PREFIX)/share/man/man1" ;\ + bin="$(DESTDIR)$(PREFIX)/bin" ;\ + doc="$(DESTDIR)$(PREFIX)/share/doc/yadm" ;\ + man="$(DESTDIR)$(PREFIX)/share/man/man1" ;\ install -d "$$bin" "$$doc" "$$man" ;\ install -m 0755 yadm "$$bin" ;\ install -m 0644 yadm.1 "$$man" ;\ From 31e2ce56bc0dc7d014284877d81e73e3023123b0 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 23 Dec 2021 15:42:08 -0600 Subject: [PATCH 06/32] Support "arch" variable in built-in templates --- yadm | 1 + 1 file changed, 1 insertion(+) diff --git a/yadm b/yadm index 0a242cf..bd1cf9c 100755 --- a/yadm +++ b/yadm @@ -365,6 +365,7 @@ function template_default() { BEGIN { blank = "[ ]" c["class"] = class + c["arch"] = arch c["os"] = os c["hostname"] = host c["user"] = user From bacc948bba916679f174677e9b163ecb947c47be Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 23 Dec 2021 15:37:23 -0600 Subject: [PATCH 07/32] Support "YADM_ARCH" variable in esh templates --- yadm | 1 + 1 file changed, 1 insertion(+) diff --git a/yadm b/yadm index bd1cf9c..bce89ff 100755 --- a/yadm +++ b/yadm @@ -486,6 +486,7 @@ function template_esh() { "$ESH_PROGRAM" -o "$temp_file" "$input" \ YADM_CLASS="$local_class" \ + YADM_ARCH="$local_arch" \ YADM_OS="$local_system" \ YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ From 4843e1fa14010c06cb5f072c9c7f7b12ce468b09 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 23 Dec 2021 15:42:43 -0600 Subject: [PATCH 08/32] Add arch to template tests --- test/test_unit_template_default.py | 14 ++++++++++++++ test/test_unit_template_esh.py | 14 ++++++++++++++ test/test_unit_template_j2.py | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index ea2f904..f503a39 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -5,6 +5,7 @@ FILE_MODE = 0o754 # these values are also testing the handling of bizarre characters LOCAL_CLASS = "default_Test+@-!^Class" +LOCAL_ARCH = "default_Test+@-!^Arch" LOCAL_SYSTEM = "default_Test+@-!^System" LOCAL_HOST = "default_Test+@-!^Host" LOCAL_USER = "default_Test+@-!^User" @@ -12,6 +13,7 @@ LOCAL_DISTRO = "default_Test+@-!^Distro" TEMPLATE = f''' start of template default class = >{{{{yadm.class}}}}< +default arch = >{{{{yadm.arch}}}}< default os = >{{{{yadm.os}}}}< default host = >{{{{yadm.hostname}}}}< default user = >{{{{yadm.user}}}}< @@ -33,6 +35,15 @@ Should not be included... {{% if yadm.class == "wrongclass2" %}} wrong class 2 {{% endif %}} +{{% if yadm.arch == "wrongarch1" %}} +wrong arch 1 +{{% endif %}} +{{% if yadm.arch == "{LOCAL_ARCH}" %}} +Included section for arch = {{{{yadm.arch}}}} ({{{{yadm.arch}}}} repeated) +{{% endif %}} +{{% if yadm.arch == "wrongarch2" %}} +wrong arch 2 +{{% endif %}} {{% if yadm.os == "wrongos1" %}} wrong os 1 {{% endif %}} @@ -74,6 +85,7 @@ end of template EXPECTED = f''' start of template default class = >{LOCAL_CLASS}< +default arch = >{LOCAL_ARCH}< default os = >{LOCAL_SYSTEM}< default host = >{LOCAL_HOST}< default user = >{LOCAL_USER}< @@ -81,6 +93,7 @@ default distro = >{LOCAL_DISTRO}< Included section from else Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Multiple lines +Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) @@ -137,6 +150,7 @@ def test_template_default(runner, yadm, tmpdir): YADM_TEST=1 source {yadm} set_awk local_class="{LOCAL_CLASS}" + local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" diff --git a/test/test_unit_template_esh.py b/test/test_unit_template_esh.py index 23766c4..ee3888a 100644 --- a/test/test_unit_template_esh.py +++ b/test/test_unit_template_esh.py @@ -4,6 +4,7 @@ import os FILE_MODE = 0o754 LOCAL_CLASS = "esh_Test+@-!^Class" +LOCAL_ARCH = "esh_Test+@-!^Arch" LOCAL_SYSTEM = "esh_Test+@-!^System" LOCAL_HOST = "esh_Test+@-!^Host" LOCAL_USER = "esh_Test+@-!^User" @@ -11,6 +12,7 @@ LOCAL_DISTRO = "esh_Test+@-!^Distro" TEMPLATE = f''' start of template esh class = ><%=$YADM_CLASS%>< +esh arch = ><%=$YADM_ARCH%>< esh os = ><%=$YADM_OS%>< esh host = ><%=$YADM_HOSTNAME%>< esh user = ><%=$YADM_USER%>< @@ -24,6 +26,15 @@ Included section for class = <%=$YADM_CLASS%> (<%=$YADM_CLASS%> repeated) <% if [ "$YADM_CLASS" = "wrongclass2" ]; then -%> wrong class 2 <% fi -%> +<% if [ "$YADM_ARCH" = "wrongarch1" ]; then -%> +wrong arch 1 +<% fi -%> +<% if [ "$YADM_ARCH" = "{LOCAL_ARCH}" ]; then -%> +Included section for arch = <%=$YADM_ARCH%> (<%=$YADM_ARCH%> repeated) +<% fi -%> +<% if [ "$YADM_ARCH" = "wrongarch2" ]; then -%> +wrong arch 2 +<% fi -%> <% if [ "$YADM_OS" = "wrongos1" ]; then -%> wrong os 1 <% fi -%> @@ -65,11 +76,13 @@ end of template EXPECTED = f''' start of template esh class = >{LOCAL_CLASS}< +esh arch = >{LOCAL_ARCH}< esh os = >{LOCAL_SYSTEM}< esh host = >{LOCAL_HOST}< esh user = >{LOCAL_USER}< esh distro = >{LOCAL_DISTRO}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) @@ -95,6 +108,7 @@ def test_template_esh(runner, yadm, tmpdir): script = f""" YADM_TEST=1 source {yadm} local_class="{LOCAL_CLASS}" + local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" diff --git a/test/test_unit_template_j2.py b/test/test_unit_template_j2.py index 981112b..6e4c5b0 100644 --- a/test/test_unit_template_j2.py +++ b/test/test_unit_template_j2.py @@ -5,6 +5,7 @@ import pytest FILE_MODE = 0o754 LOCAL_CLASS = "j2_Test+@-!^Class" +LOCAL_ARCH = "j2_Test+@-!^Arch" LOCAL_SYSTEM = "j2_Test+@-!^System" LOCAL_HOST = "j2_Test+@-!^Host" LOCAL_USER = "j2_Test+@-!^User" @@ -12,6 +13,7 @@ LOCAL_DISTRO = "j2_Test+@-!^Distro" TEMPLATE = f''' start of template j2 class = >{{{{YADM_CLASS}}}}< +j2 arch = >{{{{YADM_ARCH}}}}< j2 os = >{{{{YADM_OS}}}}< j2 host = >{{{{YADM_HOSTNAME}}}}< j2 user = >{{{{YADM_USER}}}}< @@ -25,6 +27,15 @@ Included section for class = {{{{YADM_CLASS}}}} ({{{{YADM_CLASS}}}} repeated) {{%- if YADM_CLASS == "wrongclass2" %}} wrong class 2 {{%- endif %}} +{{%- if YADM_ARCH == "wrongarch1" %}} +wrong arch 1 +{{%- endif %}} +{{%- if YADM_ARCH == "{LOCAL_ARCH}" %}} +Included section for arch = {{{{YADM_ARCH}}}} ({{{{YADM_ARCH}}}} repeated) +{{%- endif %}} +{{%- if YADM_ARCH == "wrongarch2" %}} +wrong arch 2 +{{%- endif %}} {{%- if YADM_OS == "wrongos1" %}} wrong os 1 {{%- endif %}} @@ -66,11 +77,13 @@ end of template EXPECTED = f''' start of template j2 class = >{LOCAL_CLASS}< +j2 arch = >{LOCAL_ARCH}< j2 os = >{LOCAL_SYSTEM}< j2 host = >{LOCAL_HOST}< j2 user = >{LOCAL_USER}< j2 distro = >{LOCAL_DISTRO}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) @@ -97,6 +110,7 @@ def test_template_j2(runner, yadm, tmpdir, processor): script = f""" YADM_TEST=1 source {yadm} local_class="{LOCAL_CLASS}" + local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" From 4caf5f681e75dc339ba26d9d3d525e771b9f0604 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 23 Dec 2021 15:40:06 -0600 Subject: [PATCH 09/32] Add arch to manpage --- yadm.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/yadm.1 b/yadm.1 index 46dfe44..04da06b 100644 --- a/yadm.1 +++ b/yadm.1 @@ -655,6 +655,7 @@ During processing, the following variables are available in the template: yadm.class YADM_CLASS Locally defined yadm class yadm.distro YADM_DISTRO lsb_release -si yadm.hostname YADM_HOSTNAME uname -n (without domain) + yadm.arch YADM_ARCH uname -m yadm.os YADM_OS uname -s yadm.user YADM_USER id -u -n yadm.source YADM_SOURCE Template filename From 2f00dabcdbbb90dc6f611a61792d984a85e6d592 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Thu, 23 Dec 2021 15:51:18 -0600 Subject: [PATCH 10/32] Make order of attributes match precedence --- yadm.1 | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/yadm.1 b/yadm.1 index 04da06b..6f4ba6b 100644 --- a/yadm.1 +++ b/yadm.1 @@ -478,6 +478,21 @@ Valid if the value matches the current user. Current user is calculated by running .BR "id -u -n" . .TP +.BR hostname , " h +Valid if the value matches the short hostname. +Hostname is calculated by running +.BR "uname -n" , +and trimming off any domain. +.TP +.BR class , " c +Valid if the value matches the +.B local.class +configuration. +Class must be manually set using +.BR "yadm config local.class " . +See the CONFIGURATION section for more details about setting +.BR local.class . +.TP .BR distro , " d Valid if the value matches the distro. Distro is calculated by running @@ -495,21 +510,6 @@ Valid if the value matches the architecture. Architecture is calculated by running .BR "uname -m" . .TP -.BR class , " c -Valid if the value matches the -.B local.class -configuration. -Class must be manually set using -.BR "yadm config local.class " . -See the CONFIGURATION section for more details about setting -.BR local.class . -.TP -.BR hostname , " h -Valid if the value matches the short hostname. -Hostname is calculated by running -.BR "uname -n" , -and trimming off any domain. -.TP .B default Valid when no other alternate is valid. .TP From 42c74efbac61e47789626ea90930e35fa2d0c15f Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Sun, 10 Jan 2021 22:38:42 +0100 Subject: [PATCH 11/32] Add support for multiple local classes A local class is set with: $ yadm config local.class cls1 More classes can be added with: $ yadm config --add local.class cls2 $ yadm config --add local.class cls3 Any of cls1, cls2 and cls3 can be used in an alternate condition. For templates, the existing variable yadm.class/YADM_CLASS is set to the last class (i.e. cls3) to remain compatible with how it works today and with what the following command gives: $ yadm config local.class For the default template processor there is no explicit yadm.classes variable. Instead a yadm.class condition will check against all classes. For the other processors, a new template variable YADM_CLASSES will be set to all classes separated by newline. For jinja2 templates a class can be checked with: {%- if "cls" in YADM_CLASSES.split("\n") %} For esh templates the logic is a bit more complex, but it is possible to do. Fixes #185. --- pylintrc | 2 +- test/test_alt.py | 4 ++- test/test_unit_score_file.py | 1 + test/test_unit_set_local_alt_values.py | 5 +++- test/test_unit_template_default.py | 6 ++++ test/test_unit_template_esh.py | 7 +++++ test/test_unit_template_j2.py | 6 ++++ test/utils.py | 5 ++-- yadm | 40 ++++++++++++++++++++++---- 9 files changed, 66 insertions(+), 10 deletions(-) diff --git a/pylintrc b/pylintrc index 1034736..ba41b74 100644 --- a/pylintrc +++ b/pylintrc @@ -8,7 +8,7 @@ max-attributes=8 max-statements=65 [SIMILARITIES] -min-similarity-lines=7 +min-similarity-lines=8 [MESSAGES CONTROL] disable=redefined-outer-name diff --git a/test/test_alt.py b/test/test_alt.py index 45c9055..1559f10 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -97,7 +97,9 @@ def test_alt_conditions( # set the class tst_class = 'testclass' - utils.set_local(paths, 'class', tst_class) + utils.set_local(paths, 'class', tst_class + ".before") + utils.set_local(paths, 'class', tst_class, add=True) + utils.set_local(paths, 'class', tst_class + ".after", add=True) suffix = string.Template(suffix).substitute( tst_arch=tst_arch, diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index f7b821a..2c9d9c9 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -201,6 +201,7 @@ def test_score_values( YADM_TEST=1 source {yadm} score=0 local_class={local_class} + local_classes=({local_class}) local_arch={local_arch} local_system={local_system} local_distro={local_distro} diff --git a/test/test_unit_set_local_alt_values.py b/test/test_unit_set_local_alt_values.py index e49d055..2bb7802 100644 --- a/test/test_unit_set_local_alt_values.py +++ b/test/test_unit_set_local_alt_values.py @@ -34,7 +34,10 @@ def test_set_local_alt_values( echo "user='$local_user'" """ - if override: + if override == 'class': + utils.set_local(paths, override, 'first') + utils.set_local(paths, override, 'override', add=True) + elif override: utils.set_local(paths, override, 'override') run = runner(command=['bash'], inp=script) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index f503a39..5afe1d7 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -5,6 +5,7 @@ FILE_MODE = 0o754 # these values are also testing the handling of bizarre characters LOCAL_CLASS = "default_Test+@-!^Class" +LOCAL_CLASS2 = "default_Test+@-|^2nd_Class withSpace" LOCAL_ARCH = "default_Test+@-!^Arch" LOCAL_SYSTEM = "default_Test+@-!^System" LOCAL_HOST = "default_Test+@-!^Host" @@ -32,6 +33,9 @@ Multiple lines {{% else %}} Should not be included... {{% endif %}} +{{% if yadm.class == "{LOCAL_CLASS2}" %}} +Included section for second class +{{% endif %}} {{% if yadm.class == "wrongclass2" %}} wrong class 2 {{% endif %}} @@ -93,6 +97,7 @@ default distro = >{LOCAL_DISTRO}< Included section from else Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Multiple lines +Included section for second class Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) @@ -150,6 +155,7 @@ def test_template_default(runner, yadm, tmpdir): YADM_TEST=1 source {yadm} set_awk local_class="{LOCAL_CLASS}" + local_classes=("{LOCAL_CLASS2}" "{LOCAL_CLASS}") local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" diff --git a/test/test_unit_template_esh.py b/test/test_unit_template_esh.py index ee3888a..2672380 100644 --- a/test/test_unit_template_esh.py +++ b/test/test_unit_template_esh.py @@ -4,6 +4,7 @@ import os FILE_MODE = 0o754 LOCAL_CLASS = "esh_Test+@-!^Class" +LOCAL_CLASS2 = "esh_Test+@-|^2nd_Class withSpace" LOCAL_ARCH = "esh_Test+@-!^Arch" LOCAL_SYSTEM = "esh_Test+@-!^System" LOCAL_HOST = "esh_Test+@-!^Host" @@ -26,6 +27,10 @@ Included section for class = <%=$YADM_CLASS%> (<%=$YADM_CLASS%> repeated) <% if [ "$YADM_CLASS" = "wrongclass2" ]; then -%> wrong class 2 <% fi -%> +<% echo "$YADM_CLASSES" | while IFS='' read cls; do + if [ "$cls" = "{LOCAL_CLASS2}" ]; then -%> +Included section for second class +<% fi; done -%> <% if [ "$YADM_ARCH" = "wrongarch1" ]; then -%> wrong arch 1 <% fi -%> @@ -82,6 +87,7 @@ esh host = >{LOCAL_HOST}< esh user = >{LOCAL_USER}< esh distro = >{LOCAL_DISTRO}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included section for second class Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) @@ -108,6 +114,7 @@ def test_template_esh(runner, yadm, tmpdir): script = f""" YADM_TEST=1 source {yadm} local_class="{LOCAL_CLASS}" + local_classes=("{LOCAL_CLASS2}" "{LOCAL_CLASS}") local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" diff --git a/test/test_unit_template_j2.py b/test/test_unit_template_j2.py index 6e4c5b0..e2f48d9 100644 --- a/test/test_unit_template_j2.py +++ b/test/test_unit_template_j2.py @@ -5,6 +5,7 @@ import pytest FILE_MODE = 0o754 LOCAL_CLASS = "j2_Test+@-!^Class" +LOCAL_CLASS2 = "j2_Test+@-|^2nd_Class withSpace" LOCAL_ARCH = "j2_Test+@-!^Arch" LOCAL_SYSTEM = "j2_Test+@-!^System" LOCAL_HOST = "j2_Test+@-!^Host" @@ -27,6 +28,9 @@ Included section for class = {{{{YADM_CLASS}}}} ({{{{YADM_CLASS}}}} repeated) {{%- if YADM_CLASS == "wrongclass2" %}} wrong class 2 {{%- endif %}} +{{%- if "{LOCAL_CLASS2}" in YADM_CLASSES.split("\\n") %}} +Included section for second class +{{%- endif %}} {{%- if YADM_ARCH == "wrongarch1" %}} wrong arch 1 {{%- endif %}} @@ -83,6 +87,7 @@ j2 host = >{LOCAL_HOST}< j2 user = >{LOCAL_USER}< j2 distro = >{LOCAL_DISTRO}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included section for second class Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) @@ -110,6 +115,7 @@ def test_template_j2(runner, yadm, tmpdir, processor): script = f""" YADM_TEST=1 source {yadm} local_class="{LOCAL_CLASS}" + local_classes=("{LOCAL_CLASS2}" "{LOCAL_CLASS}") local_arch="{LOCAL_ARCH}" local_system="{LOCAL_SYSTEM}" local_host="{LOCAL_HOST}" diff --git a/test/utils.py b/test/utils.py index 2291fc5..67a9e53 100644 --- a/test/utils.py +++ b/test/utils.py @@ -21,11 +21,12 @@ INCLUDE_DIRS = ['', 'test alt'] INCLUDE_CONTENT = '8780846c02e34c930d0afd127906668f' -def set_local(paths, variable, value): +def set_local(paths, variable, value, add=False): """Set local override""" + add = "--add" if add else "" os.system( f'GIT_DIR={str(paths.repo)} ' - f'git config --local "local.{variable}" "{value}"' + f'git config --local {add} "local.{variable}" "{value}"' ) diff --git a/yadm b/yadm index bce89ff..167f921 100755 --- a/yadm +++ b/yadm @@ -211,7 +211,7 @@ function score_file() { return fi elif [[ "$label" =~ ^(c|class)$ ]]; then - if [ "$value" = "$local_class" ]; then + if in_list "$value" "${local_classes[@]}"; then score=$((score + 8)) else score=0 @@ -418,12 +418,22 @@ function replace_vars() { 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() { pattern = ifs blank "+(" 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) return pattern @@ -439,6 +449,7 @@ EOF -v distro="$local_distro" \ -v source="$input" \ -v source_dir="$(dirname "$input")" \ + -v classes="$(join_string $'\n' "${local_classes[@]}")" \ "$awk_pgm" \ "$input" > "$temp_file" || rm -f "$temp_file" @@ -457,6 +468,7 @@ function template_j2cli() { YADM_USER="$local_user" \ YADM_DISTRO="$local_distro" \ YADM_SOURCE="$input" \ + YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ "$J2CLI_PROGRAM" "$input" -o "$temp_file" move_file "$input" "$output" "$temp_file" @@ -474,6 +486,7 @@ function template_envtpl() { YADM_USER="$local_user" \ YADM_DISTRO="$local_distro" \ YADM_SOURCE="$input" \ + YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ "$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file" move_file "$input" "$output" "$temp_file" @@ -484,6 +497,7 @@ function template_esh() { output="$2" temp_file="${output}.$$.$RANDOM" + YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ "$ESH_PROGRAM" -o "$temp_file" "$input" \ YADM_CLASS="$local_class" \ YADM_ARCH="$local_arch" \ @@ -521,6 +535,7 @@ function alt() { # gather values for processing alternates local local_class + local -a local_classes local local_arch local local_system local local_host @@ -620,7 +635,12 @@ function remove_stale_links() { 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)" if [ -z "$local_arch" ] ; then @@ -2032,6 +2052,16 @@ function join_string { printf "%s" "${*:2}" } +function in_list { + local element="$1" + shift + + for e in "$@"; do + [[ "$e" = "$element" ]] && return 0 + done + return 1 +} + function get_mode { local filename="$1" local mode From 2379d63068c4e4571d8b7cbaee408ae48387aa9f Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Mon, 27 Dec 2021 22:10:13 +0100 Subject: [PATCH 12/32] Support overriding architecture In the same way as os, hostname and user. --- test/test_unit_set_local_alt_values.py | 10 +++++++++- yadm | 2 +- yadm.1 | 10 +++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/test_unit_set_local_alt_values.py b/test/test_unit_set_local_alt_values.py index e49d055..947a31c 100644 --- a/test/test_unit_set_local_alt_values.py +++ b/test/test_unit_set_local_alt_values.py @@ -7,6 +7,7 @@ import utils 'override', [ False, 'class', + 'arch', 'os', 'hostname', 'user', @@ -14,6 +15,7 @@ import utils ids=[ 'no-override', 'override-class', + 'override-arch', 'override-os', 'override-hostname', 'override-user', @@ -21,7 +23,7 @@ import utils ) @pytest.mark.usefixtures('ds1_copy') def test_set_local_alt_values( - runner, yadm, paths, tst_sys, tst_host, tst_user, override): + runner, yadm, paths, tst_arch, tst_sys, tst_host, tst_user, override): """Use issue_legacy_path_warning""" script = f""" YADM_TEST=1 source {yadm} && @@ -29,6 +31,7 @@ def test_set_local_alt_values( YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths && set_local_alt_values echo "class='$local_class'" + echo "arch='$local_arch'" echo "os='$local_system'" echo "host='$local_host'" echo "user='$local_user'" @@ -46,6 +49,11 @@ def test_set_local_alt_values( else: assert "class=''" in run.out + if override == 'arch': + assert "arch='override'" in run.out + else: + assert f"arch='{tst_arch}'" in run.out + if override == 'os': assert "os='override'" in run.out else: diff --git a/yadm b/yadm index bce89ff..b11ccbf 100755 --- a/yadm +++ b/yadm @@ -837,7 +837,7 @@ EOF function config() { use_repo_config=0 - local_options="^local\.(class|os|hostname|user)$" + local_options="^local\.(class|arch|os|hostname|user)$" for option in "$@"; do [[ "$option" =~ $local_options ]] && use_repo_config=1 done diff --git a/yadm.1 b/yadm.1 index 6f4ba6b..87d0d90 100644 --- a/yadm.1 +++ b/yadm.1 @@ -427,7 +427,7 @@ Disable the permission changes to This feature is enabled by default. .RE -The following four "local" configurations are not stored in the +The following five "local" configurations are not stored in the .IR $HOME/.config/yadm/config, they are stored in the local repository. @@ -436,6 +436,9 @@ they are stored in the local repository. Specify a class for the purpose of symlinking alternate files. By default, no class will be matched. .TP +.B local.arch +Override the architecture for the purpose of symlinking alternate files. +.TP .B local.hostname Override the hostname for the purpose of symlinking alternate files. .TP @@ -601,8 +604,9 @@ command. The following sets the class to be "Work". yadm config local.class Work -Similarly, the values of os, hostname, and user can be manually overridden -using the configuration options +Similarly, the values of architecture, os, hostname, and user can be manually +overridden using the configuration options +.BR local.arch , .BR local.os , .BR local.hostname , and From a9fc8b1374743e743ba395a41604428971ead6b4 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 29 Dec 2021 20:44:12 +0100 Subject: [PATCH 13/32] Bump esh to version 0.3.1 in docker image --- test/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Dockerfile b/test/Dockerfile index 3e5a299..38bea54 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER Tim Byrne # Shellcheck and esh versions ARG SC_VER=0.7.1 -ARG ESH_VER=0.3.0 +ARG ESH_VER=0.3.1 # Install prerequisites and configure UTF-8 locale RUN \ From 1aa9839096f78607d74b0bd327102b0c0743830e Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 29 Dec 2021 21:55:14 +0100 Subject: [PATCH 14/32] Bump shellcheck to version 0.8.0 in docker image And fix the new SC2295 warning. --- test/Dockerfile | 2 +- test/conftest.py | 2 +- yadm | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Dockerfile b/test/Dockerfile index 3e5a299..858c1cb 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:18.04 MAINTAINER Tim Byrne # Shellcheck and esh versions -ARG SC_VER=0.7.1 +ARG SC_VER=0.8.0 ARG ESH_VER=0.3.0 # Install prerequisites and configure UTF-8 locale diff --git a/test/conftest.py b/test/conftest.py index 13e0f86..ea7eee6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -25,7 +25,7 @@ def pytest_addoption(parser): @pytest.fixture(scope='session') def shellcheck_version(): """Version of shellcheck supported""" - return '0.7.1' + return '0.8.0' @pytest.fixture(scope='session') diff --git a/yadm b/yadm index b11ccbf..117c2ca 100755 --- a/yadm +++ b/yadm @@ -170,8 +170,8 @@ function score_file() { tgt="${src%%##*}" conditions="${src#*##}" - if [ "${tgt#$YADM_ALT/}" != "${tgt}" ]; then - tgt="${YADM_BASE}/${tgt#$YADM_ALT/}" + if [ "${tgt#"$YADM_ALT/"}" != "${tgt}" ]; then + tgt="${YADM_BASE}/${tgt#"$YADM_ALT/"}" fi score=0 @@ -552,8 +552,8 @@ function alt() { if [[ $possible_alt =~ .\#\#. ]]; then base_alt="${possible_alt%%##*}" yadm_alt="${YADM_BASE}/${base_alt}" - if [ "${yadm_alt#$YADM_ALT/}" != "${yadm_alt}" ]; then - base_alt="${yadm_alt#$YADM_ALT/}" + if [ "${yadm_alt#"$YADM_ALT/"}" != "${yadm_alt}" ]; then + base_alt="${yadm_alt#"$YADM_ALT/"}" fi possible_alts+=("$YADM_BASE/${base_alt}") fi @@ -1382,7 +1382,7 @@ function upgrade() { ; do if [ -e "$legacy_path" ]; then - new_filename=${legacy_path#$YADM_LEGACY_DIR/} + new_filename="${legacy_path#"$YADM_LEGACY_DIR/"}" new_filename="$YADM_DIR/$new_filename" actions_performed=1 echo "Moving $legacy_path to $new_filename" @@ -1946,7 +1946,7 @@ function relative_path() { result="" count=0 - while [ "${full#$common_part}" == "${full}" ]; do + while [ "${full#"$common_part"}" == "${full}" ]; do [ "$count" = "500" ] && return # this is a failsafe # no match, means that candidate common part is not correct # go up one level (reduce common part) @@ -1967,7 +1967,7 @@ function relative_path() { # since we now have identified the common part, # compute the non-common part - forward_part="${full#$common_part}" + forward_part="${full#"$common_part"}" # and now stick all parts together if [[ -n $result ]] && [[ -n $forward_part ]]; then From f28d4bc1c68d2c0035eacc21ba0f4f3aa3d39b64 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Fri, 7 Jan 2022 00:28:14 -0600 Subject: [PATCH 15/32] Update image tag --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3bae5e8..b8f5cca 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PYTESTS = $(wildcard test/test_*.py) -IMAGE = yadm/testbed:2020-12-29 +IMAGE = yadm/testbed:2022-01-07 .PHONY: all all: From 8186705059ac7ff6b20aaae1e8a15ed172051b79 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 17 Jan 2022 09:12:41 -0600 Subject: [PATCH 16/32] Include Git version with yadm version (#377) --- test/test_version.py | 4 ++-- yadm | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_version.py b/test/test_version.py index 08bebe1..2f51f7e 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -29,8 +29,8 @@ def test_semantic_version(expected_version): @pytest.mark.parametrize('cmd', ['--version', 'version']) def test_reported_version( runner, yadm_cmd, cmd, expected_version): - """Report correct version""" + """Report correct version, include git version""" run = runner(command=yadm_cmd(cmd)) assert run.success assert run.err == '' - assert run.out == f'yadm {expected_version}\n' + assert run.out.startswith(f'yadm version {expected_version}\ngit version') diff --git a/yadm b/yadm index 117c2ca..94aa698 100755 --- a/yadm +++ b/yadm @@ -1413,7 +1413,8 @@ function upgrade() { function version() { - echo "yadm $VERSION" + echo "yadm version $VERSION" + "$GIT_PROGRAM" --version exit_with_hook 0 } From 32bc9abb0c5992ba82fe9cae3a16260e3caf86b2 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 17 Jan 2022 11:45:09 -0600 Subject: [PATCH 17/32] Include bash version --- test/test_version.py | 6 ++++-- yadm | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/test_version.py b/test/test_version.py index 2f51f7e..d440d3b 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -29,8 +29,10 @@ def test_semantic_version(expected_version): @pytest.mark.parametrize('cmd', ['--version', 'version']) def test_reported_version( runner, yadm_cmd, cmd, expected_version): - """Report correct version, include git version""" + """Report correct version and bash/git versions""" run = runner(command=yadm_cmd(cmd)) assert run.success assert run.err == '' - assert run.out.startswith(f'yadm version {expected_version}\ngit version') + assert 'bash version' in run.out + assert 'git version' in run.out + assert run.out.endswith(f'\nyadm version {expected_version}\n') diff --git a/yadm b/yadm index 94aa698..73e6044 100755 --- a/yadm +++ b/yadm @@ -1413,8 +1413,9 @@ function upgrade() { function version() { + echo "bash version $BASH_VERSION" + printf " "; "$GIT_PROGRAM" --version echo "yadm version $VERSION" - "$GIT_PROGRAM" --version exit_with_hook 0 } From 5ae553b078bff5ab48b63e78a9d30ad166f0543c Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 17 Jan 2022 13:46:31 -0600 Subject: [PATCH 18/32] Add support for distro_family (#213) Obtained from /etc/os-release: ID_LIKE. Alternate attributes f & distro_family. --- test/conftest.py | 11 ++++ test/test_alt.py | 5 +- test/test_unit_query_distro_family.py | 26 ++++++++++ test/test_unit_score_file.py | 10 ++-- test/test_unit_set_local_alt_values.py | 9 ++-- test/test_unit_template_default.py | 40 ++++++++++----- test/test_unit_template_esh.py | 40 ++++++++++----- test/test_unit_template_j2.py | 40 ++++++++++----- yadm | 70 ++++++++++++++++++-------- 9 files changed, 187 insertions(+), 64 deletions(-) create mode 100644 test/test_unit_query_distro_family.py diff --git a/test/conftest.py b/test/conftest.py index ea7eee6..95e2fca 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -68,6 +68,17 @@ def tst_distro(runner): return distro +@pytest.fixture(scope='session') +def tst_distro_family(runner): + """Test session's distro_family""" + family = '' + with contextlib.suppress(Exception): + run = runner(command=[ + 'grep', '-oP', r'ID_LIKE=\K.+', '/etc/os-release'], report=False) + family = run.out.strip() + return family + + @pytest.fixture(scope='session') def tst_sys(): """Test session's uname value""" diff --git a/test/test_alt.py b/test/test_alt.py index 45c9055..e0f40f1 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -85,13 +85,15 @@ def test_relative_link(runner, paths, yadm_alt): '##a.$tst_arch', '##arch.$tst_arch', '##architecture.$tst_arch', '##o.$tst_sys', '##os.$tst_sys', '##d.$tst_distro', '##distro.$tst_distro', + '##f.$tst_distro_family', '##distro_family.$tst_distro_family', '##c.$tst_class', '##class.$tst_class', '##h.$tst_host', '##hostname.$tst_host', '##u.$tst_user', '##user.$tst_user', ]) def test_alt_conditions( runner, paths, - tst_arch, tst_sys, tst_distro, tst_host, tst_user, suffix): + tst_arch, tst_sys, tst_distro, tst_distro_family, tst_host, tst_user, + suffix): """Test conditions supported by yadm alt""" yadm_dir, yadm_data = setup_standard_yadm_dir(paths) @@ -103,6 +105,7 @@ def test_alt_conditions( tst_arch=tst_arch, tst_sys=tst_sys, tst_distro=tst_distro, + tst_distro_family=tst_distro_family, tst_class=tst_class, tst_host=tst_host, tst_user=tst_user, diff --git a/test/test_unit_query_distro_family.py b/test/test_unit_query_distro_family.py new file mode 100644 index 0000000..bf68319 --- /dev/null +++ b/test/test_unit_query_distro_family.py @@ -0,0 +1,26 @@ +"""Unit tests: query_distro_family""" +import pytest + + +@pytest.mark.parametrize( + 'condition', ['os-release', 'os-release-quotes', 'missing']) +def test_query_distro_family(runner, yadm, tmp_path, condition): + """Match ID_LIKE when present""" + test_family = 'testfamily' + os_release = tmp_path.joinpath('os-release') + if 'os-release' in condition: + quotes = '"' if 'quotes' in condition else '' + os_release.write_text( + f"testing\nID_LIKE={quotes}{test_family}{quotes}\nfamily") + script = f""" + YADM_TEST=1 source {yadm} + OS_RELEASE="{os_release}" + query_distro_family + """ + run = runner(command=['bash'], inp=script) + assert run.success + assert run.err == '' + if 'os-release' in condition: + assert run.out.rstrip() == test_family + else: + assert run.out.rstrip() == '' diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index f7b821a..c89516b 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -18,17 +18,21 @@ CONDITION = { 'labels': ['d', 'distro'], 'modifier': 4, }, + 'distro_family': { + 'labels': ['f', 'distro_family'], + 'modifier': 8, + }, 'class': { 'labels': ['c', 'class'], - 'modifier': 8, + 'modifier': 16, }, 'hostname': { 'labels': ['h', 'hostname'], - 'modifier': 16, + 'modifier': 32, }, 'user': { 'labels': ['u', 'user'], - 'modifier': 32, + 'modifier': 64, }, } TEMPLATE_LABELS = ['t', 'template', 'yadm'] diff --git a/test/test_unit_set_local_alt_values.py b/test/test_unit_set_local_alt_values.py index 947a31c..b177c2b 100644 --- a/test/test_unit_set_local_alt_values.py +++ b/test/test_unit_set_local_alt_values.py @@ -70,17 +70,20 @@ def test_set_local_alt_values( assert f"user='{tst_user}'" in run.out -def test_distro(runner, yadm): - """Assert that local_distro is set""" +def test_distro_and_family(runner, yadm): + """Assert that local_distro/local_distro_family are set""" script = f""" YADM_TEST=1 source {yadm} function config() {{ echo "$1"; }} function query_distro() {{ echo "testdistro"; }} + function query_distro_family() {{ echo "testfamily"; }} set_local_alt_values echo "distro='$local_distro'" + echo "distro_family='$local_distro_family'" """ run = runner(command=['bash'], inp=script) assert run.success assert run.err == '' - assert run.out.strip() == "distro='testdistro'" + assert "distro='testdistro'" in run.out + assert "distro_family='testfamily'" in run.out diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index f503a39..36098e2 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -10,14 +10,16 @@ LOCAL_SYSTEM = "default_Test+@-!^System" LOCAL_HOST = "default_Test+@-!^Host" LOCAL_USER = "default_Test+@-!^User" LOCAL_DISTRO = "default_Test+@-!^Distro" +LOCAL_DISTRO_FAMILY = "default_Test+@-!^Family" TEMPLATE = f''' start of template -default class = >{{{{yadm.class}}}}< -default arch = >{{{{yadm.arch}}}}< -default os = >{{{{yadm.os}}}}< -default host = >{{{{yadm.hostname}}}}< -default user = >{{{{yadm.user}}}}< -default distro = >{{{{yadm.distro}}}}< +default class = >{{{{yadm.class}}}}< +default arch = >{{{{yadm.arch}}}}< +default os = >{{{{yadm.os}}}}< +default host = >{{{{yadm.hostname}}}}< +default user = >{{{{yadm.user}}}}< +default distro = >{{{{yadm.distro}}}}< +default distro_family = >{{{{yadm.distro_family}}}}< {{% if yadm.class == "else1" %}} wrong else 1 {{% else %}} @@ -80,16 +82,27 @@ Included section for distro = {{{{yadm.distro}}}} ({{{{yadm.distro}}}} again) {{% if yadm.distro == "wrongdistro2" %}} wrong distro 2 {{% endif %}} +{{% if yadm.distro_family == "wrongfamily1" %}} +wrong family 1 +{{% endif %}} +{{% if yadm.distro_family == "{LOCAL_DISTRO_FAMILY}" %}} +Included section for distro_family = \ +{{{{yadm.distro_family}}}} ({{{{yadm.distro_family}}}} again) +{{% endif %}} +{{% if yadm.distro_family == "wrongfamily2" %}} +wrong family 2 +{{% endif %}} end of template ''' EXPECTED = f''' start of template -default class = >{LOCAL_CLASS}< -default arch = >{LOCAL_ARCH}< -default os = >{LOCAL_SYSTEM}< -default host = >{LOCAL_HOST}< -default user = >{LOCAL_USER}< -default distro = >{LOCAL_DISTRO}< +default class = >{LOCAL_CLASS}< +default arch = >{LOCAL_ARCH}< +default os = >{LOCAL_SYSTEM}< +default host = >{LOCAL_HOST}< +default user = >{LOCAL_USER}< +default distro = >{LOCAL_DISTRO}< +default distro_family = >{LOCAL_DISTRO_FAMILY}< Included section from else Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Multiple lines @@ -98,6 +111,8 @@ Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) +Included section for distro_family = \ +{LOCAL_DISTRO_FAMILY} ({LOCAL_DISTRO_FAMILY} again) end of template ''' @@ -155,6 +170,7 @@ def test_template_default(runner, yadm, tmpdir): local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" local_distro="{LOCAL_DISTRO}" + local_distro_family="{LOCAL_DISTRO_FAMILY}" template_default "{input_file}" "{output_file}" """ run = runner(command=['bash'], inp=script) diff --git a/test/test_unit_template_esh.py b/test/test_unit_template_esh.py index ee3888a..d4adc70 100644 --- a/test/test_unit_template_esh.py +++ b/test/test_unit_template_esh.py @@ -9,14 +9,16 @@ LOCAL_SYSTEM = "esh_Test+@-!^System" LOCAL_HOST = "esh_Test+@-!^Host" LOCAL_USER = "esh_Test+@-!^User" LOCAL_DISTRO = "esh_Test+@-!^Distro" +LOCAL_DISTRO_FAMILY = "esh_Test+@-!^Family" TEMPLATE = f''' start of template -esh class = ><%=$YADM_CLASS%>< -esh arch = ><%=$YADM_ARCH%>< -esh os = ><%=$YADM_OS%>< -esh host = ><%=$YADM_HOSTNAME%>< -esh user = ><%=$YADM_USER%>< -esh distro = ><%=$YADM_DISTRO%>< +esh class = ><%=$YADM_CLASS%>< +esh arch = ><%=$YADM_ARCH%>< +esh os = ><%=$YADM_OS%>< +esh host = ><%=$YADM_HOSTNAME%>< +esh user = ><%=$YADM_USER%>< +esh distro = ><%=$YADM_DISTRO%>< +esh distro_family = ><%=$YADM_DISTRO_FAMILY%>< <% if [ "$YADM_CLASS" = "wrongclass1" ]; then -%> wrong class 1 <% fi -%> @@ -71,22 +73,35 @@ Included section for distro = <%=$YADM_DISTRO%> (<%=$YADM_DISTRO%> again) <% if [ "$YADM_DISTRO" = "wrongdistro2" ]; then -%> wrong distro 2 <% fi -%> +<% if [ "$YADM_DISTRO_FAMILY" = "wrongfamily1" ]; then -%> +wrong family 1 +<% fi -%> +<% if [ "$YADM_DISTRO_FAMILY" = "{LOCAL_DISTRO_FAMILY}" ]; then -%> +Included section for distro_family = \ +<%=$YADM_DISTRO_FAMILY%> (<%=$YADM_DISTRO_FAMILY%> again) +<% fi -%> +<% if [ "$YADM_DISTRO" = "wrongfamily2" ]; then -%> +wrong family 2 +<% fi -%> end of template ''' EXPECTED = f''' start of template -esh class = >{LOCAL_CLASS}< -esh arch = >{LOCAL_ARCH}< -esh os = >{LOCAL_SYSTEM}< -esh host = >{LOCAL_HOST}< -esh user = >{LOCAL_USER}< -esh distro = >{LOCAL_DISTRO}< +esh class = >{LOCAL_CLASS}< +esh arch = >{LOCAL_ARCH}< +esh os = >{LOCAL_SYSTEM}< +esh host = >{LOCAL_HOST}< +esh user = >{LOCAL_USER}< +esh distro = >{LOCAL_DISTRO}< +esh distro_family = >{LOCAL_DISTRO_FAMILY}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) +Included section for distro_family = \ +{LOCAL_DISTRO_FAMILY} ({LOCAL_DISTRO_FAMILY} again) end of template ''' @@ -113,6 +128,7 @@ def test_template_esh(runner, yadm, tmpdir): local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" local_distro="{LOCAL_DISTRO}" + local_distro_family="{LOCAL_DISTRO_FAMILY}" template_esh "{input_file}" "{output_file}" """ run = runner(command=['bash'], inp=script) diff --git a/test/test_unit_template_j2.py b/test/test_unit_template_j2.py index 6e4c5b0..7429f8d 100644 --- a/test/test_unit_template_j2.py +++ b/test/test_unit_template_j2.py @@ -10,14 +10,16 @@ LOCAL_SYSTEM = "j2_Test+@-!^System" LOCAL_HOST = "j2_Test+@-!^Host" LOCAL_USER = "j2_Test+@-!^User" LOCAL_DISTRO = "j2_Test+@-!^Distro" +LOCAL_DISTRO_FAMILY = "j2_Test+@-!^Family" TEMPLATE = f''' start of template -j2 class = >{{{{YADM_CLASS}}}}< -j2 arch = >{{{{YADM_ARCH}}}}< -j2 os = >{{{{YADM_OS}}}}< -j2 host = >{{{{YADM_HOSTNAME}}}}< -j2 user = >{{{{YADM_USER}}}}< -j2 distro = >{{{{YADM_DISTRO}}}}< +j2 class = >{{{{YADM_CLASS}}}}< +j2 arch = >{{{{YADM_ARCH}}}}< +j2 os = >{{{{YADM_OS}}}}< +j2 host = >{{{{YADM_HOSTNAME}}}}< +j2 user = >{{{{YADM_USER}}}}< +j2 distro = >{{{{YADM_DISTRO}}}}< +j2 distro_family = >{{{{YADM_DISTRO_FAMILY}}}}< {{%- if YADM_CLASS == "wrongclass1" %}} wrong class 1 {{%- endif %}} @@ -72,22 +74,35 @@ Included section for distro = {{{{YADM_DISTRO}}}} ({{{{YADM_DISTRO}}}} again) {{%- if YADM_DISTRO == "wrongdistro2" %}} wrong distro 2 {{%- endif %}} +{{%- if YADM_DISTRO_FAMILY == "wrongfamily1" %}} +wrong family 1 +{{%- endif %}} +{{%- if YADM_DISTRO_FAMILY == "{LOCAL_DISTRO_FAMILY}" %}} +Included section for distro_family = \ +{{{{YADM_DISTRO_FAMILY}}}} ({{{{YADM_DISTRO_FAMILY}}}} again) +{{%- endif %}} +{{%- if YADM_DISTRO_FAMILY == "wrongfamily2" %}} +wrong family 2 +{{%- endif %}} end of template ''' EXPECTED = f''' start of template -j2 class = >{LOCAL_CLASS}< -j2 arch = >{LOCAL_ARCH}< -j2 os = >{LOCAL_SYSTEM}< -j2 host = >{LOCAL_HOST}< -j2 user = >{LOCAL_USER}< -j2 distro = >{LOCAL_DISTRO}< +j2 class = >{LOCAL_CLASS}< +j2 arch = >{LOCAL_ARCH}< +j2 os = >{LOCAL_SYSTEM}< +j2 host = >{LOCAL_HOST}< +j2 user = >{LOCAL_USER}< +j2 distro = >{LOCAL_DISTRO}< +j2 distro_family = >{LOCAL_DISTRO_FAMILY}< Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) +Included section for distro_family = \ +{LOCAL_DISTRO_FAMILY} ({LOCAL_DISTRO_FAMILY} again) end of template ''' @@ -115,6 +130,7 @@ def test_template_j2(runner, yadm, tmpdir, processor): local_host="{LOCAL_HOST}" local_user="{LOCAL_USER}" local_distro="{LOCAL_DISTRO}" + local_distro_family="{LOCAL_DISTRO_FAMILY}" template_{processor} "{input_file}" "{output_file}" """ run = runner(command=['bash'], inp=script) diff --git a/yadm b/yadm index 73e6044..be020d7 100755 --- a/yadm +++ b/yadm @@ -210,23 +210,30 @@ function score_file() { score=0 return fi + elif [[ "$label" =~ ^(f|distro_family)$ ]]; then + if [ "$value" = "$local_distro_family" ]; then + score=$((score + 8)) + else + score=0 + return + fi elif [[ "$label" =~ ^(c|class)$ ]]; then if [ "$value" = "$local_class" ]; then - score=$((score + 8)) + score=$((score + 16)) else score=0 return fi elif [[ "$label" =~ ^(h|hostname)$ ]]; then if [ "$value" = "$local_host" ]; then - score=$((score + 16)) + score=$((score + 32)) else score=0 return fi elif [[ "$label" =~ ^(u|user)$ ]]; then if [ "$value" = "$local_user" ]; then - score=$((score + 32)) + score=$((score + 64)) else score=0 return @@ -363,24 +370,25 @@ function template_default() { read -r -d '' awk_pgm << "EOF" # built-in default template processor BEGIN { - blank = "[ ]" - c["class"] = class - c["arch"] = arch - c["os"] = os - c["hostname"] = host - c["user"] = user - c["distro"] = distro - c["source"] = source - ifs = "^{%" blank "*if" - els = "^{%" blank "*else" blank "*%}$" - end = "^{%" blank "*endif" blank "*%}$" - skp = "^{%" blank "*(if|else|endif)" - vld = conditions() - inc_start = "^{%" blank "*include" blank "+\"?" - inc_end = "\"?" blank "*%}$" - inc = inc_start ".+" inc_end - prt = 1 - err = 0 + blank = "[ ]" + c["class"] = class + c["arch"] = arch + c["os"] = os + c["hostname"] = host + c["user"] = user + c["distro"] = distro + c["distro_family"] = distro_family + c["source"] = source + ifs = "^{%" blank "*if" + els = "^{%" blank "*else" blank "*%}$" + end = "^{%" blank "*endif" blank "*%}$" + skp = "^{%" blank "*(if|else|endif)" + vld = conditions() + inc_start = "^{%" blank "*include" blank "+\"?" + inc_end = "\"?" blank "*%}$" + inc = inc_start ".+" inc_end + prt = 1 + err = 0 } END { exit err } { replace_vars() } # variable replacements @@ -437,6 +445,7 @@ EOF -v host="$local_host" \ -v user="$local_user" \ -v distro="$local_distro" \ + -v distro_family="$local_distro_family" \ -v source="$input" \ -v source_dir="$(dirname "$input")" \ "$awk_pgm" \ @@ -456,6 +465,7 @@ function template_j2cli() { YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ YADM_DISTRO="$local_distro" \ + YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_SOURCE="$input" \ "$J2CLI_PROGRAM" "$input" -o "$temp_file" @@ -473,6 +483,7 @@ function template_envtpl() { YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ YADM_DISTRO="$local_distro" \ + YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_SOURCE="$input" \ "$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file" @@ -491,6 +502,7 @@ function template_esh() { YADM_HOSTNAME="$local_host" \ YADM_USER="$local_user" \ YADM_DISTRO="$local_distro" \ + YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_SOURCE="$input" move_file "$input" "$output" "$temp_file" @@ -526,6 +538,7 @@ function alt() { local local_host local local_user local local_distro + local local_distro_family set_local_alt_values # only be noisy if the "alt" command was run directly @@ -644,6 +657,7 @@ function set_local_alt_values() { fi local_distro="$(query_distro)" + local_distro_family="$(query_distro_family)" } @@ -1486,6 +1500,20 @@ function query_distro() { echo "$distro" } +function query_distro_family() { + family="" + if [ -f "$OS_RELEASE" ]; then + while IFS='' read -r line || [ -n "$line" ]; do + if [[ "$line" = ID_LIKE=* ]]; then + family="${line#ID_LIKE=}" + family="${family//\"}" + break + fi + done < "$OS_RELEASE" + fi + echo "$family" +} + function process_global_args() { # global arguments are removed before the main processing is done From 3d3432516f91960d743bc6a02abb397e973e0b2a Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 17 Jan 2022 14:27:52 -0600 Subject: [PATCH 19/32] Distinguish tests of templates --- test/test_unit_template_esh.py | 28 ++++++++++++++-------------- test/test_unit_template_j2.py | 31 +++++++++++++++++-------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/test/test_unit_template_esh.py b/test/test_unit_template_esh.py index d4adc70..f8249a6 100644 --- a/test/test_unit_template_esh.py +++ b/test/test_unit_template_esh.py @@ -23,7 +23,7 @@ esh distro_family = ><%=$YADM_DISTRO_FAMILY%>< wrong class 1 <% fi -%> <% if [ "$YADM_CLASS" = "{LOCAL_CLASS}" ]; then -%> -Included section for class = <%=$YADM_CLASS%> (<%=$YADM_CLASS%> repeated) +Included esh section for class = <%=$YADM_CLASS%> (<%=$YADM_CLASS%> repeated) <% fi -%> <% if [ "$YADM_CLASS" = "wrongclass2" ]; then -%> wrong class 2 @@ -32,7 +32,7 @@ wrong class 2 wrong arch 1 <% fi -%> <% if [ "$YADM_ARCH" = "{LOCAL_ARCH}" ]; then -%> -Included section for arch = <%=$YADM_ARCH%> (<%=$YADM_ARCH%> repeated) +Included esh section for arch = <%=$YADM_ARCH%> (<%=$YADM_ARCH%> repeated) <% fi -%> <% if [ "$YADM_ARCH" = "wrongarch2" ]; then -%> wrong arch 2 @@ -41,7 +41,7 @@ wrong arch 2 wrong os 1 <% fi -%> <% if [ "$YADM_OS" = "{LOCAL_SYSTEM}" ]; then -%> -Included section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated) +Included esh section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated) <% fi -%> <% if [ "$YADM_OS" = "wrongos2" ]; then -%> wrong os 2 @@ -50,7 +50,7 @@ wrong os 2 wrong host 1 <% fi -%> <% if [ "$YADM_HOSTNAME" = "{LOCAL_HOST}" ]; then -%> -Included section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again) +Included esh section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again) <% fi -%> <% if [ "$YADM_HOSTNAME" = "wronghost2" ]; then -%> wrong host 2 @@ -59,7 +59,7 @@ wrong host 2 wrong user 1 <% fi -%> <% if [ "$YADM_USER" = "{LOCAL_USER}" ]; then -%> -Included section for user = <%=$YADM_USER%> (<%=$YADM_USER%> repeated) +Included esh section for user = <%=$YADM_USER%> (<%=$YADM_USER%> repeated) <% fi -%> <% if [ "$YADM_USER" = "wronguser2" ]; then -%> wrong user 2 @@ -68,7 +68,7 @@ wrong user 2 wrong distro 1 <% fi -%> <% if [ "$YADM_DISTRO" = "{LOCAL_DISTRO}" ]; then -%> -Included section for distro = <%=$YADM_DISTRO%> (<%=$YADM_DISTRO%> again) +Included esh section for distro = <%=$YADM_DISTRO%> (<%=$YADM_DISTRO%> again) <% fi -%> <% if [ "$YADM_DISTRO" = "wrongdistro2" ]; then -%> wrong distro 2 @@ -77,7 +77,7 @@ wrong distro 2 wrong family 1 <% fi -%> <% if [ "$YADM_DISTRO_FAMILY" = "{LOCAL_DISTRO_FAMILY}" ]; then -%> -Included section for distro_family = \ +Included esh section for distro_family = \ <%=$YADM_DISTRO_FAMILY%> (<%=$YADM_DISTRO_FAMILY%> again) <% fi -%> <% if [ "$YADM_DISTRO" = "wrongfamily2" ]; then -%> @@ -94,13 +94,13 @@ esh host = >{LOCAL_HOST}< esh user = >{LOCAL_USER}< esh distro = >{LOCAL_DISTRO}< esh distro_family = >{LOCAL_DISTRO_FAMILY}< -Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) -Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) -Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) -Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) -Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) -Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) -Included section for distro_family = \ +Included esh section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included esh section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) +Included esh section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) +Included esh section for host = {LOCAL_HOST} ({LOCAL_HOST} again) +Included esh section for user = {LOCAL_USER} ({LOCAL_USER} repeated) +Included esh section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) +Included esh section for distro_family = \ {LOCAL_DISTRO_FAMILY} ({LOCAL_DISTRO_FAMILY} again) end of template ''' diff --git a/test/test_unit_template_j2.py b/test/test_unit_template_j2.py index 7429f8d..3cfe9df 100644 --- a/test/test_unit_template_j2.py +++ b/test/test_unit_template_j2.py @@ -24,7 +24,8 @@ j2 distro_family = >{{{{YADM_DISTRO_FAMILY}}}}< wrong class 1 {{%- endif %}} {{%- if YADM_CLASS == "{LOCAL_CLASS}" %}} -Included section for class = {{{{YADM_CLASS}}}} ({{{{YADM_CLASS}}}} repeated) +Included j2 section for class = \ +{{{{YADM_CLASS}}}} ({{{{YADM_CLASS}}}} repeated) {{%- endif %}} {{%- if YADM_CLASS == "wrongclass2" %}} wrong class 2 @@ -33,7 +34,7 @@ wrong class 2 wrong arch 1 {{%- endif %}} {{%- if YADM_ARCH == "{LOCAL_ARCH}" %}} -Included section for arch = {{{{YADM_ARCH}}}} ({{{{YADM_ARCH}}}} repeated) +Included j2 section for arch = {{{{YADM_ARCH}}}} ({{{{YADM_ARCH}}}} repeated) {{%- endif %}} {{%- if YADM_ARCH == "wrongarch2" %}} wrong arch 2 @@ -42,7 +43,7 @@ wrong arch 2 wrong os 1 {{%- endif %}} {{%- if YADM_OS == "{LOCAL_SYSTEM}" %}} -Included section for os = {{{{YADM_OS}}}} ({{{{YADM_OS}}}} repeated) +Included j2 section for os = {{{{YADM_OS}}}} ({{{{YADM_OS}}}} repeated) {{%- endif %}} {{%- if YADM_OS == "wrongos2" %}} wrong os 2 @@ -51,7 +52,8 @@ wrong os 2 wrong host 1 {{%- endif %}} {{%- if YADM_HOSTNAME == "{LOCAL_HOST}" %}} -Included section for host = {{{{YADM_HOSTNAME}}}} ({{{{YADM_HOSTNAME}}}} again) +Included j2 section for host = \ +{{{{YADM_HOSTNAME}}}} ({{{{YADM_HOSTNAME}}}} again) {{%- endif %}} {{%- if YADM_HOSTNAME == "wronghost2" %}} wrong host 2 @@ -60,7 +62,7 @@ wrong host 2 wrong user 1 {{%- endif %}} {{%- if YADM_USER == "{LOCAL_USER}" %}} -Included section for user = {{{{YADM_USER}}}} ({{{{YADM_USER}}}} repeated) +Included j2 section for user = {{{{YADM_USER}}}} ({{{{YADM_USER}}}} repeated) {{%- endif %}} {{%- if YADM_USER == "wronguser2" %}} wrong user 2 @@ -69,7 +71,8 @@ wrong user 2 wrong distro 1 {{%- endif %}} {{%- if YADM_DISTRO == "{LOCAL_DISTRO}" %}} -Included section for distro = {{{{YADM_DISTRO}}}} ({{{{YADM_DISTRO}}}} again) +Included j2 section for distro = \ +{{{{YADM_DISTRO}}}} ({{{{YADM_DISTRO}}}} again) {{%- endif %}} {{%- if YADM_DISTRO == "wrongdistro2" %}} wrong distro 2 @@ -78,7 +81,7 @@ wrong distro 2 wrong family 1 {{%- endif %}} {{%- if YADM_DISTRO_FAMILY == "{LOCAL_DISTRO_FAMILY}" %}} -Included section for distro_family = \ +Included j2 section for distro_family = \ {{{{YADM_DISTRO_FAMILY}}}} ({{{{YADM_DISTRO_FAMILY}}}} again) {{%- endif %}} {{%- if YADM_DISTRO_FAMILY == "wrongfamily2" %}} @@ -95,13 +98,13 @@ j2 host = >{LOCAL_HOST}< j2 user = >{LOCAL_USER}< j2 distro = >{LOCAL_DISTRO}< j2 distro_family = >{LOCAL_DISTRO_FAMILY}< -Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) -Included section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) -Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) -Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again) -Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated) -Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) -Included section for distro_family = \ +Included j2 section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) +Included j2 section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) +Included j2 section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated) +Included j2 section for host = {LOCAL_HOST} ({LOCAL_HOST} again) +Included j2 section for user = {LOCAL_USER} ({LOCAL_USER} repeated) +Included j2 section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again) +Included j2 section for distro_family = \ {LOCAL_DISTRO_FAMILY} ({LOCAL_DISTRO_FAMILY} again) end of template ''' From b0e08566588e4811b41086a68260050259aa72f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20K=C3=B6ch?= Date: Mon, 24 Jan 2022 21:49:46 +0000 Subject: [PATCH 20/32] Add test --- test/test_unit_template_default.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index ea2f904..faab58b 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -202,3 +202,22 @@ def test_include(runner, yadm, tmpdir): assert run.err == '' assert output_file.read() == EXPECTED_INCLUDE assert os.stat(output_file).st_mode == os.stat(input_file).st_mode + + +def test_env(runner, yadm, tmpdir): + """Test env""" + + input_file = tmpdir.join('input') + input_file.write('{{env.PWD}}', ensure=True) + input_file.chmod(FILE_MODE) + output_file = tmpdir.join('output') + + script = f""" + YADM_TEST=1 source {yadm} + set_awk + template_default "{input_file}" "{output_file}" + """ + run = runner(command=['bash'], inp=script) + assert run.success + assert run.err == '' + assert output_file.read() == os.environ['PWD'] From 487f030405852edb9d23ee3918aa9d9266830cc1 Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Tue, 25 Jan 2022 12:19:09 -0800 Subject: [PATCH 21/32] Update test/test_unit_template_default.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paulo Köch --- test/test_unit_template_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index faab58b..ab80025 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -220,4 +220,4 @@ def test_env(runner, yadm, tmpdir): run = runner(command=['bash'], inp=script) assert run.success assert run.err == '' - assert output_file.read() == os.environ['PWD'] + assert output_file.read().strip() == os.environ['PWD'] From b7c5294bd94e799a2359ffb938173fb3a5814358 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 10:15:54 -0600 Subject: [PATCH 22/32] Add manpage docs for distro_family (#213) --- yadm.1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yadm.1 b/yadm.1 index 87d0d90..c2e1ef0 100644 --- a/yadm.1 +++ b/yadm.1 @@ -503,6 +503,11 @@ Distro is calculated by running or by inspecting the ID from .BR "/etc/os-release" . .TP +.BR distro_family , " f +Valid if the value matches the distro family. +Distro family is calculated by inspecting the ID_LIKE line from +.BR "/etc/os-release" . +.TP .BR os , " o Valid if the value matches the OS. OS is calculated by running @@ -658,6 +663,7 @@ During processing, the following variables are available in the template: ------------- ------------- -------------------------- yadm.class YADM_CLASS Locally defined yadm class yadm.distro YADM_DISTRO lsb_release -si + yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release yadm.hostname YADM_HOSTNAME uname -n (without domain) yadm.arch YADM_ARCH uname -m yadm.os YADM_OS uname -s From 82bfd5e773e38c200b534ca2e142127075d12f14 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 10:20:54 -0600 Subject: [PATCH 23/32] Fix table formatting --- yadm.1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/yadm.1 b/yadm.1 index c2e1ef0..04acbaf 100644 --- a/yadm.1 +++ b/yadm.1 @@ -659,16 +659,16 @@ to create or overwrite files. During processing, the following variables are available in the template: - Default Jinja or ESH Description - ------------- ------------- -------------------------- - yadm.class YADM_CLASS Locally defined yadm class - yadm.distro YADM_DISTRO lsb_release -si + Default Jinja or ESH Description + ------------- ------------- -------------------------- + yadm.class YADM_CLASS Locally defined yadm class + yadm.distro YADM_DISTRO lsb_release -si yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release - yadm.hostname YADM_HOSTNAME uname -n (without domain) - yadm.arch YADM_ARCH uname -m - yadm.os YADM_OS uname -s - yadm.user YADM_USER id -u -n - yadm.source YADM_SOURCE Template filename + yadm.hostname YADM_HOSTNAME uname -n (without domain) + yadm.arch YADM_ARCH uname -m + yadm.os YADM_OS uname -s + yadm.user YADM_USER id -u -n + yadm.source YADM_SOURCE Template filename .BR NOTE : The OS for "Windows Subsystem for Linux" is reported as "WSL", even From 50bf8716cd1b6f7f527333f76ab8fbff784bf79c Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 11:31:44 -0600 Subject: [PATCH 24/32] Unify template support for classes (#185) --- test/test_unit_template_default.py | 3 +++ test/test_unit_template_esh.py | 2 ++ test/test_unit_template_j2.py | 3 +++ yadm | 1 + 4 files changed, 9 insertions(+) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index debd3ed..729784e 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -21,6 +21,7 @@ default host = >{{{{yadm.hostname}}}}< default user = >{{{{yadm.user}}}}< default distro = >{{{{yadm.distro}}}}< default distro_family = >{{{{yadm.distro_family}}}}< +classes = >{{{{yadm.classes}}}}< {{% if yadm.class == "else1" %}} wrong else 1 {{% else %}} @@ -107,6 +108,8 @@ default host = >{LOCAL_HOST}< default user = >{LOCAL_USER}< default distro = >{LOCAL_DISTRO}< default distro_family = >{LOCAL_DISTRO_FAMILY}< +classes = >{LOCAL_CLASS2} +{LOCAL_CLASS}< Included section from else Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Multiple lines diff --git a/test/test_unit_template_esh.py b/test/test_unit_template_esh.py index 2c0f73a..7f2f2b9 100644 --- a/test/test_unit_template_esh.py +++ b/test/test_unit_template_esh.py @@ -20,6 +20,7 @@ esh host = ><%=$YADM_HOSTNAME%>< esh user = ><%=$YADM_USER%>< esh distro = ><%=$YADM_DISTRO%>< esh distro_family = ><%=$YADM_DISTRO_FAMILY%>< +esh classes = ><%=$YADM_CLASSES%>< <% if [ "$YADM_CLASS" = "wrongclass1" ]; then -%> wrong class 1 <% fi -%> @@ -99,6 +100,7 @@ esh host = >{LOCAL_HOST}< esh user = >{LOCAL_USER}< esh distro = >{LOCAL_DISTRO}< esh distro_family = >{LOCAL_DISTRO_FAMILY}< +esh classes = >{LOCAL_CLASS2} {LOCAL_CLASS}< Included esh section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included esh section for second class Included esh section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) diff --git a/test/test_unit_template_j2.py b/test/test_unit_template_j2.py index 8da0dc0..4042a2d 100644 --- a/test/test_unit_template_j2.py +++ b/test/test_unit_template_j2.py @@ -21,6 +21,7 @@ j2 host = >{{{{YADM_HOSTNAME}}}}< j2 user = >{{{{YADM_USER}}}}< j2 distro = >{{{{YADM_DISTRO}}}}< j2 distro_family = >{{{{YADM_DISTRO_FAMILY}}}}< +j2 classes = >{{{{YADM_CLASSES}}}}< {{%- if YADM_CLASS == "wrongclass1" %}} wrong class 1 {{%- endif %}} @@ -102,6 +103,8 @@ j2 host = >{LOCAL_HOST}< j2 user = >{LOCAL_USER}< j2 distro = >{LOCAL_DISTRO}< j2 distro_family = >{LOCAL_DISTRO_FAMILY}< +j2 classes = >{LOCAL_CLASS2} +{LOCAL_CLASS}< Included j2 section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated) Included j2 section for second class Included j2 section for arch = {LOCAL_ARCH} ({LOCAL_ARCH} repeated) diff --git a/yadm b/yadm index daf0669..22343ed 100755 --- a/yadm +++ b/yadm @@ -372,6 +372,7 @@ function template_default() { BEGIN { blank = "[ ]" c["class"] = class + c["classes"] = classes c["arch"] = arch c["os"] = os c["hostname"] = host From 718e99c826dd00e6dfe4d68a77635c072bf8b228 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 11:36:51 -0600 Subject: [PATCH 25/32] Add manpage documentation for multiple classes --- yadm.1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/yadm.1 b/yadm.1 index 04acbaf..538a1c7 100644 --- a/yadm.1 +++ b/yadm.1 @@ -435,6 +435,11 @@ they are stored in the local repository. .B local.class Specify a class for the purpose of symlinking alternate files. By default, no class will be matched. +The local host can be assigned multiple classes using command: + +.RS +yadm config --add local.class +.RE .TP .B local.arch Override the architecture for the purpose of symlinking alternate files. @@ -660,8 +665,9 @@ to create or overwrite files. During processing, the following variables are available in the template: Default Jinja or ESH Description - ------------- ------------- -------------------------- - yadm.class YADM_CLASS Locally defined yadm class + ------------- ------------- ------------------------------- + yadm.class YADM_CLASS Last locally defined class + yadm.classes YADM_CLASSES All classes yadm.distro YADM_DISTRO lsb_release -si yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release yadm.hostname YADM_HOSTNAME uname -n (without domain) From 3445763731378ccff6d1e1c912e5eab9f3a5b136 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 12:42:45 -0600 Subject: [PATCH 26/32] Add manpage docs about env support in default templates --- yadm.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/yadm.1 b/yadm.1 index 538a1c7..7234244 100644 --- a/yadm.1 +++ b/yadm.1 @@ -675,6 +675,7 @@ During processing, the following variables are available in the template: yadm.os YADM_OS uname -s yadm.user YADM_USER id -u -n yadm.source YADM_SOURCE Template filename + env.VAR Environment variable VAR .BR NOTE : The OS for "Windows Subsystem for Linux" is reported as "WSL", even From 39d0c791ced5a580c4ab09a74957730743822d1a Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 13:18:48 -0600 Subject: [PATCH 27/32] Reorder list --- yadm.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yadm.1 b/yadm.1 index 7234244..d8bcad4 100644 --- a/yadm.1 +++ b/yadm.1 @@ -666,15 +666,15 @@ During processing, the following variables are available in the template: Default Jinja or ESH Description ------------- ------------- ------------------------------- + yadm.arch YADM_ARCH uname -m yadm.class YADM_CLASS Last locally defined class yadm.classes YADM_CLASSES All classes yadm.distro YADM_DISTRO lsb_release -si yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release yadm.hostname YADM_HOSTNAME uname -n (without domain) - yadm.arch YADM_ARCH uname -m yadm.os YADM_OS uname -s - yadm.user YADM_USER id -u -n yadm.source YADM_SOURCE Template filename + yadm.user YADM_USER id -u -n env.VAR Environment variable VAR .BR NOTE : From ebb6715aadd7a82968c6ace8955ffe735a715543 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 14:01:08 -0600 Subject: [PATCH 28/32] Reduce supported labels for architecture --- test/test_alt.py | 2 +- test/test_unit_score_file.py | 2 +- yadm | 2 +- yadm.1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_alt.py b/test/test_alt.py index 6d14f65..ddaf374 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -82,7 +82,7 @@ def test_relative_link(runner, paths, yadm_alt): @pytest.mark.parametrize('suffix', [ '##default', '##default,e.txt', '##default,extension.txt', - '##a.$tst_arch', '##arch.$tst_arch', '##architecture.$tst_arch', + '##a.$tst_arch', '##arch.$tst_arch', '##o.$tst_sys', '##os.$tst_sys', '##d.$tst_distro', '##distro.$tst_distro', '##f.$tst_distro_family', '##distro_family.$tst_distro_family', diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index 539831b..a63246a 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -7,7 +7,7 @@ CONDITION = { 'modifier': 0, }, 'arch': { - 'labels': ['a', 'arch', 'architecture'], + 'labels': ['a', 'arch'], 'modifier': 1, }, 'system': { diff --git a/yadm b/yadm index 22343ed..40fa224 100755 --- a/yadm +++ b/yadm @@ -189,7 +189,7 @@ function score_file() { if [[ "$label" =~ ^(default)$ ]]; then score=$((score + 0)) # variable conditions - elif [[ "$label" =~ ^(a|arch|architecture)$ ]]; then + elif [[ "$label" =~ ^(a|arch)$ ]]; then if [ "$value" = "$local_arch" ]; then score=$((score + 1)) else diff --git a/yadm.1 b/yadm.1 index d8bcad4..94ad229 100644 --- a/yadm.1 +++ b/yadm.1 @@ -518,7 +518,7 @@ Valid if the value matches the OS. OS is calculated by running .BR "uname -s" . .TP -.BR architecture , " arch" , " a +.BR arch , " a Valid if the value matches the architecture. Architecture is calculated by running .BR "uname -m" . From 46f72c2768d685a978599a16ac2c386998da3e4e Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 14:09:57 -0600 Subject: [PATCH 29/32] Add local.arch to config introspection --- test/conftest.py | 1 + yadm | 1 + 2 files changed, 2 insertions(+) diff --git a/test/conftest.py b/test/conftest.py index 95e2fca..d3bbb76 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -126,6 +126,7 @@ def supported_configs(): This list should be updated every time yadm learns a new config. """ return [ + 'local.arch', 'local.class', 'local.hostname', 'local.os', diff --git a/yadm b/yadm index 40fa224..1c5cd55 100755 --- a/yadm +++ b/yadm @@ -1247,6 +1247,7 @@ EOF function introspect_configs() { local msg read -r -d '' msg <<-EOF +local.arch local.class local.hostname local.os From 287249df91b668fd4fba7acf3ffb7b90c06bc418 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Sat, 12 Mar 2022 15:04:47 -0600 Subject: [PATCH 30/32] Clarify requirements for linked directories (#328) --- yadm.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yadm.1 b/yadm.1 index 94ad229..ce82c9a 100644 --- a/yadm.1 +++ b/yadm.1 @@ -595,7 +595,7 @@ If no "##default" version exists and no files have valid conditions, then no link will be created. Links are also created for directories named this way, as long as they have at -least one yadm managed file within them. +least one yadm managed file within them (at the top level). yadm will automatically create these links by default. This can be disabled using the From a4adadcc8cee3c76699f717eb21a930d2c84f8b7 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Feb 2022 14:55:05 -0600 Subject: [PATCH 31/32] Fix table format --- yadm.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yadm.1 b/yadm.1 index ce82c9a..e56d574 100644 --- a/yadm.1 +++ b/yadm.1 @@ -665,7 +665,7 @@ to create or overwrite files. During processing, the following variables are available in the template: Default Jinja or ESH Description - ------------- ------------- ------------------------------- + ------------- ------------- ---------------------------- yadm.arch YADM_ARCH uname -m yadm.class YADM_CLASS Last locally defined class yadm.classes YADM_CLASSES All classes From 82c0b6d02eb8dc3734355c875bdde0b6aea67873 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Wed, 16 Mar 2022 09:26:11 -0500 Subject: [PATCH 32/32] Update version number and update documentation * Support architecture for alternates/templates (#202, #203, #393) * Support distro_family for alternates/templates (#213) * Support setting multiple classes (#185, #304) * Support environment variables in default template processor (#347) * Update version command to include Bash & Git versions (#377) --- CHANGES | 7 ++ CONTRIBUTORS | 7 ++ README.md | 2 +- yadm | 4 +- yadm.1 | 2 +- yadm.md | 235 ++++++++++++++++++++++++++++----------------------- yadm.spec | 2 +- 7 files changed, 146 insertions(+), 113 deletions(-) diff --git a/CHANGES b/CHANGES index 240b1ee..4f5590f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +3.2.0 + * Support architecture for alternates/templates (#202, #203, #393) + * Support distro_family for alternates/templates (#213) + * Support setting multiple classes (#185, #304) + * Support environment variables in default template processor (#347) + * Update version command to include Bash & Git versions (#377) + 3.1.1 * Fix clone support for older versions of Git (#348) * Fix support for multiple GPG recipients (#342) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7732572..2fc77ea 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -11,11 +11,14 @@ Tin Lai Espen Henriksen Cameron Eagans Klas Mellbourn +James Clark Tomas Cernaj jonasc Chad Wade Day, Jr Sébastien Gross David Mandelberg +Paulo Köch +Oren Zipori Daniel Gray Paraplegic Racehorse japm48 @@ -23,16 +26,20 @@ Siôn Le Roux Mateusz Piotrowski Uroš Golja Satoshi Ohki +Nicolas stig124 FORMICHELLA +Jonas Franciszek Madej Daniel Wagenknecht Stig Palmquist Patrick Hof con-f-use +Samisafool Bram Ceulemans Travis A. Everett Sheng Yang Jared Smartt Adam Jimerson +dessert1 addshore Tim Condit Thomas Luzat diff --git a/README.md b/README.md index 410d270..8037946 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The star count helps others discover yadm. [master-badge]: https://img.shields.io/github/workflow/status/TheLocehiliosan/yadm/Tests/master?label=master [master-commits]: https://github.com/TheLocehiliosan/yadm/commits/master [master-date]: https://img.shields.io/github/last-commit/TheLocehiliosan/yadm/master.svg?label=master -[obs-badge]: https://img.shields.io/badge/OBS-v3.1.1-blue +[obs-badge]: https://img.shields.io/badge/OBS-v3.2.0-blue [obs-link]: https://software.opensuse.org//download.html?project=home%3ATheLocehiliosan%3Ayadm&package=yadm [releases-badge]: https://img.shields.io/github/tag/TheLocehiliosan/yadm.svg?label=latest+release [releases-link]: https://github.com/TheLocehiliosan/yadm/releases diff --git a/yadm b/yadm index 1c5cd55..ec59d0e 100755 --- a/yadm +++ b/yadm @@ -1,6 +1,6 @@ #!/bin/sh # yadm - Yet Another Dotfiles Manager -# Copyright (C) 2015-2021 Tim Byrne +# Copyright (C) 2015-2022 Tim Byrne # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ if [ -z "$BASH_VERSION" ]; then [ "$YADM_TEST" != 1 ] && exec bash "$0" "$@" fi -VERSION=3.1.1 +VERSION=3.2.0 YADM_WORK="$HOME" YADM_DIR= diff --git a/yadm.1 b/yadm.1 index e56d574..908e93e 100644 --- a/yadm.1 +++ b/yadm.1 @@ -1,5 +1,5 @@ .\" vim: set spell so=8: -.TH yadm 1 "23 August 2021" "3.1.1" +.TH yadm 1 "16 March 2022" "3.2.0" .SH NAME diff --git a/yadm.md b/yadm.md index 6b2257a..73890d8 100644 --- a/yadm.md +++ b/yadm.md @@ -331,13 +331,20 @@ Disable the permission changes to $HOME/.ssh/*. This feature is enabled by default. - The following four "local" configurations are not stored in the + The following five "local" configurations are not stored in the $HOME/.config/yadm/config, they are stored in the local repository. local.class Specify a class for the purpose of symlinking alternate files. - By default, no class will be matched. + By default, no class will be matched. The local host can be + assigned multiple classes using command: + + yadm config --add local.class + + local.arch + Override the architecture for the purpose of symlinking alter- + nate files. local.hostname Override the hostname for the purpose of symlinking alternate @@ -384,13 +391,9 @@ Valid if the value matches the current user. Current user is calculated by running id -u -n. - distro, d - Valid if the value matches the distro. Distro is calculated by - running lsb_release -si or by inspecting the ID from /etc/os- - release. - - os, o Valid if the value matches the OS. OS is calculated by running - uname -s. + hostname, h + Valid if the value matches the short hostname. Hostname is cal- + culated by running uname -n, and trimming off any domain. class, c Valid if the value matches the local.class configuration. Class @@ -398,9 +401,21 @@ the CONFIGURATION section for more details about setting local.class. - hostname, h - Valid if the value matches the short hostname. Hostname is cal- - culated by running uname -n, and trimming off any domain. + distro, d + Valid if the value matches the distro. Distro is calculated by + running lsb_release -si or by inspecting the ID from /etc/os- + release. + + distro_family, f + Valid if the value matches the distro family. Distro family is + calculated by inspecting the ID_LIKE line from /etc/os-release. + + os, o Valid if the value matches the OS. OS is calculated by running + uname -s. + + arch, a + Valid if the value matches the architecture. Architecture is + calculated by running uname -m. default Valid when no other alternate is valid. @@ -408,31 +423,31 @@ extension, e A special "condition" that doesn't affect the selection process. Its purpose is instead to allow the alternate file to end with a - certain extension to e.g. make editors highlight the content + certain extension to e.g. make editors highlight the content properly. - NOTE: The OS for "Windows Subsystem for Linux" is reported as "WSL", + NOTE: The OS for "Windows Subsystem for Linux" is reported as "WSL", even though uname identifies as "Linux". - You may use any number of conditions, in any order. An alternate will - only be used if ALL conditions are valid. For all files managed by - yadm's repository or listed in $HOME/.config/yadm/encrypt, if they - match this naming convention, symbolic links will be created for the + You may use any number of conditions, in any order. An alternate will + only be used if ALL conditions are valid. For all files managed by + yadm's repository or listed in $HOME/.config/yadm/encrypt, if they + match this naming convention, symbolic links will be created for the most appropriate version. The "most appropriate" version is determined by calculating a score for - each version of a file. A template is always scored higher than any - symlink condition. The number of conditions is the next largest factor - in scoring. Files with more conditions will always be favored. Any + each version of a file. A template is always scored higher than any + symlink condition. The number of conditions is the next largest factor + in scoring. Files with more conditions will always be favored. Any invalid condition will disqualify that file completely. If you don't care to have all versions of alternates stored in the same directory as the generated symlink, you can place them in the - $HOME/.config/yadm/alt directory. The generated symlink or processed + $HOME/.config/yadm/alt directory. The generated symlink or processed template will be created using the same relative path. - Alternate linking may best be demonstrated by example. Assume the fol- + Alternate linking may best be demonstrated by example. Assume the fol- lowing files are managed by yadm's repository: - $HOME/path/example.txt##default @@ -450,12 +465,12 @@ $HOME/path/example.txt -> $HOME/path/example.txt##os.Darwin,host- name.host2 - However, on another Macbook named "host3", yadm will create a symbolic + However, on another Mackbook named "host3", yadm will create a symbolic link which looks like this: $HOME/path/example.txt -> $HOME/path/example.txt##os.Darwin - Since the hostname doesn't match any of the managed files, the more + Since the hostname doesn't match any of the managed files, the more generic version is chosen. If running on a Linux server named "host4", the link will be: @@ -470,81 +485,85 @@ $HOME/path/example.txt -> $HOME/path/example.txt##class.Work - If no "##default" version exists and no files have valid conditions, + If no "##default" version exists and no files have valid conditions, then no link will be created. - Links are also created for directories named this way, as long as they - have at least one yadm managed file within them. + Links are also created for directories named this way, as long as they + have at least one yadm managed file within them (at the top level). yadm will automatically create these links by default. This can be dis- - abled using the yadm.auto-alt configuration. Even if disabled, links + abled using the yadm.auto-alt configuration. Even if disabled, links can be manually created by running yadm alt. - Class is a special value which is stored locally on each host (inside - the local repository). To use alternate symlinks using class, you must - set the value of class using the configuration local.class. This is + Class is a special value which is stored locally on each host (inside + the local repository). To use alternate symlinks using class, you must + set the value of class using the configuration local.class. This is set like any other yadm configuration with the yadm config command. The following sets the class to be "Work". yadm config local.class Work - Similarly, the values of os, hostname, and user can be manually over- - ridden using the configuration options local.os, local.hostname, and - local.user. + Similarly, the values of architecture, os, hostname, and user can be + manually overridden using the configuration options local.arch, + local.os, local.hostname, and local.user. ## TEMPLATES - If a template condition is defined in an alternate file's "##" suffix, + If a template condition is defined in an alternate file's "##" suffix, and the necessary dependencies for the template are available, then the file will be processed to create or overwrite files. Supported template processors: default - This is yadm's built-in template processor. This processor is + This is yadm's built-in template processor. This processor is very basic, with a Jinja-like syntax. The advantage of this pro- - cessor is that it only depends upon awk, which is available on - most *nix systems. To use this processor, specify the value of + cessor is that it only depends upon awk, which is available on + most *nix systems. To use this processor, specify the value of "default" or just leave the value off (e.g. "##template"). ESH ESH is a template processor written in POSIX compliant shell. It - allows executing shell commands within templates. This can be - used to reference your own configurations within templates, for + allows executing shell commands within templates. This can be + used to reference your own configurations within templates, for example: <% yadm config mysection.myconfig %> To use the ESH template processor, specify the value of "esh" - j2cli To use the j2cli Jinja template processor, specify the value of + j2cli To use the j2cli Jinja template processor, specify the value of "j2" or "j2cli". envtpl To use the envtpl Jinja template processor, specify the value of "j2" or "envtpl". - NOTE: Specifying "j2" as the processor will attempt to use j2cli or + NOTE: Specifying "j2" as the processor will attempt to use j2cli or envtpl, whichever is available. - If the template processor specified is available, templates will be + If the template processor specified is available, templates will be processed to create or overwrite files. - During processing, the following variables are available in the tem- + During processing, the following variables are available in the tem- plate: - Default Jinja or ESH Description - ------------- ------------- -------------------------- - yadm.class YADM_CLASS Locally defined yadm class - yadm.distro YADM_DISTRO lsb_release -si - yadm.hostname YADM_HOSTNAME uname -n (without domain) - yadm.os YADM_OS uname -s - yadm.user YADM_USER id -u -n - yadm.source YADM_SOURCE Template filename + Default Jinja or ESH Description + ------------- ------------- ---------------------------- + yadm.arch YADM_ARCH uname -m + yadm.class YADM_CLASS Last locally defined class + yadm.classes YADM_CLASSES All classes + yadm.distro YADM_DISTRO lsb_release -si + yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release + yadm.hostname YADM_HOSTNAME uname -n (without domain) + yadm.os YADM_OS uname -s + yadm.source YADM_SOURCE Template filename + yadm.user YADM_USER id -u -n + env.VAR Environment variable VAR - NOTE: The OS for "Windows Subsystem for Linux" is reported as "WSL", + NOTE: The OS for "Windows Subsystem for Linux" is reported as "WSL", even though uname identifies as "Linux". - NOTE: If lsb_release is not available, DISTRO will be the ID specified + NOTE: If lsb_release is not available, DISTRO will be the ID specified in /etc/os-release. Examples: @@ -558,7 +577,7 @@ {% include "whatever.extra" %} {% endif %} - would output a file named whatever with the following content if the + would output a file named whatever with the following content if the user is "harvey": config=work-Linux @@ -568,7 +587,7 @@ config=dev-whatever admin=false - An equivalent Jinja template named whatever##template.j2 would look + An equivalent Jinja template named whatever##template.j2 would look like: {% if YADM_USER == 'harvey' -%} @@ -578,7 +597,7 @@ {% include 'whatever.extra' %} {% endif -%} - An equivalent ESH templated named whatever##template.esh would look + An equivalent ESH templated named whatever##template.esh would look like: <% if [ "$YADM_USER" = "harvey" ]; then -%> @@ -590,56 +609,56 @@ ## ENCRYPTION - It can be useful to manage confidential files, like SSH or GPG keys, - across multiple systems. However, doing so would put plain text data + It can be useful to manage confidential files, like SSH or GPG keys, + across multiple systems. However, doing so would put plain text data into a Git repository, which often resides on a public system. yadm can - make it easy to encrypt and decrypt a set of files so the encrypted - version can be maintained in the Git repository. This feature will + make it easy to encrypt and decrypt a set of files so the encrypted + version can be maintained in the Git repository. This feature will only work if a supported tool is available. Both gpg(1) and openssl(1) - are supported. gpg is used by default, but openssl can be configured + are supported. gpg is used by default, but openssl can be configured with the yadm.cypher configuration. - To use this feature, a list of patterns must be created and saved as - $HOME/.config/yadm/encrypt. This list of patterns should be relative + To use this feature, a list of patterns must be created and saved as + $HOME/.config/yadm/encrypt. This list of patterns should be relative to the configured work-tree (usually $HOME). For example: .ssh/*.key .gnupg/*.gpg Standard filename expansions (*, ?, [) are supported. If you have Bash - version 4, you may use "**" to match all subdirectories. Other shell + version 4, you may use "**" to match all subdirectories. Other shell expansions like brace and tilde are not supported. Spaces in paths are - supported, and should not be quoted. If a directory is specified, its + supported, and should not be quoted. If a directory is specified, its contents will be included, but not recursively. Paths beginning with a "!" will be excluded. The yadm encrypt command will find all files matching the patterns, and - prompt for a password. Once a password has confirmed, the matching - files will be encrypted and saved as $HOME/.local/share/yadm/archive. - The "encrypt" and "archive" files should be added to the yadm reposi- + prompt for a password. Once a password has confirmed, the matching + files will be encrypted and saved as $HOME/.local/share/yadm/archive. + The "encrypt" and "archive" files should be added to the yadm reposi- tory so they are available across multiple systems. To decrypt these files later, or on another system run yadm decrypt and - provide the correct password. After files are decrypted, permissions + provide the correct password. After files are decrypted, permissions are automatically updated as described in the PERMISSIONS section. - Symmetric encryption is used by default, but asymmetric encryption may + Symmetric encryption is used by default, but asymmetric encryption may be enabled using the yadm.gpg-recipient configuration. - NOTE: It is recommended that you use a private repository when keeping + NOTE: It is recommended that you use a private repository when keeping confidential files, even though they are encrypted. Patterns found in $HOME/.config/yadm/encrypt are automatically added to - the repository's info/exclude file every time yadm encrypt is run. + the repository's info/exclude file every time yadm encrypt is run. This is to prevent accidentally committing sensitive data to the repos- itory. This can be disabled using the yadm.auto-exclude configuration. Using transcrypt or git-crypt - A completely separate option for encrypting data is to install and use - transcrypt or git-crypt. Once installed, you can use these tools by - running yadm transcrypt or yadm git-crypt. These tools enables trans- - parent encryption and decryption of files in a git repository. See the + A completely separate option for encrypting data is to install and use + transcrypt or git-crypt. Once installed, you can use these tools by + running yadm transcrypt or yadm git-crypt. These tools enables trans- + parent encryption and decryption of files in a git repository. See the following web sites for more information: - https://github.com/elasticdog/transcrypt @@ -649,9 +668,9 @@ ## PERMISSIONS - When files are checked out of a Git repository, their initial permis- - sions are dependent upon the user's umask. Because of this, yadm will - automatically update the permissions of some file paths. The "group" + When files are checked out of a Git repository, their initial permis- + sions are dependent upon the user's umask. Because of this, yadm will + automatically update the permissions of some file paths. The "group" and "others" permissions will be removed from the following files: - $HOME/.local/share/yadm/archive @@ -663,39 +682,39 @@ - The GPG directory and files, .gnupg/* yadm will automatically update permissions by default. This can be dis- - abled using the yadm.auto-perms configuration. Even if disabled, per- - missions can be manually updated by running yadm perms. The .ssh - directory processing can be disabled using the yadm.ssh-perms configu- - ration. The .gnupg directory processing can be disabled using the + abled using the yadm.auto-perms configuration. Even if disabled, per- + missions can be manually updated by running yadm perms. The .ssh + directory processing can be disabled using the yadm.ssh-perms configu- + ration. The .gnupg directory processing can be disabled using the yadm.gpg-perms configuration. - When cloning a repo which includes data in a .ssh or .gnupg directory, - if those directories do not exist at the time of cloning, yadm will + When cloning a repo which includes data in a .ssh or .gnupg directory, + if those directories do not exist at the time of cloning, yadm will create the directories with mask 0700 prior to merging the fetched data into the work-tree. When running a Git command and .ssh or .gnupg directories do not exist, - yadm will create those directories with mask 0700 prior to running the + yadm will create those directories with mask 0700 prior to running the Git command. This can be disabled using the yadm.auto-private-dirs con- figuration. ## HOOKS - For every command yadm supports, a program can be provided to run - before or after that command. These are referred to as "hooks". yadm - looks for hooks in the directory $HOME/.config/yadm/hooks. Each hook + For every command yadm supports, a program can be provided to run + before or after that command. These are referred to as "hooks". yadm + looks for hooks in the directory $HOME/.config/yadm/hooks. Each hook is named using a prefix of pre_ or post_, followed by the command which - should trigger the hook. For example, to create a hook which is run - after every yadm pull command, create a hook named post_pull. Hooks + should trigger the hook. For example, to create a hook which is run + after every yadm pull command, create a hook named post_pull. Hooks must have the executable file permission set. If a pre_ hook is defined, and the hook terminates with a non-zero exit - status, yadm will refuse to run the yadm command. For example, if a - pre_commit hook is defined, but that command ends with a non-zero exit - status, the yadm commit will never be run. This allows one to "short- + status, yadm will refuse to run the yadm command. For example, if a + pre_commit hook is defined, but that command ends with a non-zero exit + status, the yadm commit will never be run. This allows one to "short- circuit" any operation using a pre_ hook. - Hooks have the following environment variables available to them at + Hooks have the following environment variables available to them at runtime: YADM_HOOK_COMMAND @@ -717,19 +736,19 @@ ## FILES - All of yadm's configurations are relative to the "yadm directory". - yadm uses the "XDG Base Directory Specification" to determine this - directory. If the environment variable $XDG_CONFIG_HOME is defined as - a fully qualified path, this directory will be $XDG_CONFIG_HOME/yadm. + All of yadm's configurations are relative to the "yadm directory". + yadm uses the "XDG Base Directory Specification" to determine this + directory. If the environment variable $XDG_CONFIG_HOME is defined as + a fully qualified path, this directory will be $XDG_CONFIG_HOME/yadm. Otherwise it will be $HOME/.config/yadm. Similarly, yadm's data files are relative to the "yadm data directory". - yadm uses the "XDG Base Directory Specification" to determine this - directory. If the environment variable $XDG_DATA_HOME is defined as a + yadm uses the "XDG Base Directory Specification" to determine this + directory. If the environment variable $XDG_DATA_HOME is defined as a fully qualified path, this directory will be $XDG_DATA_HOME/yadm. Oth- erwise it will be $HOME/.local/share/yadm. - The following are the default paths yadm uses for its own data. Most + The following are the default paths yadm uses for its own data. Most of these paths can be altered using universal options. See the OPTIONS section for details. @@ -738,16 +757,16 @@ tive to this directory. $HOME/.local/share/yadm - The yadm data directory. By default, all data yadm stores is + The yadm data directory. By default, all data yadm stores is relative to this directory. $YADM_DIR/config Configuration file for yadm. $YADM_DIR/alt - This is a directory to keep "alternate files" without having - them side-by-side with the resulting symlink or processed tem- - plate. Alternate files placed in this directory will be created + This is a directory to keep "alternate files" without having + them side-by-side with the resulting symlink or processed tem- + plate. Alternate files placed in this directory will be created relative to $HOME instead. $YADM_DATA/repo.git diff --git a/yadm.spec b/yadm.spec index 3df88b6..a5e9322 100644 --- a/yadm.spec +++ b/yadm.spec @@ -1,7 +1,7 @@ %{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}} Name: yadm Summary: Yet Another Dotfiles Manager -Version: 3.1.1 +Version: 3.2.0 Group: Development/Tools Release: 1%{?dist} URL: https://yadm.io