From 0734288483700e8e10cebd87c797b625aa83d55e Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Sun, 21 Feb 2021 19:59:57 +0000 Subject: [PATCH 1/7] First draft of __apt_pin --- cdist/conf/type/__apt_pin/man.rst | 53 ++++++++++++++++ cdist/conf/type/__apt_pin/manifest | 63 +++++++++++++++++++ .../type/__apt_pin/parameter/default/package | 1 + .../type/__apt_pin/parameter/default/state | 1 + cdist/conf/type/__apt_pin/parameter/optional | 2 + cdist/conf/type/__apt_pin/parameter/required | 2 + 6 files changed, 122 insertions(+) create mode 100644 cdist/conf/type/__apt_pin/man.rst create mode 100755 cdist/conf/type/__apt_pin/manifest create mode 100644 cdist/conf/type/__apt_pin/parameter/default/package create mode 100644 cdist/conf/type/__apt_pin/parameter/default/state create mode 100644 cdist/conf/type/__apt_pin/parameter/optional create mode 100644 cdist/conf/type/__apt_pin/parameter/required diff --git a/cdist/conf/type/__apt_pin/man.rst b/cdist/conf/type/__apt_pin/man.rst new file mode 100644 index 00000000..7fcae6f8 --- /dev/null +++ b/cdist/conf/type/__apt_pin/man.rst @@ -0,0 +1,53 @@ +cdist-type__apt_pin(7) +====================== + +NAME +---- +cdist-type__apt_pin - TODO + + +DESCRIPTION +----------- +This space intentionally left blank. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +BOOLEAN PARAMETERS +------------------ +None. + + +EXAMPLES +-------- + +.. code-block:: sh + + # TODO + __apt_pin + + +SEE ALSO +-------- +:strong:`TODO`\ (7) + + +AUTHORS +------- +Daniel Fancsali + + +COPYING +------- +Copyright \(C) 2021 Daniel Fancsali. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__apt_pin/manifest b/cdist/conf/type/__apt_pin/manifest new file mode 100755 index 00000000..8dd9770d --- /dev/null +++ b/cdist/conf/type/__apt_pin/manifest @@ -0,0 +1,63 @@ +#!/bin/sh -e +# +# 2021 Daniel Fancsali (fancsali@gmail.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "$__global/explorer/os") +state="$(cat "$__object/parameter/state")" +package="$(cat "$__object/parameter/package")" +distribution="$(cat "$__object/parameter/distribution")" +priority="$(cat "$__object/parameter/priority")" + + +case "$os" in + debian|ubuntu|devuan) + ;; + *) + printf "This type is specific to Debian and it's derivatives" >&2 + printf "If you feel there's an equivalent functionality in %s, please contribute..." "$os" >&2 + exit 1 + ;; +esac + +if [ "$package" = "*" ]; then + name="default" + +else + name="$__object_id" +fi + +case $distribution in + stabletesting|unsatbel|experimental) + pin="release a=$distribution" + ;; + *) + pin="release n=$distribution" + ;; +esac + + +__file /etc/apt/preferences.d/$name \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source - << EOF +Package: $package +Pin: $pin +Pin-Priority: $priority +EOF diff --git a/cdist/conf/type/__apt_pin/parameter/default/package b/cdist/conf/type/__apt_pin/parameter/default/package new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/cdist/conf/type/__apt_pin/parameter/default/package @@ -0,0 +1 @@ +* diff --git a/cdist/conf/type/__apt_pin/parameter/default/state b/cdist/conf/type/__apt_pin/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__apt_pin/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__apt_pin/parameter/optional b/cdist/conf/type/__apt_pin/parameter/optional new file mode 100644 index 00000000..52f01fd2 --- /dev/null +++ b/cdist/conf/type/__apt_pin/parameter/optional @@ -0,0 +1,2 @@ +state +package diff --git a/cdist/conf/type/__apt_pin/parameter/required b/cdist/conf/type/__apt_pin/parameter/required new file mode 100644 index 00000000..4b4e9741 --- /dev/null +++ b/cdist/conf/type/__apt_pin/parameter/required @@ -0,0 +1,2 @@ +distribution +priority From 1a74470c4d9b30e41a72fbfc084dc54ea44e643b Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Tue, 23 Feb 2021 09:37:36 +0000 Subject: [PATCH 2/7] __apt_pin: Always use $__object_id as preferences.d filename --- cdist/conf/type/__apt_pin/manifest | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cdist/conf/type/__apt_pin/manifest b/cdist/conf/type/__apt_pin/manifest index 8dd9770d..162b523f 100755 --- a/cdist/conf/type/__apt_pin/manifest +++ b/cdist/conf/type/__apt_pin/manifest @@ -36,12 +36,7 @@ case "$os" in ;; esac -if [ "$package" = "*" ]; then - name="default" - -else - name="$__object_id" -fi +name="$__object_id" case $distribution in stabletesting|unsatbel|experimental) From dc66efa690e15ff32d6836e23baa1cbec5eee1ed Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Tue, 23 Feb 2021 11:59:09 +0000 Subject: [PATCH 3/7] Fix shellcheck issues --- cdist/conf/type/__apt_pin/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_pin/manifest b/cdist/conf/type/__apt_pin/manifest index 162b523f..b1372ad0 100755 --- a/cdist/conf/type/__apt_pin/manifest +++ b/cdist/conf/type/__apt_pin/manifest @@ -48,7 +48,7 @@ case $distribution in esac -__file /etc/apt/preferences.d/$name \ +__file "/etc/apt/preferences.d/$name" \ --owner root --group root --mode 0644 \ --state "$state" \ --source - << EOF From a3102022e18a23ce9b54eeaf7415b55361f80bd1 Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Fri, 11 Jun 2021 15:05:17 +0100 Subject: [PATCH 4/7] More sensible defaults; reword debian-only error message --- cdist/conf/type/__apt_pin/manifest | 13 +++++++++---- cdist/conf/type/__apt_pin/nonparallel | 0 cdist/conf/type/__apt_pin/parameter/default/package | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 cdist/conf/type/__apt_pin/nonparallel delete mode 100644 cdist/conf/type/__apt_pin/parameter/default/package diff --git a/cdist/conf/type/__apt_pin/manifest b/cdist/conf/type/__apt_pin/manifest index b1372ad0..909bc80d 100755 --- a/cdist/conf/type/__apt_pin/manifest +++ b/cdist/conf/type/__apt_pin/manifest @@ -19,9 +19,17 @@ # +name="$__object_id" + os=$(cat "$__global/explorer/os") state="$(cat "$__object/parameter/state")" -package="$(cat "$__object/parameter/package")" + +if [ -f "$__object/parameter/package" ]; then + package="$(cat "$__object/parameter/package")" +else + package=$name +fi + distribution="$(cat "$__object/parameter/distribution")" priority="$(cat "$__object/parameter/priority")" @@ -31,13 +39,10 @@ case "$os" in ;; *) printf "This type is specific to Debian and it's derivatives" >&2 - printf "If you feel there's an equivalent functionality in %s, please contribute..." "$os" >&2 exit 1 ;; esac -name="$__object_id" - case $distribution in stabletesting|unsatbel|experimental) pin="release a=$distribution" diff --git a/cdist/conf/type/__apt_pin/nonparallel b/cdist/conf/type/__apt_pin/nonparallel new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__apt_pin/parameter/default/package b/cdist/conf/type/__apt_pin/parameter/default/package deleted file mode 100644 index 72e8ffc0..00000000 --- a/cdist/conf/type/__apt_pin/parameter/default/package +++ /dev/null @@ -1 +0,0 @@ -* From b726697e070e5266eae38c7951ced14a2305acb2 Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Fri, 11 Jun 2021 15:05:33 +0100 Subject: [PATCH 5/7] Add documentation --- cdist/conf/type/__apt_pin/man.rst | 37 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__apt_pin/man.rst b/cdist/conf/type/__apt_pin/man.rst index 7fcae6f8..0c91cdec 100644 --- a/cdist/conf/type/__apt_pin/man.rst +++ b/cdist/conf/type/__apt_pin/man.rst @@ -13,11 +13,21 @@ This space intentionally left blank. REQUIRED PARAMETERS ------------------- -None. +distribution + Specifies what distribution the package should be pinned to. Accepts both codenames (buster/bullseye/sid) and suite names (stable/testing/...). OPTIONAL PARAMETERS ------------------- +package + Package name or glob/RE expression to match multiple packages. If not specified `__object_id` is used. + +priority + The priority value to assign to matching packages. Deafults to 500. (To match the default target distro's priority) + +state + Will be passed to underlying `__file` type; see there for valid values and defaults. + None. @@ -31,14 +41,31 @@ EXAMPLES .. code-block:: sh - # TODO - __apt_pin + # Add the bullseye repo to buster, but do not install any pacakges by default + # only if explicitely asked for + __apt_pin bullseye-default \ + --package "*" \ + --distribution bullseye \ + --priority -1 + + require="__apt_pin/bullseye-default" __apt_source bullseye \ + --uri http://deb.debian.org/debian/ \ + --distribution bullseye \ + --component main + # TODO + __apt_pin + + __apt_pin foo --package "foo foo-*" --distribution bullseye + + __foo # Installs the `foo` package internally + + __package foo-plugin-extras SEE ALSO -------- -:strong:`TODO`\ (7) - +:strong:`apt_preferences`\ (7) +:strong:`cdist-type__file`\ (7) AUTHORS ------- From 521241d74102e37fae5f55552e1ef565d26ea9d2 Mon Sep 17 00:00:00 2001 From: fancsali Date: Mon, 5 Jul 2021 15:28:05 +0200 Subject: [PATCH 6/7] Refine docs even more --- cdist/conf/type/__apt_pin/man.rst | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cdist/conf/type/__apt_pin/man.rst b/cdist/conf/type/__apt_pin/man.rst index 0c91cdec..4229c0cd 100644 --- a/cdist/conf/type/__apt_pin/man.rst +++ b/cdist/conf/type/__apt_pin/man.rst @@ -3,12 +3,12 @@ cdist-type__apt_pin(7) NAME ---- -cdist-type__apt_pin - TODO +cdist-type__apt_pin - Manage apt pinning rules DESCRIPTION ----------- -This space intentionally left blank. +Adds/removes/edits rules to pin some packages to a specific distribution. Useful if using multiple debian repositories at the same time. (Useful, if one wants to use a few specific packages from backports or perhaps Debain testing... or even sid.) REQUIRED PARAMETERS @@ -20,7 +20,7 @@ distribution OPTIONAL PARAMETERS ------------------- package - Package name or glob/RE expression to match multiple packages. If not specified `__object_id` is used. + Package name, glob or regular expression to match (multiple) packages. If not specified `__object_id` is used. priority The priority value to assign to matching packages. Deafults to 500. (To match the default target distro's priority) @@ -28,7 +28,6 @@ priority state Will be passed to underlying `__file` type; see there for valid values and defaults. -None. BOOLEAN PARAMETERS @@ -41,8 +40,8 @@ EXAMPLES .. code-block:: sh - # Add the bullseye repo to buster, but do not install any pacakges by default - # only if explicitely asked for + # Add the bullseye repo to buster, but do not install any packages by default, + # only if explicitely asked for (-1 means "never" for apt) __apt_pin bullseye-default \ --package "*" \ --distribution bullseye \ @@ -52,19 +51,19 @@ EXAMPLES --uri http://deb.debian.org/debian/ \ --distribution bullseye \ --component main - # TODO - __apt_pin __apt_pin foo --package "foo foo-*" --distribution bullseye - __foo # Installs the `foo` package internally + __foo # Assuming, this installs the `foo` package internally - __package foo-plugin-extras + __package foo-plugin-extras # Assuming we also need some extra stuff SEE ALSO -------- -:strong:`apt_preferences`\ (7) +:strong:`apt_preferences`\ (5) +:strong:`cdist-type__apt_source`\ (7) +:strong:`cdist-type__apt_backports`\ (7) :strong:`cdist-type__file`\ (7) AUTHORS From 166b58aeea09da41086525849291c70a3c3a571c Mon Sep 17 00:00:00 2001 From: fancsali Date: Mon, 5 Jul 2021 15:32:27 +0200 Subject: [PATCH 7/7] Fix typo in distro names... --- cdist/conf/type/__apt_pin/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_pin/manifest b/cdist/conf/type/__apt_pin/manifest index 909bc80d..e72a8fdd 100755 --- a/cdist/conf/type/__apt_pin/manifest +++ b/cdist/conf/type/__apt_pin/manifest @@ -44,7 +44,7 @@ case "$os" in esac case $distribution in - stabletesting|unsatbel|experimental) + stable|testing|unstable|experimental) pin="release a=$distribution" ;; *)