From ac171ba21934093be08e369424478ae1c2a54e4b Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 6 Apr 2016 17:29:23 +0200 Subject: [PATCH 01/26] remove a copy paste artefact which is wrong there --- cdist/conf/type/__start_on_boot/gencode-remote | 2 -- 1 file changed, 2 deletions(-) diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote index c8488e3a..bcba21be 100644 --- a/cdist/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -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) From d313971e1a1e79bf9a76dbd537cb1bb5298af572 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Mon, 11 Apr 2016 19:21:11 +0200 Subject: [PATCH 02/26] Create __pyvenv type and modify __package_pip accordingly. --- cdist/conf/type/__package_pip/explorer/su | 27 +++++++ cdist/conf/type/__package_pip/explorer/sudo | 27 +++++++ cdist/conf/type/__package_pip/gencode-remote | 42 +++++++++- cdist/conf/type/__package_pip/man.text | 8 ++ .../type/__package_pip/parameter/optional | 1 + cdist/conf/type/__pyvenv/explorer/group | 5 ++ cdist/conf/type/__pyvenv/explorer/owner | 5 ++ cdist/conf/type/__pyvenv/explorer/state | 9 +++ cdist/conf/type/__pyvenv/gencode-remote | 68 +++++++++++++++++ cdist/conf/type/__pyvenv/man.text | 76 +++++++++++++++++++ cdist/conf/type/__pyvenv/manifest | 46 +++++++++++ .../type/__pyvenv/parameter/default/group | 1 + .../conf/type/__pyvenv/parameter/default/mode | 1 + .../type/__pyvenv/parameter/default/owner | 1 + .../type/__pyvenv/parameter/default/python | 1 + .../type/__pyvenv/parameter/default/state | 1 + .../__pyvenv/parameter/default/venvparams | 1 + cdist/conf/type/__pyvenv/parameter/optional | 6 ++ 18 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 cdist/conf/type/__package_pip/explorer/su create mode 100644 cdist/conf/type/__package_pip/explorer/sudo create mode 100755 cdist/conf/type/__pyvenv/explorer/group create mode 100755 cdist/conf/type/__pyvenv/explorer/owner create mode 100755 cdist/conf/type/__pyvenv/explorer/state create mode 100755 cdist/conf/type/__pyvenv/gencode-remote create mode 100755 cdist/conf/type/__pyvenv/man.text create mode 100755 cdist/conf/type/__pyvenv/manifest create mode 100755 cdist/conf/type/__pyvenv/parameter/default/group create mode 100755 cdist/conf/type/__pyvenv/parameter/default/mode create mode 100755 cdist/conf/type/__pyvenv/parameter/default/owner create mode 100644 cdist/conf/type/__pyvenv/parameter/default/python create mode 100755 cdist/conf/type/__pyvenv/parameter/default/state create mode 100644 cdist/conf/type/__pyvenv/parameter/default/venvparams create mode 100755 cdist/conf/type/__pyvenv/parameter/optional diff --git a/cdist/conf/type/__package_pip/explorer/su b/cdist/conf/type/__package_pip/explorer/su new file mode 100644 index 00000000..f355a1bc --- /dev/null +++ b/cdist/conf/type/__package_pip/explorer/su @@ -0,0 +1,27 @@ +#!/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 . +# + +which su > /dev/null 2>&1 +if [ $? -eq 0 ] +then + echo yes +else + echo no +fi diff --git a/cdist/conf/type/__package_pip/explorer/sudo b/cdist/conf/type/__package_pip/explorer/sudo new file mode 100644 index 00000000..7b702bc0 --- /dev/null +++ b/cdist/conf/type/__package_pip/explorer/sudo @@ -0,0 +1,27 @@ +#!/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 . +# + +which sudo > /dev/null 2>&1 +if [ $? -eq 0 ] +then + echo yes +else + echo no +fi diff --git a/cdist/conf/type/__package_pip/gencode-remote b/cdist/conf/type/__package_pip/gencode-remote index ba44927a..ccf30f1a 100644 --- a/cdist/conf/type/__package_pip/gencode-remote +++ b/cdist/conf/type/__package_pip/gencode-remote @@ -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,49 @@ else pip="pip" fi +runasparam="$__object/parameter/runas" +if [ -f "$runasparam" ] +then + runas=$(cat "$runasparam") + has_sudo=$(cat "$__object/explorer/sudo") + if [ "$has_sudo" = "yes" ] + then + runas_cmd="sudo" + else + has_su=$(cat "$__object/explorer/su") + if [ "$has_su" = "yes" ] + then + runas_cmd="su" + else + runas_cmd="" + fi + fi +else + runas_cmd="" +fi + case "$state_should" in present) - echo $pip install -q "$name" + if [ "$runas_cmd" = "sudo" ] + then + echo sudo -H -u $runas $pip install -q "$name" + elif [ "$runas_cmd" = "su" ] + then + echo su $runas -c \"$pip install -q "$name"\" + else + echo $pip install -q "$name" + fi ;; absent) - echo $pip uninstall -q -y "$name" + if [ "$runas_cmd" = "sudo" ] + then + echo sudo -H -u $runas $pip uninstall -q -y "$name" + elif [ "$runas_cmd" = "su" ] + then + echo su $runas -c \"$pip uninstall -q -y "$name"\" + else + echo $pip uninstall -q -y "$name" + fi ;; *) echo "Unknown state: $state_should" >&2 diff --git a/cdist/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.text index 5f619871..cb7c7e11 100644 --- a/cdist/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.text @@ -30,6 +30,11 @@ pip:: state:: Either "present" or "absent", defaults to "present" +runas:: + Run pip as specified user. By default it runs as root. + It uses sudo or su, whichever it founds first, respectively. + If no sudo nor su is present then pip is run by default. + EXAMPLES -------- @@ -40,6 +45,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 -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__package_pip/parameter/optional b/cdist/conf/type/__package_pip/parameter/optional index f32876f7..83265c8b 100644 --- a/cdist/conf/type/__package_pip/parameter/optional +++ b/cdist/conf/type/__package_pip/parameter/optional @@ -1,2 +1,3 @@ pip state +runas diff --git a/cdist/conf/type/__pyvenv/explorer/group b/cdist/conf/type/__pyvenv/explorer/group new file mode 100755 index 00000000..ff072c5e --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/group @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id" + +stat --print "%G" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__pyvenv/explorer/owner b/cdist/conf/type/__pyvenv/explorer/owner new file mode 100755 index 00000000..b77e3c6e --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/owner @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id" + +stat --print "%U" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__pyvenv/explorer/state b/cdist/conf/type/__pyvenv/explorer/state new file mode 100755 index 00000000..ffe3cbbd --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/state @@ -0,0 +1,9 @@ +#!/bin/sh + +destination="/$__object_id" + +if [ -d "$destination" ]; then + echo present +else + echo absent +fi diff --git a/cdist/conf/type/__pyvenv/gencode-remote b/cdist/conf/type/__pyvenv/gencode-remote new file mode 100755 index 00000000..b0fa121d --- /dev/null +++ b/cdist/conf/type/__pyvenv/gencode-remote @@ -0,0 +1,68 @@ +#!/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 . +# +# + +state_is="$(cat "$__object/explorer/state")" +owner_is="$(cat "$__object/explorer/owner")" +group_is="$(cat "$__object/explorer/group")" + +state_should="$(cat "$__object/parameter/state")" + +destination="/$__object_id" + +owner="$(cat "$__object/parameter/owner")" +group="$(cat "$__object/parameter/group")" +mode="$(cat "$__object/parameter/mode")" +python="$(cat "$__object/parameter/python")" +if [ "$python" ] +then + python_opt="-p $python" +else + python_opt="" +fi +venvparams="$(cat "$__object/parameter/venvparams")" + +[ "$state_should" = "$state_is" -a \ + "$owner" = "$owner_is" -a \ + "$group" = "$group_is" -a \ + -n "$mode" ] && exit 0 + +case $state_should in + present) + + if [ "$state_should" != "$state_is" ]; then + echo virtualenv "$python_opt" $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 diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text new file mode 100755 index 00000000..2f9a6ea5 --- /dev/null +++ b/cdist/conf/type/__pyvenv/man.text @@ -0,0 +1,76 @@ +cdist-type__pyvenv(7) +================== +Darko Poljak + + +NAME +---- +cdist-type__pyvenv - Create or remove python virtualenv + + +DESCRIPTION +----------- +This cdist type allows you to create or remove python virtualenv. +It assumes pip and virtualenv are already installed. Concrete packages +or installation procedures depend on concrete OS and/or OS +version/distribution. +Ensure this in your init manifest as in the following example: +-------------------------------------------------------------------------------- +case "$__target_host" in + localhost) + __package python3-pip --state present + require="__package/python3-pip" __package_pip virtualenv --pip pip3 --state present + require="__package/python3-pip __package_pip/virtualenv" __pyvenv /home/darko/testenv --owner darko --group darko --mode 740 --state present + ;; +-------------------------------------------------------------------------------- + + +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. + +python:: + Use specific python interpreter for creating virtualenv. + The default is the interpreter that virtualenv was installed with. + +venvparams:: + virtualenv specific parameters to pass to virtualenv invocation. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__pyvenv /home/services/djangoenv + +# Create python virtualenv for user foo using specific python interpreter. +__pyvenv /home/foo/fooenv --group foo --user foo --python python2.6 + +# Create python virtualenv with specific parameters. +__pyvenv /home/services/djangoenv --venvparams "--relocatable --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). diff --git a/cdist/conf/type/__pyvenv/manifest b/cdist/conf/type/__pyvenv/manifest new file mode 100755 index 00000000..bd2b76e9 --- /dev/null +++ b/cdist/conf/type/__pyvenv/manifest @@ -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 . +# + +# It assumes pip and virtualenv are 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 diff --git a/cdist/conf/type/__pyvenv/parameter/default/group b/cdist/conf/type/__pyvenv/parameter/default/group new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/group @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/mode b/cdist/conf/type/__pyvenv/parameter/default/mode new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/mode @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/owner b/cdist/conf/type/__pyvenv/parameter/default/owner new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/owner @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/python b/cdist/conf/type/__pyvenv/parameter/default/python new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/python @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/state b/cdist/conf/type/__pyvenv/parameter/default/state new file mode 100755 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pyvenv/parameter/default/venvparams b/cdist/conf/type/__pyvenv/parameter/default/venvparams new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/venvparams @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/optional b/cdist/conf/type/__pyvenv/parameter/optional new file mode 100755 index 00000000..6b3fda2e --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/optional @@ -0,0 +1,6 @@ +state +group +owner +mode +python +venvparams From 2410b30b40a5d73c35a03401a58fd10e0bf0255b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Mon, 11 Apr 2016 19:30:45 +0200 Subject: [PATCH 03/26] Update changelog --- docs/changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog b/docs/changelog index b1acf329..5ec8edea 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,6 +2,8 @@ Changelog --------- next: + * Type __package_pip: Add support for running as specified user (useful for pip from virtualenv (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) From 1882040a259cff2cf855e7fa8ebbd32fb4c56309 Mon Sep 17 00:00:00 2001 From: smwltr Date: Tue, 12 Apr 2016 12:18:47 +0900 Subject: [PATCH 04/26] Adding suuport for OS Devuan --- cdist/conf/explorer/os | 5 +++++ cdist/conf/explorer/os_version | 3 +++ cdist/conf/type/__apt_norecommends/manifest | 2 +- cdist/conf/type/__hostname/gencode-remote | 4 ++-- cdist/conf/type/__hostname/manifest | 2 +- cdist/conf/type/__locale/manifest | 2 +- cdist/conf/type/__motd/gencode-remote | 4 ++-- cdist/conf/type/__motd/manifest | 2 +- cdist/conf/type/__package/manifest | 2 +- cdist/conf/type/__package_update_index/gencode-remote | 2 +- cdist/conf/type/__package_upgrade_all/gencode-remote | 2 +- cdist/conf/type/__postfix/manifest | 2 +- cdist/conf/type/__postfix_master/manifest | 2 +- cdist/conf/type/__postfix_postconf/explorer/value | 2 +- cdist/conf/type/__postfix_postconf/gencode-remote | 2 +- cdist/conf/type/__postfix_reload/gencode-remote | 2 +- cdist/conf/type/__start_on_boot/explorer/state | 2 +- cdist/conf/type/__timezone/gencode-remote | 2 +- cdist/conf/type/__timezone/manifest | 2 +- other/archived_types/__autofs/manifest | 2 +- other/archived_types/__autofs_reload/gencode-remote | 2 +- 21 files changed, 29 insertions(+), 21 deletions(-) diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index b9f3512b..de1d29c3 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -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 diff --git a/cdist/conf/explorer/os_version b/cdist/conf/explorer/os_version index 8f092827..6c7becdc 100755 --- a/cdist/conf/explorer/os_version +++ b/cdist/conf/explorer/os_version @@ -33,6 +33,9 @@ case "$($__explorer/os)" in debian) cat /etc/debian_version ;; + devuan) + cat /etc/devuan_version + ;; fedora) cat /etc/fedora-release ;; diff --git a/cdist/conf/type/__apt_norecommends/manifest b/cdist/conf/type/__apt_norecommends/manifest index 6fdc2d93..9e633308 100755 --- a/cdist/conf/type/__apt_norecommends/manifest +++ b/cdist/conf/type/__apt_norecommends/manifest @@ -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 \ diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote index 576f80bf..9fac7bf4 100755 --- a/cdist/conf/type/__hostname/gencode-remote +++ b/cdist/conf/type/__hostname/gencode-remote @@ -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" ;; diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 448e56da..76f962e0 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -34,7 +34,7 @@ not_supported() { } case "$os" in - archlinux|debian|suse|ubuntu) + archlinux|debian|suse|ubuntu|devuan) # handled in gencode-remote : ;; diff --git a/cdist/conf/type/__locale/manifest b/cdist/conf/type/__locale/manifest index 0e279630..c1837ae3 100644 --- a/cdist/conf/type/__locale/manifest +++ b/cdist/conf/type/__locale/manifest @@ -26,7 +26,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - debian) + debian|devuan) # Debian needs a seperate package __package locales --state present ;; diff --git a/cdist/conf/type/__motd/gencode-remote b/cdist/conf/type/__motd/gencode-remote index bfd13b5e..41fe3482 100755 --- a/cdist/conf/type/__motd/gencode-remote +++ b/cdist/conf/type/__motd/gencode-remote @@ -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" diff --git a/cdist/conf/type/__motd/manifest b/cdist/conf/type/__motd/manifest index 286d1ff3..4848a4c3 100755 --- a/cdist/conf/type/__motd/manifest +++ b/cdist/conf/type/__motd/manifest @@ -30,7 +30,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - debian|ubuntu) + debian|ubuntu|devuan) destination=/etc/motd.tail ;; *) diff --git a/cdist/conf/type/__package/manifest b/cdist/conf/type/__package/manifest index 25e43b30..6b0daa98 100755 --- a/cdist/conf/type/__package/manifest +++ b/cdist/conf/type/__package/manifest @@ -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" diff --git a/cdist/conf/type/__package_update_index/gencode-remote b/cdist/conf/type/__package_update_index/gencode-remote index 8ee837eb..589e7202 100755 --- a/cdist/conf/type/__package_update_index/gencode-remote +++ b/cdist/conf/type/__package_update_index/gencode-remote @@ -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 diff --git a/cdist/conf/type/__package_upgrade_all/gencode-remote b/cdist/conf/type/__package_upgrade_all/gencode-remote index 57676a57..4d034816 100755 --- a/cdist/conf/type/__package_upgrade_all/gencode-remote +++ b/cdist/conf/type/__package_upgrade_all/gencode-remote @@ -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 diff --git a/cdist/conf/type/__postfix/manifest b/cdist/conf/type/__postfix/manifest index 5a184910..43443e1e 100755 --- a/cdist/conf/type/__postfix/manifest +++ b/cdist/conf/type/__postfix/manifest @@ -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 ;; *) diff --git a/cdist/conf/type/__postfix_master/manifest b/cdist/conf/type/__postfix_master/manifest index 7777892b..3d82c526 100755 --- a/cdist/conf/type/__postfix_master/manifest +++ b/cdist/conf/type/__postfix_master/manifest @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux|centos) + ubuntu|debian|archlinux|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_postconf/explorer/value b/cdist/conf/type/__postfix_postconf/explorer/value index 3f319eda..d451bce6 100755 --- a/cdist/conf/type/__postfix_postconf/explorer/value +++ b/cdist/conf/type/__postfix_postconf/explorer/value @@ -22,7 +22,7 @@ os=$("$__explorer/os") case "$os" in - ubuntu|debian|archlinux|suse|centos) + ubuntu|debian|archlinux|suse|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_postconf/gencode-remote b/cdist/conf/type/__postfix_postconf/gencode-remote index 4b4096a5..b3557640 100755 --- a/cdist/conf/type/__postfix_postconf/gencode-remote +++ b/cdist/conf/type/__postfix_postconf/gencode-remote @@ -21,7 +21,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux|suse|centos) + ubuntu|debian|archlinux|suse|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_reload/gencode-remote b/cdist/conf/type/__postfix_reload/gencode-remote index 8311568a..7323606c 100755 --- a/cdist/conf/type/__postfix_reload/gencode-remote +++ b/cdist/conf/type/__postfix_reload/gencode-remote @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux|centos) + ubuntu|debian|archlinux|centos|devuan) echo "postfix reload" ;; *) diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state index 2f94a521..ca0f3a51 100644 --- a/cdist/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -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" ;; diff --git a/cdist/conf/type/__timezone/gencode-remote b/cdist/conf/type/__timezone/gencode-remote index b4782d4b..c07a61cb 100755 --- a/cdist/conf/type/__timezone/gencode-remote +++ b/cdist/conf/type/__timezone/gencode-remote @@ -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 diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index 9b0cce73..8ddfd122 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -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" ;; diff --git a/other/archived_types/__autofs/manifest b/other/archived_types/__autofs/manifest index 4a726c0a..ed6e87ee 100755 --- a/other/archived_types/__autofs/manifest +++ b/other/archived_types/__autofs/manifest @@ -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 ;; diff --git a/other/archived_types/__autofs_reload/gencode-remote b/other/archived_types/__autofs_reload/gencode-remote index 883602e2..913d3f24 100755 --- a/other/archived_types/__autofs_reload/gencode-remote +++ b/other/archived_types/__autofs_reload/gencode-remote @@ -28,7 +28,7 @@ not_supported() { } case "$os" in - ubuntu|debian|archlinux) + ubuntu|debian|archlinux|devuan) echo "pkill -HUP automount" ;; *) From 49423e174b35427e2984a8f77fb988c3c43bc862 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 08:24:44 +0200 Subject: [PATCH 05/26] Use pyvenv instead of virtualenv. --- cdist/conf/type/__pyvenv/gencode-remote | 10 +- cdist/conf/type/__pyvenv/man.text | 147 ++++++++++++------------ cdist/conf/type/__pyvenv/manifest | 2 +- 3 files changed, 73 insertions(+), 86 deletions(-) diff --git a/cdist/conf/type/__pyvenv/gencode-remote b/cdist/conf/type/__pyvenv/gencode-remote index b0fa121d..4e4513ee 100755 --- a/cdist/conf/type/__pyvenv/gencode-remote +++ b/cdist/conf/type/__pyvenv/gencode-remote @@ -30,13 +30,6 @@ destination="/$__object_id" owner="$(cat "$__object/parameter/owner")" group="$(cat "$__object/parameter/group")" mode="$(cat "$__object/parameter/mode")" -python="$(cat "$__object/parameter/python")" -if [ "$python" ] -then - python_opt="-p $python" -else - python_opt="" -fi venvparams="$(cat "$__object/parameter/venvparams")" [ "$state_should" = "$state_is" -a \ @@ -46,9 +39,8 @@ venvparams="$(cat "$__object/parameter/venvparams")" case $state_should in present) - if [ "$state_should" != "$state_is" ]; then - echo virtualenv "$python_opt" $venvparams "$destination" + echo pyvenv $venvparams "$destination" fi if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \ \( -n "$group" -a "$group_is" != "$group" \) ]; then diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text index 2f9a6ea5..3b1072f1 100755 --- a/cdist/conf/type/__pyvenv/man.text +++ b/cdist/conf/type/__pyvenv/man.text @@ -1,76 +1,71 @@ -cdist-type__pyvenv(7) -================== -Darko Poljak - - -NAME ----- -cdist-type__pyvenv - Create or remove python virtualenv - - -DESCRIPTION ------------ -This cdist type allows you to create or remove python virtualenv. -It assumes pip and virtualenv are already installed. Concrete packages -or installation procedures depend on concrete OS and/or OS -version/distribution. -Ensure this in your init manifest as in the following example: --------------------------------------------------------------------------------- -case "$__target_host" in - localhost) - __package python3-pip --state present - require="__package/python3-pip" __package_pip virtualenv --pip pip3 --state present - require="__package/python3-pip __package_pip/virtualenv" __pyvenv /home/darko/testenv --owner darko --group darko --mode 740 --state present - ;; --------------------------------------------------------------------------------- - - -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. - -python:: - Use specific python interpreter for creating virtualenv. - The default is the interpreter that virtualenv was installed with. - -venvparams:: - virtualenv specific parameters to pass to virtualenv invocation. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -__pyvenv /home/services/djangoenv - -# Create python virtualenv for user foo using specific python interpreter. -__pyvenv /home/foo/fooenv --group foo --user foo --python python2.6 - -# Create python virtualenv with specific parameters. -__pyvenv /home/services/djangoenv --venvparams "--relocatable --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). +cdist-type__pyvenv(7) +================== +Darko Poljak + + +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 python >= 3.3 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 --state present + require="__package/python3" __pyvenv /home/darko/testenv --owner darko --group darko --mode 740 --state present + ;; +-------------------------------------------------------------------------------- + + +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 + +venvparams:: + Specific parameters to pass to pyvenv invocation + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__pyvenv /home/services/djangoenv + +# 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). + diff --git a/cdist/conf/type/__pyvenv/manifest b/cdist/conf/type/__pyvenv/manifest index bd2b76e9..3f0fbb17 100755 --- a/cdist/conf/type/__pyvenv/manifest +++ b/cdist/conf/type/__pyvenv/manifest @@ -18,7 +18,7 @@ # along with cdist. If not, see . # -# It assumes pip and virtualenv are already installed. Concrete packages +# It assumes python >= 3.3 is already installed. Concrete packages # or installation procedures depend on concrete OS and/or OS # version/distribution. From 85af0c1bb0d6806914975ff8ddedcf189e140b80 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 08:26:58 +0200 Subject: [PATCH 06/26] Remove virtualenv params not present in pyvenv. --- cdist/conf/type/__pyvenv/parameter/optional | 1 - 1 file changed, 1 deletion(-) diff --git a/cdist/conf/type/__pyvenv/parameter/optional b/cdist/conf/type/__pyvenv/parameter/optional index 6b3fda2e..fc4019c9 100755 --- a/cdist/conf/type/__pyvenv/parameter/optional +++ b/cdist/conf/type/__pyvenv/parameter/optional @@ -2,5 +2,4 @@ state group owner mode -python venvparams From 3296158a375b50afe03136160156e8711857fcd7 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 08:27:23 +0200 Subject: [PATCH 07/26] Remove virtualenv params not present in pyvenv. --- cdist/conf/type/__pyvenv/parameter/default/python | 1 - 1 file changed, 1 deletion(-) delete mode 100644 cdist/conf/type/__pyvenv/parameter/default/python diff --git a/cdist/conf/type/__pyvenv/parameter/default/python b/cdist/conf/type/__pyvenv/parameter/default/python deleted file mode 100644 index 8b137891..00000000 --- a/cdist/conf/type/__pyvenv/parameter/default/python +++ /dev/null @@ -1 +0,0 @@ - From 0ba27d8326e6ba37262c544335c4a6f29224f7eb Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 08:29:38 +0200 Subject: [PATCH 08/26] Fix text typos. --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 5ec8edea..9feb2097 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,7 +2,7 @@ Changelog --------- next: - * Type __package_pip: Add support for running as specified user (useful for pip from virtualenv (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) From 4d5fa3087f1af3d2c6f0d4e2a86c44d3c8b9de25 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 20:14:06 +0200 Subject: [PATCH 09/26] Update comment info. --- cdist/conf/type/__pyvenv/man.text | 11 ++++++----- cdist/conf/type/__pyvenv/manifest | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text index 3b1072f1..80934710 100755 --- a/cdist/conf/type/__pyvenv/man.text +++ b/cdist/conf/type/__pyvenv/man.text @@ -10,15 +10,16 @@ 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 python >= 3.3 is already installed. Concrete package depends on concrete OS -and/or OS version/distribution. +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 --state present - require="__package/python3" __pyvenv /home/darko/testenv --owner darko --group darko --mode 740 --state present + __package python3-venv --state present + require="__package/python3-venv" __pyvenv /home/darko/testenv --owner darko --group darko --mode 740 --state present ;; -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__pyvenv/manifest b/cdist/conf/type/__pyvenv/manifest index 3f0fbb17..3e41ad04 100755 --- a/cdist/conf/type/__pyvenv/manifest +++ b/cdist/conf/type/__pyvenv/manifest @@ -18,7 +18,7 @@ # along with cdist. If not, see . # -# It assumes python >= 3.3 is already installed. Concrete packages +# It assumes pyvenv is already installed. Concrete packages # or installation procedures depend on concrete OS and/or OS # version/distribution. From d9b2f1a54073763e99e1ecbfd3e1003a0e656811 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 22:32:15 +0200 Subject: [PATCH 10/26] Add parameter --pyvenv. --- cdist/conf/type/__pyvenv/gencode-remote | 15 +++++++++++---- cdist/conf/type/__pyvenv/man.text | 6 ++++++ cdist/conf/type/__pyvenv/parameter/optional | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__pyvenv/gencode-remote b/cdist/conf/type/__pyvenv/gencode-remote index 4e4513ee..907e0ff6 100755 --- a/cdist/conf/type/__pyvenv/gencode-remote +++ b/cdist/conf/type/__pyvenv/gencode-remote @@ -25,22 +25,29 @@ group_is="$(cat "$__object/explorer/group")" state_should="$(cat "$__object/parameter/state")" -destination="/$__object_id" - owner="$(cat "$__object/parameter/owner")" group="$(cat "$__object/parameter/group")" mode="$(cat "$__object/parameter/mode")" -venvparams="$(cat "$__object/parameter/venvparams")" [ "$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" + echo $pyvenv $venvparams "$destination" fi if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \ \( -n "$group" -a "$group_is" != "$group" \) ]; then diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text index 80934710..6124c72c 100755 --- a/cdist/conf/type/__pyvenv/man.text +++ b/cdist/conf/type/__pyvenv/man.text @@ -42,6 +42,9 @@ mode:: owner:: User to chown to +pyvenv:: + Use this specific pyvenv + venvparams:: Specific parameters to pass to pyvenv invocation @@ -52,6 +55,9 @@ 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 diff --git a/cdist/conf/type/__pyvenv/parameter/optional b/cdist/conf/type/__pyvenv/parameter/optional index fc4019c9..ed2218b1 100755 --- a/cdist/conf/type/__pyvenv/parameter/optional +++ b/cdist/conf/type/__pyvenv/parameter/optional @@ -3,3 +3,4 @@ group owner mode venvparams +pyvenv From a1e86a481c9e11261a7382a91bf8a6ddbedadc31 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 13 Apr 2016 22:34:10 +0200 Subject: [PATCH 11/26] Updated man. --- cdist/conf/type/__pyvenv/man.text | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text index 6124c72c..4fcd4dd1 100755 --- a/cdist/conf/type/__pyvenv/man.text +++ b/cdist/conf/type/__pyvenv/man.text @@ -19,8 +19,10 @@ 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 --owner darko --group darko --mode 740 --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 -------------------------------------------------------------------------------- From cd78d4140a564e1547a072b857536360d6482e91 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 15 Apr 2016 08:37:33 +0200 Subject: [PATCH 12/26] Add global explorers su, sudo and sucmd. --- .../conf/{type/__package_pip => }/explorer/su | 11 ++++- cdist/conf/explorer/sucmd | 46 +++++++++++++++++++ .../{type/__package_pip => }/explorer/sudo | 11 ++++- cdist/conf/type/__package_pip/gencode-remote | 28 ++--------- 4 files changed, 69 insertions(+), 27 deletions(-) rename cdist/conf/{type/__package_pip => }/explorer/su (68%) create mode 100644 cdist/conf/explorer/sucmd rename cdist/conf/{type/__package_pip => }/explorer/sudo (67%) diff --git a/cdist/conf/type/__package_pip/explorer/su b/cdist/conf/explorer/su similarity index 68% rename from cdist/conf/type/__package_pip/explorer/su rename to cdist/conf/explorer/su index f355a1bc..ae164e69 100644 --- a/cdist/conf/type/__package_pip/explorer/su +++ b/cdist/conf/explorer/su @@ -17,11 +17,18 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# This explorer returns script code string for running a command with su. +# If no su is found then it returns empty string. +# It uses two arguments, first user and the second command to run. +# If the result string is assigned to foo it is used as: +# $ $foo user command +# which su > /dev/null 2>&1 if [ $? -eq 0 ] then - echo yes + su_func='f() { su -c "$2" $1 ; }' + echo "eval '${su_func}' ; f " else - echo no + echo "" fi diff --git a/cdist/conf/explorer/sucmd b/cdist/conf/explorer/sucmd new file mode 100644 index 00000000..1f16666d --- /dev/null +++ b/cdist/conf/explorer/sucmd @@ -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 . +# +# This explorer returns script code string for running a command with su +# or sudo, whichever it founds. If searches the command in the order of +# first sudo and then su if sudo is not found. +# If no sudo nor su is found then it returns string script code to run +# bare command. +# It uses two arguments, first user and the second command to run. +# If the result string is assigned to foo it is used as: +# $ $foo user command +# + +# first check sudo +which sudo > /dev/null 2>&1 +if [ $? -eq 0 ] +then + func='f() { sudo -H -u $1 $2; }' +else + # if no sudo then check su + which su > /dev/null 2>&1 + if [ $? -eq 0 ] + then + func='f() { su -c "$2" $1 ; }' + else + # if no sudo nor su then run bare command + func='f() { $2 ; }' + fi +fi +echo "eval '${func}' ; f " diff --git a/cdist/conf/type/__package_pip/explorer/sudo b/cdist/conf/explorer/sudo similarity index 67% rename from cdist/conf/type/__package_pip/explorer/sudo rename to cdist/conf/explorer/sudo index 7b702bc0..079c570d 100644 --- a/cdist/conf/type/__package_pip/explorer/sudo +++ b/cdist/conf/explorer/sudo @@ -17,11 +17,18 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# This explorer returns script code string for running a command with sudo. +# If no sudo is found then it returns empty string. +# It uses two arguments, first user and the second command to run. +# If the result string is assigned to foo it is used as: +# $ $foo user command +# which sudo > /dev/null 2>&1 if [ $? -eq 0 ] then - echo yes + sudo_func='f() { sudo -H -u $1 $2; }' + echo "eval '${sudo_func}' ; f " else - echo no + echo "" fi diff --git a/cdist/conf/type/__package_pip/gencode-remote b/cdist/conf/type/__package_pip/gencode-remote index ccf30f1a..b9a52efc 100644 --- a/cdist/conf/type/__package_pip/gencode-remote +++ b/cdist/conf/type/__package_pip/gencode-remote @@ -45,42 +45,24 @@ runasparam="$__object/parameter/runas" if [ -f "$runasparam" ] then runas=$(cat "$runasparam") - has_sudo=$(cat "$__object/explorer/sudo") - if [ "$has_sudo" = "yes" ] - then - runas_cmd="sudo" - else - has_su=$(cat "$__object/explorer/su") - if [ "$has_su" = "yes" ] - then - runas_cmd="su" - else - runas_cmd="" - fi - fi + runas_cmd=$(cat "$__global/explorer/sucmd") else runas_cmd="" fi case "$state_should" in present) - if [ "$runas_cmd" = "sudo" ] + if [ "$runas_cmd" ] then - echo sudo -H -u $runas $pip install -q "$name" - elif [ "$runas_cmd" = "su" ] - then - echo su $runas -c \"$pip install -q "$name"\" + echo "$runas_cmd $runas \"$pip install -q $name\"" else echo $pip install -q "$name" fi ;; absent) - if [ "$runas_cmd" = "sudo" ] + if [ "$runas_cmd" ] then - echo sudo -H -u $runas $pip uninstall -q -y "$name" - elif [ "$runas_cmd" = "su" ] - then - echo su $runas -c \"$pip uninstall -q -y "$name"\" + echo "$runas_cmd $runas \"$pip uninstall -q -y $name\"" else echo $pip uninstall -q -y "$name" fi From 641b511f1aaa2ed9e441a9cdb9db766d6f819d5e Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 15 Apr 2016 08:39:33 +0200 Subject: [PATCH 13/26] Update changelog. --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 9feb2097..3ee4622d 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,6 +2,7 @@ Changelog --------- next: + * Types: Add global explorers su, sudo and sucmd (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) From 856678b09c1d3304010ec236022aad8311ca4c55 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 15 Apr 2016 08:40:08 +0200 Subject: [PATCH 14/26] Update changelog. --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 3ee4622d..25dc2a00 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,7 +2,7 @@ Changelog --------- next: - * Types: Add global explorers su, sudo and sucmd (Darko Poljak) + * Types: Add global explorers su, sudo and sucmd (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) From 5c33d2292520c73f8cba89efb91284dc71366137 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 15 Apr 2016 10:50:51 +0200 Subject: [PATCH 15/26] Prefer su over sudo. --- cdist/conf/explorer/sucmd | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/cdist/conf/explorer/sucmd b/cdist/conf/explorer/sucmd index 1f16666d..bd4343d2 100644 --- a/cdist/conf/explorer/sucmd +++ b/cdist/conf/explorer/sucmd @@ -19,27 +19,47 @@ # # This explorer returns script code string for running a command with su # or sudo, whichever it founds. If searches the command in the order of -# first sudo and then su if sudo is not found. -# If no sudo nor su is found then it returns string script code to run +# first su and then sudo if su is not found. +# If no su nor sudo is found then it returns string script code to run # bare command. # It uses two arguments, first user and the second command to run. # If the result string is assigned to foo it is used as: # $ $foo user command # -# first check sudo -which sudo > /dev/null 2>&1 -if [ $? -eq 0 ] -then - func='f() { sudo -H -u $1 $2; }' -else - # if no sudo then check su +sudo_func() { + which sudo > /dev/null 2>&1 + if [ $? -eq 0 ] + then + func='f() { sudo -H -u $1 $2; }' + retval=0 + else + func='' + retval=1 + fi + return $retval +} +su_func() { which su > /dev/null 2>&1 if [ $? -eq 0 ] then func='f() { su -c "$2" $1 ; }' + retval=0 else - # if no sudo nor su then run bare command + func='' + retval=1 + fi + return $retval +} +# first check su +su_func +if [ $? -ne 0 ] +then + # if no su then check sudo + sudo_func + if [ $? -ne 0 ] + then + # if no su nor sudo then run bare command func='f() { $2 ; }' fi fi From f24d2644807033f0cb3f5ab080d7d3b5c1e03740 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 15 Apr 2016 12:04:31 +0200 Subject: [PATCH 16/26] Updated usage comment. --- cdist/conf/explorer/su | 5 +++-- cdist/conf/explorer/sucmd | 5 +++-- cdist/conf/explorer/sudo | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cdist/conf/explorer/su b/cdist/conf/explorer/su index ae164e69..9fc83c56 100644 --- a/cdist/conf/explorer/su +++ b/cdist/conf/explorer/su @@ -20,8 +20,9 @@ # This explorer returns script code string for running a command with su. # If no su is found then it returns empty string. # It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it is used as: -# $ $foo user command +# If the result string is assigned to foo it can be used in code +# generation as: +# echo "$foo user command" # which su > /dev/null 2>&1 diff --git a/cdist/conf/explorer/sucmd b/cdist/conf/explorer/sucmd index bd4343d2..78d46b09 100644 --- a/cdist/conf/explorer/sucmd +++ b/cdist/conf/explorer/sucmd @@ -23,8 +23,9 @@ # If no su nor sudo is found then it returns string script code to run # bare command. # It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it is used as: -# $ $foo user command +# If the result string is assigned to foo it can be used in code +# generation as: +# echo "$foo user command" # sudo_func() { diff --git a/cdist/conf/explorer/sudo b/cdist/conf/explorer/sudo index 079c570d..b217f58b 100644 --- a/cdist/conf/explorer/sudo +++ b/cdist/conf/explorer/sudo @@ -20,8 +20,9 @@ # This explorer returns script code string for running a command with sudo. # If no sudo is found then it returns empty string. # It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it is used as: -# $ $foo user command +# If the result string is assigned to foo it can be used in code +# generation as: +# echo "$foo user command" # which sudo > /dev/null 2>&1 From e76d2af3586508e90b24c85a625fae424f9faf85 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 20 Apr 2016 08:13:47 +0200 Subject: [PATCH 17/26] Remove old style defaults. --- cdist/conf/type/__mount/parameter/default/options | 1 + cdist/conf/type/__mount/parameter/default/type | 1 + 2 files changed, 2 insertions(+) create mode 100644 cdist/conf/type/__mount/parameter/default/options create mode 100644 cdist/conf/type/__mount/parameter/default/type diff --git a/cdist/conf/type/__mount/parameter/default/options b/cdist/conf/type/__mount/parameter/default/options new file mode 100644 index 00000000..e94f8140 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/options @@ -0,0 +1 @@ +defaults diff --git a/cdist/conf/type/__mount/parameter/default/type b/cdist/conf/type/__mount/parameter/default/type new file mode 100644 index 00000000..865faf10 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/type @@ -0,0 +1 @@ +auto From 2ea85c773c20fab6cec5ca7b2391db3fade515ee Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 20 Apr 2016 08:14:44 +0200 Subject: [PATCH 18/26] Remove old style defaults. --- cdist/conf/type/__mount/manifest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__mount/manifest b/cdist/conf/type/__mount/manifest index 8a1fa234..472b6e2e 100755 --- a/cdist/conf/type/__mount/manifest +++ b/cdist/conf/type/__mount/manifest @@ -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")" From 66c2e16a24df102539e462957bbf8246dd479910 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:24:47 +0200 Subject: [PATCH 19/26] __package_pip: always use su for runas parameter. --- cdist/conf/type/__package_pip/gencode-remote | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__package_pip/gencode-remote b/cdist/conf/type/__package_pip/gencode-remote index b9a52efc..ccfdb92b 100644 --- a/cdist/conf/type/__package_pip/gencode-remote +++ b/cdist/conf/type/__package_pip/gencode-remote @@ -45,24 +45,23 @@ runasparam="$__object/parameter/runas" if [ -f "$runasparam" ] then runas=$(cat "$runasparam") - runas_cmd=$(cat "$__global/explorer/sucmd") else - runas_cmd="" + runas="" fi case "$state_should" in present) - if [ "$runas_cmd" ] + if [ "$runas" ] then - echo "$runas_cmd $runas \"$pip install -q $name\"" + echo "su -c \"$pip install -q $name\" $runas" else echo $pip install -q "$name" fi ;; absent) - if [ "$runas_cmd" ] + if [ "$runas" ] then - echo "$runas_cmd $runas \"$pip uninstall -q -y $name\"" + echo "su -c \"$pip uninstall -q -y $name\" $runas" else echo $pip uninstall -q -y "$name" fi From 7aa197b731238f5315ee37e27a8c92bb4f413590 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:26:07 +0200 Subject: [PATCH 20/26] Rm unnecessary details from __package_pip man. --- cdist/conf/type/__package_pip/man.text | 2 -- 1 file changed, 2 deletions(-) diff --git a/cdist/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.text index cb7c7e11..5b67e62f 100644 --- a/cdist/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.text @@ -32,8 +32,6 @@ state:: runas:: Run pip as specified user. By default it runs as root. - It uses sudo or su, whichever it founds first, respectively. - If no sudo nor su is present then pip is run by default. EXAMPLES From 5e0975a30417eb48e7e49a296b5ca0e03c2cb6dd Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:26:47 +0200 Subject: [PATCH 21/26] Remove unnecessary global explorer. --- cdist/conf/explorer/su | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 cdist/conf/explorer/su diff --git a/cdist/conf/explorer/su b/cdist/conf/explorer/su deleted file mode 100644 index 9fc83c56..00000000 --- a/cdist/conf/explorer/su +++ /dev/null @@ -1,35 +0,0 @@ -#!/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 . -# -# This explorer returns script code string for running a command with su. -# If no su is found then it returns empty string. -# It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it can be used in code -# generation as: -# echo "$foo user command" -# - -which su > /dev/null 2>&1 -if [ $? -eq 0 ] -then - su_func='f() { su -c "$2" $1 ; }' - echo "eval '${su_func}' ; f " -else - echo "" -fi From b7da9d1ef50b2ec16ee7f4a3abb429450f43e955 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:26:57 +0200 Subject: [PATCH 22/26] Remove unnecessary global explorer. --- cdist/conf/explorer/sucmd | 67 --------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 cdist/conf/explorer/sucmd diff --git a/cdist/conf/explorer/sucmd b/cdist/conf/explorer/sucmd deleted file mode 100644 index 78d46b09..00000000 --- a/cdist/conf/explorer/sucmd +++ /dev/null @@ -1,67 +0,0 @@ -#!/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 . -# -# This explorer returns script code string for running a command with su -# or sudo, whichever it founds. If searches the command in the order of -# first su and then sudo if su is not found. -# If no su nor sudo is found then it returns string script code to run -# bare command. -# It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it can be used in code -# generation as: -# echo "$foo user command" -# - -sudo_func() { - which sudo > /dev/null 2>&1 - if [ $? -eq 0 ] - then - func='f() { sudo -H -u $1 $2; }' - retval=0 - else - func='' - retval=1 - fi - return $retval -} -su_func() { - which su > /dev/null 2>&1 - if [ $? -eq 0 ] - then - func='f() { su -c "$2" $1 ; }' - retval=0 - else - func='' - retval=1 - fi - return $retval -} -# first check su -su_func -if [ $? -ne 0 ] -then - # if no su then check sudo - sudo_func - if [ $? -ne 0 ] - then - # if no su nor sudo then run bare command - func='f() { $2 ; }' - fi -fi -echo "eval '${func}' ; f " From b40034a54aa17b19b82b1ad66f781959eaf51578 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:27:08 +0200 Subject: [PATCH 23/26] Remove unnecessary global explorer. --- cdist/conf/explorer/sudo | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 cdist/conf/explorer/sudo diff --git a/cdist/conf/explorer/sudo b/cdist/conf/explorer/sudo deleted file mode 100644 index b217f58b..00000000 --- a/cdist/conf/explorer/sudo +++ /dev/null @@ -1,35 +0,0 @@ -#!/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 . -# -# This explorer returns script code string for running a command with sudo. -# If no sudo is found then it returns empty string. -# It uses two arguments, first user and the second command to run. -# If the result string is assigned to foo it can be used in code -# generation as: -# echo "$foo user command" -# - -which sudo > /dev/null 2>&1 -if [ $? -eq 0 ] -then - sudo_func='f() { sudo -H -u $1 $2; }' - echo "eval '${sudo_func}' ; f " -else - echo "" -fi From 9a9836a0477d028ee166bfa748b43ac98414f250 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 08:28:47 +0200 Subject: [PATCH 24/26] Remove unnecessary global explorers. --- docs/changelog | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 25dc2a00..9feb2097 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,7 +2,6 @@ Changelog --------- next: - * Types: Add global explorers su, sudo and sucmd (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) From 360ab47be0a02ac65c34314881d59f6cbc6991d3 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 21 Apr 2016 09:23:19 +0200 Subject: [PATCH 25/26] Fix '=' length. --- cdist/conf/type/__pyvenv/man.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__pyvenv/man.text b/cdist/conf/type/__pyvenv/man.text index 4fcd4dd1..71d30ed5 100755 --- a/cdist/conf/type/__pyvenv/man.text +++ b/cdist/conf/type/__pyvenv/man.text @@ -1,5 +1,5 @@ cdist-type__pyvenv(7) -================== +===================== Darko Poljak From e933e8cd750f2735d223eb44f1904f71aaf0b047 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 22 Apr 2016 14:41:31 +0200 Subject: [PATCH 26/26] Add missing name parameter. --- cdist/conf/type/__package_pip/parameter/optional | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__package_pip/parameter/optional b/cdist/conf/type/__package_pip/parameter/optional index 83265c8b..d909e790 100644 --- a/cdist/conf/type/__package_pip/parameter/optional +++ b/cdist/conf/type/__package_pip/parameter/optional @@ -1,3 +1,4 @@ +name pip state runas