Merge with master.

This commit is contained in:
Darko Poljak 2016-04-28 09:09:32 +02:00
commit cf451f0bea
41 changed files with 287 additions and 27 deletions

View File

@ -49,6 +49,11 @@ if [ -f /etc/debian_version ]; then
echo debian
exit 0
fi
if [ -f /etc/devuan_version ]; then
echo devuan
exit 0
fi
###
if [ -f /etc/gentoo-release ]; then

View File

@ -33,6 +33,9 @@ case "$($__explorer/os)" in
debian)
cat /etc/debian_version
;;
devuan)
cat /etc/devuan_version
;;
fedora)
cat /etc/fedora-release
;;

View File

@ -22,7 +22,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian)
ubuntu|debian|devuan)
# No stinking recommends thank you very much.
# If I want something installed I will do so myself.
__file /etc/apt/apt.conf.d/99-no-recommends \

View File

@ -35,7 +35,7 @@ has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
# If everything is ok -> exit
#
case "$os" in
archlinux|debian|suse|ubuntu)
archlinux|debian|suse|ubuntu|devuan)
if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
exit 0
fi
@ -60,7 +60,7 @@ if [ "$has_hostnamectl" ]; then
echo "hostnamectl set-hostname '$name_should'"
else
case "$os" in
archlinux|debian|ubuntu)
archlinux|debian|ubuntu|devuan)
echo "hostname '$name_should'"
echo "printf '%s\n' '$name_should' > /etc/hostname"
;;

View File

@ -34,7 +34,7 @@ not_supported() {
}
case "$os" in
archlinux|debian|suse|ubuntu)
archlinux|debian|suse|ubuntu|devuan)
# handled in gencode-remote
:
;;

View File

@ -26,7 +26,7 @@ os=$(cat "$__global/explorer/os")
case "$os" in
debian)
debian|devuan)
# Debian needs a seperate package
__package locales --state present
;;

View File

@ -22,8 +22,8 @@
os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu)
debian|ubuntu|devuan)
# Debian and Ubuntu need to be updated,
# as seen in /etc/init.d/bootlogs
echo "uname -snrvm > /var/run/motd"

View File

@ -30,7 +30,7 @@ os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu)
debian|ubuntu|devuan)
destination=/etc/motd.tail
;;
*)

View File

@ -26,9 +26,9 @@ if [ ! -f "$__object/parameter/nofstab" ]; then
(
printf "%s" "$(cat "$__object/parameter/device")"
printf " %s" "$path"
type="$(cat "$__object/parameter/type" 2>/dev/null || echo "auto")"
type="$(cat "$__object/parameter/type")"
printf " %s" "$type"
options="$(cat "$__object/parameter/options" 2>/dev/null || echo "defaults")"
options="$(cat "$__object/parameter/options")"
printf " %s" "$options"
printf " %s" "$(cat "$__object/parameter/dump")"
printf " %s\n" "$(cat "$__object/parameter/pass")"

View File

@ -0,0 +1 @@
defaults

View File

@ -0,0 +1 @@
auto

View File

@ -32,7 +32,7 @@ else
case "$os" in
amazon|centos|fedora|redhat) type="yum" ;;
archlinux) type="pacman" ;;
debian|ubuntu) type="apt" ;;
debian|ubuntu|devuan) type="apt" ;;
freebsd)
if [ -n "$(cat "$__object/explorer/pkgng_exists")" ]; then
type="pkgng_freebsd"

View File

@ -1,6 +1,7 @@
#!/bin/sh
#
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2016 Darko Poljak (darko.poljak at gmail.com)
#
# This file is part of cdist.
#
@ -40,12 +41,30 @@ else
pip="pip"
fi
runasparam="$__object/parameter/runas"
if [ -f "$runasparam" ]
then
runas=$(cat "$runasparam")
else
runas=""
fi
case "$state_should" in
present)
echo $pip install -q "$name"
if [ "$runas" ]
then
echo "su -c \"$pip install -q $name\" $runas"
else
echo $pip install -q "$name"
fi
;;
absent)
echo $pip uninstall -q -y "$name"
if [ "$runas" ]
then
echo "su -c \"$pip uninstall -q -y $name\" $runas"
else
echo $pip uninstall -q -y "$name"
fi
;;
*)
echo "Unknown state: $state_should" >&2

View File

@ -30,6 +30,9 @@ pip::
state::
Either "present" or "absent", defaults to "present"
runas::
Run pip as specified user. By default it runs as root.
EXAMPLES
--------
@ -40,6 +43,9 @@ __package_pip pyro --state present
# Use pip in a virtualenv located at /root/shinken_virtualenv
__package_pip pyro --state present --pip /root/shinken_virtualenv/bin/pip
# Use pip in a virtualenv located at /foo/shinken_virtualenv as user foo
__package_pip pyro --state present --pip /foo/shinken_virtualenv/bin/pip --runas foo
--------------------------------------------------------------------------------

View File

@ -1,2 +1,4 @@
name
pip
state
runas

View File

@ -30,7 +30,7 @@ else
os="$(cat "$__global/explorer/os")"
case "$os" in
amazon|centos|fedora|redhat) type="yum" ;;
debian|ubuntu) type="apt" ;;
debian|ubuntu|devuan) type="apt" ;;
archlinux) type="pacman" ;;
*)
echo "Don't know how to manage packages on: $os" >&2

View File

@ -31,7 +31,7 @@ else
os="$(cat "$__global/explorer/os")"
case "$os" in
amazon|centos|fedora|redhat) type="yum" ;;
debian|ubuntu) type="apt" ;;
debian|ubuntu|devuan) type="apt" ;;
archlinux) type="pacman" ;;
*)
echo "Don't know how to manage packages on: $os" >&2

View File

@ -22,7 +22,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian|archlinux|suse|centos)
ubuntu|debian|archlinux|suse|centos|devuan)
__package postfix --state present
;;
*)

View File

@ -22,7 +22,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian|archlinux|centos)
ubuntu|debian|archlinux|centos|devuan)
:
;;
*)

View File

@ -22,7 +22,7 @@
os=$("$__explorer/os")
case "$os" in
ubuntu|debian|archlinux|suse|centos)
ubuntu|debian|archlinux|suse|centos|devuan)
:
;;
*)

View File

@ -21,7 +21,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian|archlinux|suse|centos)
ubuntu|debian|archlinux|suse|centos|devuan)
:
;;
*)

View File

@ -22,7 +22,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian|archlinux|centos)
ubuntu|debian|archlinux|centos|devuan)
echo "postfix reload"
;;
*)

View File

@ -0,0 +1,5 @@
#!/bin/sh
destination="/$__object_id"
stat --print "%G" ${destination} 2>/dev/null || exit 0

View File

@ -0,0 +1,5 @@
#!/bin/sh
destination="/$__object_id"
stat --print "%U" ${destination} 2>/dev/null || exit 0

View File

@ -0,0 +1,9 @@
#!/bin/sh
destination="/$__object_id"
if [ -d "$destination" ]; then
echo present
else
echo absent
fi

View File

@ -0,0 +1,67 @@
#!/bin/sh
#
# 2016 Darko Poljak (darko.poljak 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/>.
#
#
state_is="$(cat "$__object/explorer/state")"
owner_is="$(cat "$__object/explorer/owner")"
group_is="$(cat "$__object/explorer/group")"
state_should="$(cat "$__object/parameter/state")"
owner="$(cat "$__object/parameter/owner")"
group="$(cat "$__object/parameter/group")"
mode="$(cat "$__object/parameter/mode")"
[ "$state_should" = "$state_is" -a \
"$owner" = "$owner_is" -a \
"$group" = "$group_is" -a \
-n "$mode" ] && exit 0
destination="/$__object_id"
venvparams="$(cat "$__object/parameter/venvparams")"
pyvenvparam="$__object/parameter/pyvenv"
if [ -f "$pyvenvparam" ]
then
pyvenv=$(cat "$pyvenvparam")
else
pyvenv="pyvenv"
fi
case $state_should in
present)
if [ "$state_should" != "$state_is" ]; then
echo $pyvenv $venvparams "$destination"
fi
if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \
\( -n "$group" -a "$group_is" != "$group" \) ]; then
echo chown -R "${owner}:${group}" "$destination"
fi
if [ -n "$mode" ]; then
echo chmod -R "$mode" "$destination"
fi
;;
absent)
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac

View File

@ -0,0 +1,80 @@
cdist-type__pyvenv(7)
=====================
Darko Poljak <darko.poljak--@--gmail.com>
NAME
----
cdist-type__pyvenv - Create or remove python virtual environment
DESCRIPTION
-----------
This cdist type allows you to create or remove python virtual
environment using pyvenv.
It assumes pyvenv is already installed. Concrete package depends
on concrete OS and/or OS version/distribution.
Ensure this for e.g. in your init manifest as in the following example:
--------------------------------------------------------------------------------
case "$__target_host" in
localhost)
__package python3-venv --state present
require="__package/python3-venv" __pyvenv /home/darko/testenv --pyvenv "pyvenv-3.4" --owner darko --group darko --mode 740 --state present
require="__pyvenv/home/darko/testenv" __package_pip docopt --pip /home/darko/testenv/bin/pip --runas darko --state present
;;
esac
--------------------------------------------------------------------------------
REQUIRED PARAMETERS
-------------------
None
OPTIONAL PARAMETERS
-------------------
state::
Either "present" or "absent", defaults to "present"
group::
Group to chgrp to
mode::
Unix permissions, suitable for chmod
owner::
User to chown to
pyvenv::
Use this specific pyvenv
venvparams::
Specific parameters to pass to pyvenv invocation
EXAMPLES
--------
--------------------------------------------------------------------------------
__pyvenv /home/services/djangoenv
# Use specific pyvenv
__pyvenv /home/foo/fooenv --pyvenv /usr/local/bin/pyvenv-3.4
# Create python virtualenv for user foo.
__pyvenv /home/foo/fooenv --group foo --user foo
# Create python virtualenv with specific parameters.
__pyvenv /home/services/djangoenv --venvparams "--copies --system-site-packages"
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2016 Darko Poljak. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1,46 @@
#!/bin/sh
#
# 2016 Darko Poljak (darko.poljak 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/>.
#
# It assumes pyvenv is already installed. Concrete packages
# or installation procedures depend on concrete OS and/or OS
# version/distribution.
state_should="$(cat "$__object/parameter/state")"
owner="$(cat "$__object/parameter/owner")"
group="$(cat "$__object/parameter/group")"
mode="$(cat "$__object/parameter/mode")"
case "$state_should" in
present)
:
;;
absent)
__directory "$__object_id" --state absent \
--owner "$owner" \
--group "$group" \
--mode "$mode"
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
present

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,6 @@
state
group
owner
mode
venvparams
pyvenv

View File

@ -37,7 +37,7 @@ if [ "$init" = 'systemd' ]; then
else
case "$os" in
debian|openwrt)
debian|openwrt|devuan)
state="present"
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
;;

View File

@ -61,8 +61,6 @@ case "$state_should" in
amazon|centos|fedora|owl|redhat|suse)
echo chkconfig \"$name\" on
echo "Unsupported version $os_version of $os" >&2
exit 1
;;
openwrt)

View File

@ -24,7 +24,7 @@ timezone="$__object_id"
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian)
ubuntu|debian|devuan)
echo "echo \"$timezone\" > /etc/timezone"
;;
esac

View File

@ -26,7 +26,7 @@ timezone="$__object_id"
os=$(cat "$__global/explorer/os")
case "$os" in
archlinux|debian|ubuntu)
archlinux|debian|ubuntu|devuan)
__package tzdata
export require="__package/tzdata"
;;

View File

@ -3,6 +3,8 @@ Changelog
next:
* Core: Fix bug with parallel hosts operation when output path is specifed (Darko Poljak)
* Type __package_pip: Add support for running as specified user (useful for pip in venv) (Darko Poljak)
* New type: __pyvenv: Manage python virtualenv (Darko Poljak)
* Core: Add CDIST_REMOTE_COPY/EXEC env variables and multiplexing options for default scp/ssh (Darko Poljak)
* Types: Remove bashisms in scripts (Darko Poljak)
* Core: Fix bug in remote command with environment (Darko Poljak)

View File

@ -23,7 +23,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian|archlinux)
ubuntu|debian|archlinux|devuan)
__package autofs --state present
__start_on_boot autofs --state present
;;

View File

@ -28,7 +28,7 @@ not_supported() {
}
case "$os" in
ubuntu|debian|archlinux)
ubuntu|debian|archlinux|devuan)
echo "pkill -HUP automount"
;;
*)