Merge branch 'master' into beta
commit
ed6d26245b
@ -0,0 +1,79 @@
|
||||
cdist-type__apt_pin(7)
|
||||
======================
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__apt_pin - Manage apt pinning rules
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
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
|
||||
-------------------
|
||||
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, 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)
|
||||
|
||||
state
|
||||
Will be passed to underlying `__file` type; see there for valid values and defaults.
|
||||
|
||||
|
||||
|
||||
BOOLEAN PARAMETERS
|
||||
------------------
|
||||
None.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
# 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 \
|
||||
--priority -1
|
||||
|
||||
require="__apt_pin/bullseye-default" __apt_source bullseye \
|
||||
--uri http://deb.debian.org/debian/ \
|
||||
--distribution bullseye \
|
||||
--component main
|
||||
|
||||
__apt_pin foo --package "foo foo-*" --distribution bullseye
|
||||
|
||||
__foo # Assuming, this installs the `foo` package internally
|
||||
|
||||
__package foo-plugin-extras # Assuming we also need some extra stuff
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
:strong:`apt_preferences`\ (5)
|
||||
:strong:`cdist-type__apt_source`\ (7)
|
||||
:strong:`cdist-type__apt_backports`\ (7)
|
||||
:strong:`cdist-type__file`\ (7)
|
||||
|
||||
AUTHORS
|
||||
-------
|
||||
Daniel Fancsali <fancsali@gmail.com>
|
||||
|
||||
|
||||
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.
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
name="$__object_id"
|
||||
|
||||
os=$(cat "$__global/explorer/os")
|
||||
state="$(cat "$__object/parameter/state")"
|
||||
|
||||
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")"
|
||||
|
||||
|
||||
case "$os" in
|
||||
debian|ubuntu|devuan)
|
||||
;;
|
||||
*)
|
||||
printf "This type is specific to Debian and it's derivatives" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case $distribution in
|
||||
stable|testing|unstable|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
|
@ -0,0 +1 @@
|
||||
present
|
@ -0,0 +1,2 @@
|
||||
state
|
||||
package
|
@ -0,0 +1,2 @@
|
||||
distribution
|
||||
priority
|
@ -1,41 +1,104 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# 2015 Dominique Roux (dominique.roux4 at 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
source=$(cat "$__object/parameter/source")
|
||||
remote_user=$(cat "$__object/parameter/remote-user")
|
||||
if ! command -v rsync > /dev/null
|
||||
then
|
||||
echo 'rsync is missing in local machine' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
src="$( cat "$__object/parameter/source" )"
|
||||
|
||||
if [ -f "$__object/parameter/destination" ]; then
|
||||
destination=$(cat "$__object/parameter/destination")
|
||||
if [ ! -e "$src" ]
|
||||
then
|
||||
echo "$src not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/destination" ]
|
||||
then
|
||||
dst="$( cat "$__object/parameter/destination" )"
|
||||
else
|
||||
destination="/$__object_id"
|
||||
dst="/$__object_id"
|
||||
fi
|
||||
|
||||
set --
|
||||
if [ -f "$__object/parameter/rsync-opts" ]; then
|
||||
while read -r opts; do
|
||||
set -- "$@" "--$opts"
|
||||
done < "$__object/parameter/rsync-opts"
|
||||
# if source is directory, then make sure that
|
||||
# source and destination are ending with slash,
|
||||
# because this is what you almost always want when
|
||||
# rsyncing two directories.
|
||||
|
||||
if [ -d "$src" ]
|
||||
then
|
||||
if ! echo "$src" | grep -Eq '/$'
|
||||
then
|
||||
src="$src/"
|
||||
fi
|
||||
|
||||
if ! echo "$dst" | grep -Eq '/$'
|
||||
then
|
||||
dst="$dst/"
|
||||
fi
|
||||
fi
|
||||
|
||||
remote_user="$( cat "$__object/parameter/remote-user" )"
|
||||
|
||||
options="$( cat "$__object/parameter/options" )"
|
||||
|
||||
if [ -f "$__object/parameter/option" ]
|
||||
then
|
||||
while read -r l
|
||||
do
|
||||
# there's a limitation in argparse: value can't begin with '-'.
|
||||
# to workaround this, let's prefix opts with '\' in manifest and remove here.
|
||||
# read more about argparse issue: https://bugs.python.org/issue9334
|
||||
|
||||
options="$options $( echo "$l" | sed 's/\\//g' )"
|
||||
done \
|
||||
< "$__object/parameter/option"
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/owner" ] || [ -f "$__object/parameter/group" ]
|
||||
then
|
||||
options="$options --chown="
|
||||
|
||||
if [ -f "$__object/parameter/owner" ]
|
||||
then
|
||||
owner="$( cat "$__object/parameter/owner" )"
|
||||
options="$options$owner"
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/group" ]
|
||||
then
|
||||
group="$( cat "$__object/parameter/group" )"
|
||||
options="$options:$group"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/mode" ]
|
||||
then
|
||||
mode="$( cat "$__object/parameter/mode" )"
|
||||
options="$options --chmod=$mode"
|
||||
fi
|
||||
|
||||
# IMPORTANT
|
||||
#
|
||||
# 1. we first dry-run rsync with change summary to find out
|
||||
# if there are any changes and code generation is needed.
|
||||
# 2. normally, to get current state or target host, we run
|
||||
# such operations in type explorers, but that's not
|
||||
# possible due to how rsync works.
|
||||
# 3. redirecting output of dry-run to stderr to ease debugging.
|
||||
# 4. to understand how that cryptic regex works, please
|
||||
# open rsync manpage and read about --itemize-changes.
|
||||
|
||||
export RSYNC_RSH="$__remote_exec"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
echo rsync -a \
|
||||
--no-owner --no-group \
|
||||
-e \"${__remote_exec}\" \
|
||||
-q "$@" "${source}/" "${remote_user}@${__target_host}:${destination}"
|
||||
if ! rsync --dry-run --itemize-changes $options "$src" "$remote_user@$__target_host:$dst" \
|
||||
| grep -E '^(<|>|c|h|\.|\*)[fdL][cstTpogunbax\.\+\?]+\s' >&2
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "export RSYNC_RSH='$__remote_exec'"
|
||||
|
||||
echo "rsync $options $src $remote_user@$__target_host:$dst"
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# 2015 Dominique Roux (dominique.roux4 at 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
if [ -f "$__object/parameter/destination" ]; then
|
||||
destination=$(cat "$__object/parameter/destination")
|
||||
else
|
||||
destination="/$__object_id"
|
||||
fi
|
||||
|
||||
ownergroup=""
|
||||
if [ -f "$__object/parameter/owner" ]; then
|
||||
ownergroup=$(cat "$__object/parameter/owner")
|
||||
fi
|
||||
if [ -f "$__object/parameter/group" ]; then
|
||||
ownergroup="${ownergroup}:$(cat "$__object/parameter/group")"
|
||||
fi
|
||||
|
||||
if [ "$ownergroup" ]; then
|
||||
echo chown -R "$ownergroup" "$destination"
|
||||
fi
|
@ -1,21 +1,3 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# 2015 Dominique Roux (dominique.roux4 at 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
__package rsync
|
||||
|
@ -0,0 +1 @@
|
||||
--recursive --links --perms --times
|
@ -1,4 +1,6 @@
|
||||
destination
|
||||
owner
|
||||
group
|
||||
mode
|
||||
options
|
||||
owner
|
||||
remote-user
|
||||
|
@ -1 +1 @@
|
||||
rsync-opts
|
||||
option
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
update-alternatives --display "$__object_id" 2>/dev/null \
|
||||
| awk -F ' - ' '/priority [0-9]+$/ { print $1 }'
|
||||
LC_ALL=C update-alternatives --display "${__object_id:?}" 2>/dev/null \
|
||||
| awk -F ' - ' '/priority [0-9]+$/ { print $1 }'
|
||||
|
Loading…
Reference in New Issue