commit
3c18697da8
@ -0,0 +1 @@ |
||||
present |
@ -0,0 +1,37 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Jake Guffey (jake.guffey at eprotex.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/>. |
||||
# |
||||
# |
||||
# Retrieve the status of a package - parsed dpkg output |
||||
# |
||||
|
||||
if [ -f "$__object/parameter/name" ]; then |
||||
name="$(cat "$__object/parameter/name")" |
||||
else |
||||
name="$__object_id" |
||||
fi |
||||
|
||||
# Don't produce "no pkgs installed" output -- breaks things |
||||
PKG_OUTPUT=$(pkg info 2>&1) |
||||
echo -n "$(echo "$PKG_OUTPUT" \ |
||||
| awk '{print $1}' \ |
||||
| sed 's/^\(.*\)-\([^-]*\)$/name:\1 ver:\2/g' \ |
||||
| grep "name:$name ver:" \ |
||||
| sed 's/^.*ver:\(.*\)/\1/g')" |
||||
|
@ -0,0 +1,139 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Jake Guffey (jake.guffey at eprotex.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/>. |
||||
# |
||||
# |
||||
# Manage packages with pkg on FreeBSD |
||||
# |
||||
|
||||
# Debug |
||||
#exec >&2 |
||||
#set -x |
||||
|
||||
if [ -f "$__object/parameter/name" ]; then |
||||
name="$(cat "$__object/parameter/name")" |
||||
else |
||||
name="$__object_id" |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/flavor" ]; then |
||||
flavor="$(cat "$__object/parameter/flavor")" |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/version" ]; then |
||||
version="$(cat "$__object/parameter/version")" |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/upgrade" ]; then |
||||
upgrade="true" |
||||
else |
||||
upgrade="false" |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/repo" ]; then |
||||
repo="$(cat "$__object/parameter/repo")" |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/state" ]; then |
||||
state="$(cat "$__object/parameter/state")" |
||||
else |
||||
state="present" |
||||
fi |
||||
curr_version="$(cat "$__object/explorer/pkg_version")" |
||||
add_cmd="pkg install -y" |
||||
rm_cmd="pkg delete -y" |
||||
upg_cmd="pkg upgrade -y" |
||||
cmd="" |
||||
|
||||
# Print the command to be executed |
||||
# Parms: $1 -- mode, "rm", "add", or "upg" |
||||
# $2 -- the command to be echoed |
||||
execcmd(){ |
||||
local _cmd="" |
||||
|
||||
case "$1" in |
||||
add) |
||||
_cmd="${add_cmd} $2" |
||||
;; |
||||
rm) |
||||
_cmd="${rm_cmd} $2" |
||||
;; |
||||
upg) |
||||
_cmd="${upg_cmd} $2" |
||||
;; |
||||
*) |
||||
printf "Error. Don't understand command: %s" "$1" >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
||||
|
||||
echo "$_cmd 2>&- >&-" # Silence the output of the command |
||||
echo "status=\$?" |
||||
echo "if [ \"\$status\" -ne \"0\" ]; then" |
||||
echo " echo \"Error: ${_cmd} exited nonzero with \$status\"'!' >&2" |
||||
echo " exit 1" |
||||
echo "fi" |
||||
} |
||||
|
||||
if [ -n "$curr_version" ]; then # PKG *is* installed |
||||
if [ -n "$repo" ]; then |
||||
cmd="-r ${repo} ${name}" |
||||
else |
||||
cmd="${name}" |
||||
fi |
||||
if [ -n "$flavor" ]; then |
||||
cmd="${cmd}-${flavor}" |
||||
fi |
||||
# PKG is supposed to be removed |
||||
if [ "$state" = "absent" ]; then |
||||
execcmd "rm" "${cmd}" |
||||
# PKG is supposed to be installed to a particular version |
||||
elif [ -n "$version" ] && [ "$version" != "$curr_version" ]; then |
||||
if [ "$upgrade" = "true" ]; then |
||||
execcmd "upg" "${cmd}" |
||||
else |
||||
printf "Version %s is already installed and pkg-ng can't upgrade directly to version %s.\nTo upgrade to the latest version, use the --upgrade flag.\n" "$curr_version" "$version" >&2 |
||||
exit 1 |
||||
fi |
||||
# PKG is supposed to be installed to the latest version |
||||
else |
||||
: # Do nothing. |
||||
fi |
||||
else # PKG *isn't* installed |
||||
if [ "$state" = "absent" ]; then # Shouldn't be installed |
||||
exit 0 |
||||
else # Should be installed |
||||
if [ -n "$repo" ]; then |
||||
cmd="-r ${repo} ${name}" |
||||
else |
||||
cmd="${name}" |
||||
fi |
||||
if [ -n "$flavor" ]; then |
||||
cmd="${cmd}-${flavor}" |
||||
fi |
||||
if [ -n "$version" ]; then |
||||
cmd="${cmd}-${version}" |
||||
fi |
||||
|
||||
execcmd "add" "$cmd" |
||||
exit 0 |
||||
fi |
||||
fi |
||||
|
||||
# Debug |
||||
#set +x |
@ -0,0 +1,97 @@ |
||||
cdist-type__package_pkgng_freebsd(7) |
||||
================================== |
||||
Jake Guffey <jake.guffey--@--eprotex.com> |
||||
|
||||
|
||||
NAME |
||||
---- |
||||
cdist-type__package_pkgng_freebsd - Manage FreeBSD packages with pkg-ng |
||||
|
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This type is usually used on FreeBSD to manage packages. |
||||
|
||||
|
||||
REQUIRED PARAMETERS |
||||
------------------- |
||||
None |
||||
|
||||
|
||||
OPTIONAL PARAMETERS |
||||
------------------- |
||||
name:: |
||||
If supplied, use the name and not the object id as the package name. |
||||
|
||||
flavor:: |
||||
If supplied, use to avoid ambiguity. |
||||
|
||||
version:: |
||||
If supplied, use to install a specific version of the package named. |
||||
|
||||
repo:: |
||||
If supplied, use to install the package named from a particular repo. |
||||
|
||||
state:: |
||||
Either "present" or "absent", defaults to "present" |
||||
|
||||
|
||||
BOOLEAN PARAMETERS |
||||
------------------ |
||||
upgrade:: |
||||
If supplied, allow upgrading to the latest version of a package. |
||||
|
||||
|
||||
CAVEATS |
||||
------- |
||||
This type requires that repository definitions already exist in /etc/pkg/*.conf. |
||||
Ensure that they exist prior to use of this type with __file. |
||||
|
||||
pkg-ng can't upgrade a package to a specific version. If this type needs to |
||||
upgrade a package, it can only ugprade to the latest available version. If the |
||||
"upgrade" parameter is not given and an upgrade needs to occur, an error will result. |
||||
|
||||
|
||||
MESSAGES |
||||
-------- |
||||
install:: |
||||
The package was installed |
||||
remove:: |
||||
The package was removed |
||||
upgrade:: |
||||
The package was upgraded |
||||
exist:: |
||||
The package was already present and thus not installed |
||||
|
||||
|
||||
EXAMPLES |
||||
-------- |
||||
|
||||
-------------------------------------------------------------------------------- |
||||
# Ensure zsh is installed |
||||
__package_pkgng_freebsd zsh --state present |
||||
|
||||
# Ensure vim is installed, use flavor no_x11 |
||||
__package_pkgng_freebsd vim --state present --flavor no_x11 |
||||
|
||||
# If you don't want to follow pythonX packages, but always use python |
||||
__package_pkgng_freebsd python --state present --name python2 |
||||
|
||||
# Install a package from a particular repository when multiples exist |
||||
__package_pkgng_freebsd bash --state present --repo myrepo |
||||
|
||||
# Remove obsolete package |
||||
__package_pkgng_freebsd puppet --state absent |
||||
-------------------------------------------------------------------------------- |
||||
|
||||
|
||||
SEE ALSO |
||||
-------- |
||||
- cdist-type(7) |
||||
- cdist-type__package(7) |
||||
|
||||
|
||||
COPYING |
||||
------- |
||||
Copyright \(C) 2014 Jake Guffey. Free use of this software is |
||||
granted under the terms of the GNU General Public License version 3 (GPLv3). |
@ -0,0 +1 @@ |
||||
upgrade |
@ -0,0 +1,5 @@ |
||||
name |
||||
flavor |
||||
version |
||||
repo |
||||
state |
@ -0,0 +1,50 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Ricardo Catalinas Jiménez (jimenezrick 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/>. |
||||
# |
||||
# |
||||
# Update the package index with the appropriate package manager |
||||
# |
||||
|
||||
type="$__object/parameter/type" |
||||
|
||||
if [ -f "$type" ]; then |
||||
type="$(cat "$type")" |
||||
else |
||||
# By default determine package manager based on operating system |
||||
os="$(cat "$__global/explorer/os")" |
||||
case "$os" in |
||||
amazon|centos|fedora|redhat) type="yum" ;; |
||||
debian|ubuntu) type="apt" ;; |
||||
archlinux) type="pacman" ;; |
||||
*) |
||||
echo "Don't know how to manage packages on: $os" >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
||||
fi |
||||
|
||||
case "$type" in |
||||
yum) ;; |
||||
apt) echo "apt-get --quiet update" ;; |
||||
pacman) echo "pacman --noprogressbar --sync --refresh" ;; |
||||
*) |
||||
echo "Don't know how to manage packages on: $os" >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
@ -0,0 +1,52 @@ |
||||
cdist-type__package_update_index(7) |
||||
=================================== |
||||
Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com> |
||||
|
||||
|
||||
NAME |
||||
---- |
||||
cdist-type__package_update_index - Update the package index |
||||
|
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This cdist type allows you to update the package index on the target. |
||||
It will automatically use the appropriate package manager. |
||||
|
||||
|
||||
REQUIRED PARAMETERS |
||||
------------------- |
||||
None |
||||
|
||||
|
||||
OPTIONAL PARAMETERS |
||||
------------------- |
||||
type:: |
||||
The package manager to use. Default is determined based on the $os |
||||
explorer variable. |
||||
e.g. apt for Debian |
||||
yum for Red Hat |
||||
pacman for Arch Linux |
||||
|
||||
|
||||
EXAMPLES |
||||
-------- |
||||
|
||||
-------------------------------------------------------------------------------- |
||||
# Update the package index on the target |
||||
__package_update_index |
||||
|
||||
# Force use of a specific package manager |
||||
__package_update_index --type apt |
||||
-------------------------------------------------------------------------------- |
||||
|
||||
|
||||
SEE ALSO |
||||
-------- |
||||
- cdist-type(7) |
||||
|
||||
|
||||
COPYING |
||||
------- |
||||
Copyright \(C) 2014 Ricardo Catalinas Jiménez. Free use of this software is |
||||
granted under the terms of the GNU General Public License version 3 (GPLv3). |
@ -0,0 +1 @@ |
||||
type |
@ -0,0 +1,62 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Ricardo Catalinas Jiménez (jimenezrick 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/>. |
||||
# |
||||
# |
||||
# Upgrade all the already installed packages with the appropriate package |
||||
# manager |
||||
# |
||||
|
||||
type="$__object/parameter/type" |
||||
|
||||
if [ -f "$type" ]; then |
||||
type="$(cat "$type")" |
||||
else |
||||
# By default determine package manager based on operating system |
||||
os="$(cat "$__global/explorer/os")" |
||||
case "$os" in |
||||
amazon|centos|fedora|redhat) type="yum" ;; |
||||
debian|ubuntu) type="apt" ;; |
||||
archlinux) type="pacman" ;; |
||||
*) |
||||
echo "Don't know how to manage packages on: $os" >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
||||
fi |
||||
|
||||
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" |
||||
|
||||
case "$type" in |
||||
yum) |
||||
echo "yum --quiet --assumeyes update" |
||||
echo "yum --quiet clean all" |
||||
;; |
||||
apt) |
||||
echo $aptget dist-upgrade |
||||
echo "apt-get --quiet autoclean" |
||||
;; |
||||
pacman) |
||||
echo "pacman --noprogressbar --noconfirm --sync --sysupgrade" |
||||
echo "pacman --noprogressbar --noconfirm --sync --clean" |
||||
;; |
||||
*) |
||||
echo "Don't know how to manage packages on: $os" >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
@ -0,0 +1,52 @@ |
||||
cdist-type__package_upgrade_all(7) |
||||
================================== |
||||
Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com> |
||||
|
||||
|
||||
NAME |
||||
---- |
||||
cdist-type__package_upgrade_all - Upgrade all the installed packages |
||||
|
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This cdist type allows you to upgrade all the installed packages on the |
||||
target. It will automatically use the appropriate package manager. |
||||
|
||||
|
||||
REQUIRED PARAMETERS |
||||
------------------- |
||||
None |
||||
|
||||
|
||||
OPTIONAL PARAMETERS |
||||
------------------- |
||||
type:: |
||||
The package manager to use. Default is determined based on the $os |
||||
explorer variable. |
||||
e.g. apt for Debian |
||||
yum for Red Hat |
||||
pacman for Arch Linux |
||||
|
||||
|
||||
EXAMPLES |
||||
-------- |
||||
|
||||
-------------------------------------------------------------------------------- |
||||
# Upgrade all the installed packages on the target |
||||
__package_upgrade_all |
||||
|
||||
# Force use of a specific package manager |
||||
__package_upgrade_all --type apt |
||||
-------------------------------------------------------------------------------- |
||||
|
||||
|
||||
SEE ALSO |
||||
-------- |
||||
- cdist-type(7) |
||||
|
||||
|
||||
COPYING |
||||
------- |
||||
Copyright \(C) 2014 Ricardo Catalinas Jiménez. Free use of this software is |
||||
granted under the terms of the GNU General Public License version 3 (GPLv3). |
@ -0,0 +1 @@ |
||||
type |
@ -0,0 +1,26 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Steven Armstrong (steven-cdist at armstrong.cc) |
||||
# |
||||
# 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/>. |
||||
# |
||||
|
||||
# extract the keytype and base64 encoded key ignoring any options and comment |
||||
type_and_key="$(cat "$__object/parameter/key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" |
||||
file="$(cat $__object/parameter/file)" |
||||
|
||||
# get any entries that match the type and key |
||||
grep ".*$type_and_key[ \n]" "$file" || true |
@ -0,0 +1,109 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Steven Armstrong (steven-cdist at armstrong.cc) |
||||
# |
||||
# 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/>. |
||||
# |
||||
|
||||
set -u |
||||
|
||||
remove_line() { |
||||
file="$1" |
||||
line="$2" |
||||
cat << DONE |
||||
tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) |
||||
# preserve ownership and permissions of existing file |
||||
if [ -f "$file" ]; then |
||||
cp -p "$file" "\$tmpfile" |
||||
fi |
||||
grep -v -F -x '$line' '$file' > \$tmpfile || true |
||||
mv -f "\$tmpfile" "$file" |
||||
DONE |
||||
} |
||||
|
||||
add_line() { |
||||
file="$1" |
||||
line="$2" |
||||
# escape single quotes |
||||
line_sanitised=$(echo "$line" | sed -e "s/'/'\"'\"'/g") |
||||
printf '%s' "printf '%s\n' '$line_sanitised' >> $file" |
||||
} |
||||
|
||||
|
||||
file="$(cat "$__object/parameter/file")" |
||||
mkdir "$__object/files" |
||||
|
||||
# Generate the entry as it should be |
||||
( |
||||
if [ -f "$__object/parameter/option" ]; then |
||||
# comma seperated list of options |
||||
options="$(cat "$__object/parameter/option" | tr '\n' ',')" |
||||
printf '%s ' "${options%*,}" |
||||
fi |
||||
if [ -f "$__object/parameter/comment" ]; then |
||||
# extract the keytype and base64 encoded key ignoring any options and comment |
||||
printf '%s ' "$(cat "$__object/parameter/key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" |
||||
# override the comment with the one explicitly given |
||||
printf '%s' "$(cat "$__object/parameter/comment")" |
||||
else |
||||
printf '%s' "$(cat "$__object/parameter/key")" |
||||
fi |
||||
printf '\n' |
||||
) > "$__object/files/should" |
||||
|
||||
# Remove conflicting entries if any |
||||
if [ -s "$__object/explorer/entry" ]; then |
||||
# Note that the files have to be sorted for comparison with `comm`. |
||||
sort "$__object/explorer/entry" > "$__object/files/is" |
||||
comm -13 "$__object/files/should" "$__object/files/is" | { |
||||
while read entry; do |
||||
remove_line "$file" "$entry" |
||||
done |
||||
} |
||||
fi |
||||
|
||||
# Determine the current state |
||||
entry="$(cat "$__object/files/should")" |
||||
state_should="$(cat "$__object/parameter/state")" |
||||
num_existing_entries=$(grep -c -F -x "$entry" "$__object/explorer/entry") |
||||
if [ $num_existing_entries -eq 1 ]; then |
||||
state_is="present" |
||||
else |
||||
# Posix grep does not define the -m option, so we can not remove a single |
||||
# occurence of a string from a file in the `remove_line` function. Instead |
||||
# _all_ occurences are removed. |
||||
# By using `comm` to detect conflicting entries this could lead to the |
||||
# situation that the key we want to add is actually removed. |
||||
# To workaround this we must treat 0 or more then 1 existing entries to |
||||
# mean current state is 'absent'. By doing this, the key is readded |
||||
# again after cleaning up conflicting entries. |
||||
state_is="absent" |
||||
fi |
||||
|
||||
# Manage the actual entry as it should be |
||||
if [ "$state_should" = "$state_is" ]; then |
||||
# Nothing to do |
||||
exit 0 |
||||
fi |
||||
|
||||
case "$state_should" in |
||||
present) |
||||
add_line "$file" "$entry" |
||||
;; |
||||
absent) |
||||
remove_line "$file" "$entry" |
||||
;; |
||||
esac |
@ -0,0 +1,67 @@ |
||||
cdist-type__ssh_authorized_key(7) |
||||
================================= |
||||
Steven Armstrong <steven-cdist--@--armstrong.cc> |
||||
|
||||
|
||||
NAME |
||||
---- |
||||
cdist-type__ssh_authorized_key - manage a single ssh authorized key entry |
||||
|
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
Manage a single authorized key entry in an authorized_key file. |
||||
This type was created to be used by the __ssh_authorized_keys type. |
||||
|
||||
|
||||
REQUIRED PARAMETERS |
||||
------------------- |
||||
file:: |
||||
the authorized_keys file to which the given key should be added |
||||
|
||||
key:: |
||||
a string containing the ssh keytype, base 64 encoded key and optional |
||||
trailing comment which shall be added to the given authorized_keys file. |
||||
|
||||
|
||||
OPTIONAL PARAMETERS |
||||
------------------- |
||||
comment:: |
||||
explicit comment instead of the one which may be trailing the given key |
||||
|
||||
option:: |
||||
an option to set for this authorized_key entry. |
||||
Can be specified multiple times. |
||||
See sshd(8) for available options. |
||||
|
||||
state:: |
||||
if the given keys should be 'present' or 'absent', defaults to 'present'. |
||||
|
||||
|
||||
EXAMPLES |
||||
-------- |
||||
|
||||
-------------------------------------------------------------------------------- |
||||
__ssh_authorized_key some-id \ |
||||
--file "/home/user/.ssh/autorized_keys" \ |
||||
--key "$(cat ~/.ssh/id_rsa.pub)" |
||||
|
||||
__ssh_authorized_key some-id \ |
||||
--file "/home/user/.ssh/autorized_keys" \ |
||||
--key "$(cat ~/.ssh/id_rsa.pub)" \ |
||||
--option 'command="/path/to/script"' \ |
||||
--option 'environment="FOO=bar"' \ |
||||
--comment 'one to rule them all' |
||||
-------------------------------------------------------------------------------- |
||||
|
||||
|
||||
SEE ALSO |
||||
-------- |
||||
- cdist-type(7) |
||||
- cdist__ssh_authorized_keys(7) |
||||
- sshd(8) |
||||
|
||||
COPYING |
||||
------- |
||||
Copyright \(C) 2014 Steven Armstrong. Free use of this software is |
||||
granted under the terms of the GNU General Public License version 3 (GPLv3). |
@ -0,0 +1 @@ |
||||
present |
@ -0,0 +1,2 @@ |
||||
comment |
||||
state |
@ -0,0 +1 @@ |
||||
option |
@ -0,0 +1,2 @@ |
||||
file |
||||
key |
@ -0,0 +1,32 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Steven Armstrong (steven-cdist at armstrong.cc) |
||||
# |
||||
# 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/>. |
||||
# |
||||
|
||||
# Find and sort any entries in the authorized_keys file that we care about |
||||
|
||||
file="$($__type_explorer/file)" |
||||
|
||||
( |
||||
while read key; do |
||||
# extract the keytype and base64 encoded key ignoring any options and comment |
||||
type_and_key="$(echo "$key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" |
||||
# emit any entries that match the type and key |
||||
grep ".*$type_and_key[ \n]" "$file" |
||||
done < "$__object/parameter/key" |
||||
) | sort |
@ -0,0 +1,27 @@ |
||||
#!/bin/sh |
||||
# |
||||
# 2014 Steven Armstrong (steven-cdist at armstrong.cc) |
||||
# |
||||
# 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/file" ]; then |
||||
cat "$__object/parameter/file" |
||||
else |
||||
owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")" |
||||
home=$(getent passwd "$owner" | cut -d':' -f 6) |
||||
echo "$home/.ssh/authorized_keys" |
||||
fi |
Loading…
Reference in new issue