From 8ed0c672b14f2fcb642c7511d64d839651049c59 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 11 Mar 2016 19:23:59 +0100 Subject: [PATCH 01/18] Fix error with args. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 40f34e25..5aadce0c 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join((str(x) for x in error.args))) finally: if message_prefix: message.merge_messages() From afbb3df28083d5b91b972a2eb720b1d319e01c25 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 17 Mar 2016 23:34:30 +0100 Subject: [PATCH 02/18] remove legacy cruft Signed-off-by: Steven Armstrong --- cdist/conf/type/__apt_ppa/manifest | 5 ++--- docs/changelog | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest index 1d90e9c4..a67c7613 100755 --- a/cdist/conf/type/__apt_ppa/manifest +++ b/cdist/conf/type/__apt_ppa/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2016 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,9 +21,8 @@ name="$__object_id" __package software-properties-common -__package python-software-properties -require="__package/software-properties-common __package/python-software-properties" \ +require="__package/software-properties-common" \ __file /usr/local/bin/remove-apt-repository \ --source "$__type/files/remove-apt-repository" \ --mode 0755 diff --git a/docs/changelog b/docs/changelog index cf7e4e4b..e88b2198 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,6 +9,8 @@ next: * Type __consul: Add source & cksum for 0.5.2 (Steven Armstrong) * Core: Support object ids '.cdist' (Nico Schottelius) * Type __apt_norecommends: Also setup autoremove options (Dmitry Bogatov) + * Type __apt_ppa: Do not install legacy package python-software-properties + (Steven Armstrong) 3.1.13: 2015-05-16 From 76a78f0d9b51d1f545d8dd7425a17a814782edd3 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 17 Mar 2016 23:38:57 +0100 Subject: [PATCH 03/18] /spaces/tab/ Signed-off-by: Steven Armstrong --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index e88b2198..5a6fa726 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,7 +9,7 @@ next: * Type __consul: Add source & cksum for 0.5.2 (Steven Armstrong) * Core: Support object ids '.cdist' (Nico Schottelius) * Type __apt_norecommends: Also setup autoremove options (Dmitry Bogatov) - * Type __apt_ppa: Do not install legacy package python-software-properties + * Type __apt_ppa: Do not install legacy package python-software-properties (Steven Armstrong) From 3ae042f2cd9d468ce607344fe673cd90c0036d55 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:27:23 +0100 Subject: [PATCH 04/18] Rverting manually (limited connectivity) to original. Will be fixed in a separate branch. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 5aadce0c..dc7c02bc 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join((str(x) for x in error.args))) + raise cdist.Error(" ".join(*args) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() From 6ae94df0a194e6314f3296567363ddb4987ec933 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:29:16 +0100 Subject: [PATCH 05/18] Reset manually to original. Limited connectivity, but have extra time, so doing it online. Will be fixed in a separate branch. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index dc7c02bc..40f34e25 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join(*args) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() From 4851197de2e4eb0657dfa5557edf3d5ca4030c0b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:31:06 +0100 Subject: [PATCH 06/18] Reseting to original manually (limited connect). Limited connectivity, but have extra time, so reseting this to original. This new feature will be implemented in separate branch. --- scripts/cdist | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/scripts/cdist b/scripts/cdist index 8aa998d2..39449666 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # # 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -21,34 +20,6 @@ # # -def inspect_ssh_mux_opts(): - import subprocess - - """Inspect whether or not ssh supports multiplexing options""" - wanted_mux_opts = { - "ControlPath":"~/.ssh/master-%l-%r@%h:%p", - "ControlMaster":"auto", - "ControlPersist":"125", - } - # if checked key option is present then this assumes - # all options in value are present - check = { - "ControlMaster": ("ControlMaster", "ControlPath"), - "ControlPersist": ("ControlPersist",), - } - mux_opts = {} - for x in check: - try: - subprocess.check_output("ssh -o {}".format(x), - stderr=subprocess.STDOUT, shell=True) - except subprocess.CalledProcessError as e: - foo = e.output.decode().lower() - if not "bad configuration option" in foo: - for o in check[x]: - mux_opts[o] = wanted_mux_opts[o] - foo = [" -o {}={}".format(x, mux_opts[x]) for x in mux_opts] - return " ".join(foo) - def commandline(): """Parse command line""" import argparse @@ -82,11 +53,6 @@ def commandline(): parser['banner'].set_defaults(func=cdist.banner.banner) # Config - # inspect multiplexing options for default remote copy/exec scp/ssh - MUX_OPTS = inspect_ssh_mux_opts() - cdist.REMOTE_EXEC += MUX_OPTS - cdist.REMOTE_COPY += MUX_OPTS - parser['config'] = parser['sub'].add_parser('config', parents=[parser['loglevel']]) parser['config'].add_argument('host', nargs='+', From 5e5106479f55a184fff67ee89e3530680f8a9ec0 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 18:22:14 +0100 Subject: [PATCH 07/18] Fix old bug: join wrong arg for OSError. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 40f34e25..0be803a9 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join(command) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() From 017990467588ec81732d57c10607ed5403e1a986 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 22 Mar 2016 11:01:19 +0100 Subject: [PATCH 08/18] bugfix for newer zypper (SLES12SP1) releases, different column numbers in output --- cdist/conf/type/__zypper_service/explorer/service_uri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri index bcad4ec8..d57d2aa8 100644 --- a/cdist/conf/type/__zypper_service/explorer/service_uri +++ b/cdist/conf/type/__zypper_service/explorer/service_uri @@ -27,4 +27,4 @@ else fi # simpler command which works only on SLES11 SP3 or newer: # echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 7) -echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | cut -d'|' -f 7 ) +echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | awk '{print $NF}') From b749a4b88a982c347a212d95301e3b08e25a5126 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 23 Mar 2016 15:47:31 +0100 Subject: [PATCH 09/18] consul changes --- cdist/conf/type/__consul/files/versions/0.4.1/source | 2 +- cdist/conf/type/__consul/files/versions/0.5.0/source | 2 +- cdist/conf/type/__consul/files/versions/0.5.1/source | 2 +- cdist/conf/type/__consul/files/versions/0.6.4/cksum | 1 + cdist/conf/type/__consul/files/versions/0.6.4/source | 1 + cdist/conf/type/__consul/parameter/default/version | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 cdist/conf/type/__consul/files/versions/0.6.4/cksum create mode 100644 cdist/conf/type/__consul/files/versions/0.6.4/source diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/source b/cdist/conf/type/__consul/files/versions/0.4.1/source index 7fb949c8..b1e9908d 100644 --- a/cdist/conf/type/__consul/files/versions/0.4.1/source +++ b/cdist/conf/type/__consul/files/versions/0.4.1/source @@ -1 +1 @@ -https://releases.hashicorp.com/consul/0.4.1/consul_0.4.1_linux_amd64.zip +https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/source b/cdist/conf/type/__consul/files/versions/0.5.0/source index dc1c33c4..00a209a5 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.0/source +++ b/cdist/conf/type/__consul/files/versions/0.5.0/source @@ -1 +1 @@ -https://releases.hashicorp.com/consul/0.5.0/consul_0.5.0_linux_amd64.zip +https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.1/source b/cdist/conf/type/__consul/files/versions/0.5.1/source index a47eb69c..f02a1103 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.1/source +++ b/cdist/conf/type/__consul/files/versions/0.5.1/source @@ -1 +1 @@ -https://releases.hashicorp.com/consul/0.5.1/consul_0.5.1_linux_amd64.zip +https://dl.bintray.com/mitchellh/consul/0.5.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.4/cksum b/cdist/conf/type/__consul/files/versions/0.6.4/cksum new file mode 100644 index 00000000..1124b7aa --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.4/cksum @@ -0,0 +1 @@ +3832641574 23002736 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.4/source b/cdist/conf/type/__consul/files/versions/0.6.4/source new file mode 100644 index 00000000..96879b8d --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.4/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip diff --git a/cdist/conf/type/__consul/parameter/default/version b/cdist/conf/type/__consul/parameter/default/version index 8f0916f7..d2b13eb6 100644 --- a/cdist/conf/type/__consul/parameter/default/version +++ b/cdist/conf/type/__consul/parameter/default/version @@ -1 +1 @@ -0.5.0 +0.6.4 From 14f3ee403aef85c8a31a1fef616aafba9f52cacf Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 23 Mar 2016 16:34:57 +0100 Subject: [PATCH 10/18] fix fo __start_on_boot for ALL systemd distros --- cdist/conf/explorer/init | 24 ++++ .../conf/type/__start_on_boot/explorer/state | 78 ++++++----- .../conf/type/__start_on_boot/gencode-remote | 131 ++++++++++-------- 3 files changed, 135 insertions(+), 98 deletions(-) create mode 100755 cdist/conf/explorer/init mode change 100755 => 100644 cdist/conf/type/__start_on_boot/explorer/state mode change 100755 => 100644 cdist/conf/type/__start_on_boot/gencode-remote diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init new file mode 100755 index 00000000..3777b431 --- /dev/null +++ b/cdist/conf/explorer/init @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 2016 Daniel Heule (hda at sfs.biz) +# +# 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 . +# +# +# Check whether the given name will be started on boot or not +# + +ps -o comm= --pid 1 diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state old mode 100755 new mode 100644 index 1906033c..1cad6602 --- a/cdist/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -24,47 +24,51 @@ os=$("$__explorer/os") runlevel=$("$__explorer/runlevel") +init=$("$__explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" name="$__object_id" -case "$os" in - archlinux) - state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ - && echo present \ - || echo absent) - ;; +if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo, new RHEL and SLES versions + state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ + && echo present \ + || echo absent) - debian|openwrt) - state="present" - [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" - ;; - ubuntu) - state="absent" - [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" - [ -f "/etc/init/${name}.conf" ] && state="present" - ;; +else + case "$os" in + debian|openwrt) + state="present" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" + ;; + ubuntu) + state="absent" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" + [ -f "/etc/init/${name}.conf" ] && state="present" + ;; - amazon|centos|fedora|owl|redhat) - state=$(chkconfig --level "$runlevel" "$name" || echo absent) - [ "$state" ] || state="present" - ;; - suse) - # check for target if set, usable for boot. services in runlevel B - if [ "$target_runlevel" != 'default' ]; then - runlevel="$target_runlevel" - fi - # suses chkconfig has the same name, but works different ... - state=$(chkconfig --check "$name" "$runlevel" || echo absent) - [ "$state" ] || state="present" - ;; - gentoo) - state="present" - [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" - ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; -esac + amazon|centos|fedora|owl|redhat) + state=$(chkconfig --level "$runlevel" "$name" || echo absent) + [ "$state" ] || state="present" + ;; + suse) + # check for target if set, usable for boot. services in runlevel B + if [ "$target_runlevel" != 'default' ]; then + runlevel="$target_runlevel" + fi + # suses chkconfig has the same name, but works different ... + state=$(chkconfig --check "$name" "$runlevel" || echo absent) + [ "$state" ] || state="present" + ;; + gentoo) + state="present" + [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" + ;; + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac +fi echo $state diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote old mode 100755 new mode 100644 index 611e59fe..c8488e3a --- a/cdist/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh # # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2013 Daniel Heule (hda at sfs.biz) +# 2016 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -22,6 +22,7 @@ state_should="$(cat "$__object/parameter/state")" state_is=$(cat "$__object/explorer/state") +init=$(cat "$__global/explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" # Short circuit if nothing is to be done @@ -33,78 +34,86 @@ name="$__object_id" case "$state_should" in present) - case "$os" in - archlinux) - echo "systemctl enable \"$name\"" - ;; - debian) - case "$os_version" in - [1-7]*) - echo "update-rc.d \"$name\" defaults >/dev/null" - ;; - 8*) - echo "systemctl enable \"$name\"" - ;; - *) - echo "Unsupported version $os_version of $os" >&2 - exit 1 - ;; - esac - ;; + if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q enable \"$name\"" + else + case "$os" in + debian) + case "$os_version" in + [1-7]*) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; + 8*) + echo "systemctl enable \"$name\"" + ;; + *) + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; + esac + ;; - gentoo) - echo rc-update add \"$name\" \"$target_runlevel\" - ;; + gentoo) + echo rc-update add \"$name\" \"$target_runlevel\" + ;; - amazon|centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" on - ;; + amazon|centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" on + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; - openwrt) - # 'enable' can be successful and still return a non-zero exit - # code, deal with it by checking for success ourselves in that - # case (the || ... part). - echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" - ;; + openwrt) + # 'enable' can be successful and still return a non-zero exit + # code, deal with it by checking for success ourselves in that + # case (the || ... part). + echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" + ;; - ubuntu) - echo "update-rc.d \"$name\" defaults >/dev/null" - ;; + ubuntu) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; absent) - case "$os" in - archlinux) - echo "systemctl disable \"$name\"" - ;; - debian|ubuntu) - echo update-rc.d -f \"$name\" remove - ;; + if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q disable \"$name\"" - gentoo) - echo rc-update del \"$name\" \"$target_runlevel\" - ;; + else + case "$os" in + debian|ubuntu) + echo update-rc.d -f \"$name\" remove + ;; - centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" off - ;; + gentoo) + echo rc-update del \"$name\" \"$target_runlevel\" + ;; - openwrt) - echo "\"/etc/init.d/$name\" disable" - ;; + centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" off + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac - + openwrt) + echo "\"/etc/init.d/$name\" disable" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; *) From d3a0bd20c0b14cb129f2bc7f0e55d2069bc5a5d3 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 24 Mar 2016 10:58:14 +0100 Subject: [PATCH 11/18] replace egrep with awk functions --- cdist/conf/type/__zypper_service/explorer/service_uri | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri index d57d2aa8..6eee47fb 100644 --- a/cdist/conf/type/__zypper_service/explorer/service_uri +++ b/cdist/conf/type/__zypper_service/explorer/service_uri @@ -25,6 +25,4 @@ if [ -f "$__object/parameter/uri" ]; then else uri="/$__object_id" fi -# simpler command which works only on SLES11 SP3 or newer: -# echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 7) -echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | awk '{print $NF}') +echo $(zypper ls -u | awk 'BEGIN { FS = "[ ]+\\|[ ]+" } ; $4 == "Yes" && $NF == "'$uri'" {print $NF}') From 2c49e04c9847fe55ec4b64fe815ce0fe36e79766 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 24 Mar 2016 11:22:09 +0100 Subject: [PATCH 12/18] Updated the exlorer for more systems changed the ps syntax, so it should work on freebsd to added a case so it could easy implemented for other os to --- cdist/conf/explorer/init | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index 3777b431..a9cdd0d3 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -18,7 +18,19 @@ # along with cdist. If not, see . # # -# Check whether the given name will be started on boot or not +# Returns the process name of pid 1 ( normaly the init system ) +# for example at linux this value is "init" or "systemd" in most cases # -ps -o comm= --pid 1 +uname_s="$(uname -s)" + +case "$uname_s" in + Linux|FreeBSD) + ps -o comm= -p 1 || true + exit 0 + ;; + *) + echo "init exlorer needs to be implemented for $os" >&2 + exit 1 + ;; +esac From 9c6d7dbd892c30c11ed8c03f74a24d688d47cad4 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 24 Mar 2016 11:29:13 +0100 Subject: [PATCH 13/18] modified the unknown case ... --- cdist/conf/explorer/init | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index a9cdd0d3..fd54d0c0 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -27,10 +27,8 @@ uname_s="$(uname -s)" case "$uname_s" in Linux|FreeBSD) ps -o comm= -p 1 || true - exit 0 ;; *) - echo "init exlorer needs to be implemented for $os" >&2 - exit 1 + echo "unknown" ;; esac From f7de217129de14e3857fd19eaa1cc1402312966a Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 25 Mar 2016 16:39:48 +0100 Subject: [PATCH 14/18] modified the unknown case to empty... --- cdist/conf/explorer/init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index fd54d0c0..2693a0d3 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -29,6 +29,7 @@ case "$uname_s" in ps -o comm= -p 1 || true ;; *) - echo "unknown" + # return a empty string as unknown value + echo "" ;; esac From 1dfd6671e7f6ce22c834fb38f8f110456f684924 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 21:57:50 +0100 Subject: [PATCH 15/18] Fix #416: error for non-posix remote shell. Fix remote.py test errors. --- cdist/exec/remote.py | 27 ++++++++++++++++++++++----- cdist/test/exec/remote.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 9b7d5d1c..c99cc77c 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -130,12 +130,29 @@ class Remote(object): # FIXME: replace this by -o SendEnv name -o SendEnv name ... to ssh? # can't pass environment to remote side, so prepend command with # variable declarations + + # cdist command prepended with variable assignments expects + # posix shell (bourne, bash) at the remote as user default shell. + # If remote user shell isn't poxis shell, but for e.g. csh/tcsh + # then these var assignments are not var assignments for this + # remote shell, it tries to execute it as a command and fails. + # So really do this by default: + # /bin/sh -c 'export ; command' + # so that constructed remote command isn't dependent on remote + # shell. Do this only if env is not None. env breaks this. + # Explicitly use /bin/sh, because var assignments assume poxis + # shell already. + # This leaves the posibility to write script that needs to be run + # remotely in e.g. csh and setting up CDIST_REMOTE_SHELL to e.g. + # /bin/csh will execute this script in the right way. if env: - remote_env = ["%s=%s" % item for item in env.items()] - cmd.extend(remote_env) - - cmd.extend(command) - + cmd.append("/bin/sh") + cmd.append("-c") + remote_env = [" export %s=%s;" % item for item in env.items()] + string_cmd = " ".join(remote_env) + " ".join(command) + cmd.append(string_cmd) + else: + cmd.extend(command) return self._run_command(cmd, env=env, return_output=return_output) def _run_command(self, command, env=None, return_output=False): diff --git a/cdist/test/exec/remote.py b/cdist/test/exec/remote.py index 8e7d408a..7d61b85c 100644 --- a/cdist/test/exec/remote.py +++ b/cdist/test/exec/remote.py @@ -39,7 +39,7 @@ class RemoteTestCase(test.CdistTestCase): user = getpass.getuser() remote_exec = "ssh -o User=%s -q" % user remote_copy = "scp -o User=%s -q" % user - self.remote = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + self.remote = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) def tearDown(self): shutil.rmtree(self.temp_dir) @@ -125,7 +125,7 @@ class RemoteTestCase(test.CdistTestCase): os.chmod(remote_exec_path, 0o755) remote_exec = remote_exec_path remote_copy = "echo" - r = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) self.assertEqual(r.run('/bin/true', return_output=True), "%s\n" % self.target_host) def test_run_script_target_host_in_env(self): @@ -135,8 +135,33 @@ class RemoteTestCase(test.CdistTestCase): os.chmod(remote_exec_path, 0o755) remote_exec = remote_exec_path remote_copy = "echo" - r = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", "/bin/true"]) self.assertEqual(r.run_script(script, return_output=True), "%s\n" % self.target_host) + + def test_run_script_with_env_target_host_in_env(self): + handle, script = self.mkstemp(dir=self.temp_dir) + with os.fdopen(handle, "w") as fd: + fd.writelines(["#!/bin/sh\n", 'if [ "$__object" ]; then echo $__object; else echo no_env; fi\n']) + os.chmod(script, 0o755) + handle, remote_exec_path = self.mkstemp(dir=self.temp_dir) + with os.fdopen(handle, 'w') as fd: + fd.writelines(["#!/bin/sh\n", 'shift; cmd=$1; shift; $cmd "$@"\n']) + os.chmod(remote_exec_path, 0o755) + remote_exec = remote_exec_path + remote_copy = "echo" + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) + output = r.run_script(script, return_output=True) + self.assertEqual(output, "no_env\n") + env = { + '__object': 'test_object', + } + output = r.run_script(script, env=env, return_output=True) + self.assertEqual(output, "test_object\n") + +if __name__ == '__main__': + import unittest + + unittest.main() From f55d00fe96dd7c1ab7dd1431784329ade9ac3da7 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 30 Mar 2016 12:43:59 +0200 Subject: [PATCH 16/18] checkbashisms --- .../conf/type/__firewalld_rule/explorer/rule | 1 + .../conf/type/__firewalld_rule/gencode-remote | 1 + .../conf/type/__iptables_apply/gencode-remote | 2 ++ cdist/conf/type/__iptables_apply/manifest | 1 + cdist/conf/type/__iptables_rule/manifest | 1 + .../type/__key_value/files/remote_script.sh | 2 ++ cdist/conf/type/__motd/gencode-remote | 2 ++ .../__package_zypper/explorer/pkg_version | 2 +- cdist/conf/type/__pacman_conf/manifest | 23 ++++++++++--------- .../type/__pacman_conf_integrate/manifest | 4 ++-- cdist/conf/type/__qemu_img/gencode-remote | 2 ++ cdist/conf/type/__qemu_img/manifest | 2 ++ .../conf/type/__start_on_boot/explorer/state | 2 +- .../conf/type/__start_on_boot/gencode-remote | 4 ++-- 14 files changed, 32 insertions(+), 17 deletions(-) diff --git a/cdist/conf/type/__firewalld_rule/explorer/rule b/cdist/conf/type/__firewalld_rule/explorer/rule index e9e1ebeb..5a0e0265 100644 --- a/cdist/conf/type/__firewalld_rule/explorer/rule +++ b/cdist/conf/type/__firewalld_rule/explorer/rule @@ -1,3 +1,4 @@ +#!/bin/sh # # 2015 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__firewalld_rule/gencode-remote b/cdist/conf/type/__firewalld_rule/gencode-remote index e184f5b3..8f1ba28a 100644 --- a/cdist/conf/type/__firewalld_rule/gencode-remote +++ b/cdist/conf/type/__firewalld_rule/gencode-remote @@ -1,3 +1,4 @@ +#!/bin/sh # # 2015 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__iptables_apply/gencode-remote b/cdist/conf/type/__iptables_apply/gencode-remote index 9cdf28cf..c15d4d7f 100644 --- a/cdist/conf/type/__iptables_apply/gencode-remote +++ b/cdist/conf/type/__iptables_apply/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh + if grep -q "^__file/etc/iptables.d/" "$__messages_in"; then echo /etc/init.d/iptables restart fi diff --git a/cdist/conf/type/__iptables_apply/manifest b/cdist/conf/type/__iptables_apply/manifest index a22901ba..3bb2d976 100644 --- a/cdist/conf/type/__iptables_apply/manifest +++ b/cdist/conf/type/__iptables_apply/manifest @@ -1,3 +1,4 @@ +#!/bin/sh # # 2013 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__iptables_rule/manifest b/cdist/conf/type/__iptables_rule/manifest index f02ab18b..13cec523 100644 --- a/cdist/conf/type/__iptables_rule/manifest +++ b/cdist/conf/type/__iptables_rule/manifest @@ -1,3 +1,4 @@ +#!/bin/sh # # 2013 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__key_value/files/remote_script.sh b/cdist/conf/type/__key_value/files/remote_script.sh index 282ba531..52b3f2de 100644 --- a/cdist/conf/type/__key_value/files/remote_script.sh +++ b/cdist/conf/type/__key_value/files/remote_script.sh @@ -1,3 +1,5 @@ +#!/bin/sh + export key="$(cat "$__object/parameter/key" 2>/dev/null \ || echo "$__object_id")" export state="$(cat "$__object/parameter/state")" diff --git a/cdist/conf/type/__motd/gencode-remote b/cdist/conf/type/__motd/gencode-remote index 2aa84902..bfd13b5e 100755 --- a/cdist/conf/type/__motd/gencode-remote +++ b/cdist/conf/type/__motd/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh +# # 2013 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. diff --git a/cdist/conf/type/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version index 7f203067..83bf6dab 100644 --- a/cdist/conf/type/__package_zypper/explorer/pkg_version +++ b/cdist/conf/type/__package_zypper/explorer/pkg_version @@ -42,7 +42,7 @@ case "$ptype" in zypper search --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true ;; *) - echo "unknown ptype in __package_zypper explorer" &>2 + echo "unknown ptype in __package_zypper explorer" >&2 exit 1 ;; esac diff --git a/cdist/conf/type/__pacman_conf/manifest b/cdist/conf/type/__pacman_conf/manifest index 19e232a7..903be087 100644 --- a/cdist/conf/type/__pacman_conf/manifest +++ b/cdist/conf/type/__pacman_conf/manifest @@ -42,11 +42,12 @@ contains_element() { MATCH=0 target=$1 - keys="${@:2}" + # keys="${@:2}" + shift - - for key in ${keys}; do - if [ "${key}" == "${target}" ]; then + # for key in ${keys}; do + for key in "$@"; do + if [ "${key}" = "${target}" ]; then MATCH=1 return 0 fi @@ -58,14 +59,14 @@ if [ "${file}" ]; then __file "${sec_path}/plain_file_${file}"\ --state exists --mode 666 - if [ "${state}" == "present" ]; then + if [ "${state}" = "present" ]; then require="__file/${sec_path}/plain_file_${file}" __key_value ${file}_${key}\ --file ${sec_path}/plain_file_${file} --key ${key} --value ${value} --delimiter ' = ' exit 0 - elif [ "${state}" == "absent" ]; then + elif [ "${state}" = "absent" ]; then require="__file/${sec_path}/plain_file_${file}" __key_value ${file}_${key}\ --state absent exit 0 @@ -76,7 +77,7 @@ if [ "${file}" ]; then fi fi -if [ "${section}" == "options" ]; then +if [ "${section}" = "options" ]; then __file "${sec_path}/${section}"\ --state exists --mode 666 --source - << eof @@ -87,10 +88,10 @@ eof contains_element "${key}" "${boolean_option_keys}" if [ "${MATCH}" -eq 1 ]; then - if [ "${value}" == "on" ]; then + if [ "${value}" = "on" ]; then require="__file/${sec_path}/${section}" __line ${key}_${value}\ --file ${sec_path}/${section} --line ${key} - elif [ "${value}" == "off" ]; then + elif [ "${value}" = "off" ]; then require="__file/${sec_path}/${section}" __line ${key}_${value}\ --file ${sec_path}/${section} --line ${key} --state absent fi @@ -111,7 +112,7 @@ else --state exists --mode 666 --source - << eof [${section}] eof - if [ "${state}" == "present" ]; then + if [ "${state}" = "present" ]; then #check if key is valid contains_element "${key}" "${allowed_repo_keys}" @@ -122,7 +123,7 @@ eof require="__file/${sec_path}/repo_${section}" __key_value ${section}_${key}\ --file ${sec_path}/repo_${section} --key ${key} --value ${value} --delimiter ' = ' - elif [ "${state}" == "absent" ]; then + elif [ "${state}" = "absent" ]; then require="__file/${sec_path}/repo_${section}" __key_value ${section}_${key}\ --state absent diff --git a/cdist/conf/type/__pacman_conf_integrate/manifest b/cdist/conf/type/__pacman_conf_integrate/manifest index 5f398c19..1d02f3b3 100644 --- a/cdist/conf/type/__pacman_conf_integrate/manifest +++ b/cdist/conf/type/__pacman_conf_integrate/manifest @@ -22,7 +22,7 @@ state=$(cat $__object/parameter/state 2>/dev/null) path="/etc/" -if [ "${state}" == "present" ]; then +if [ "${state}" = "present" ]; then __file /etc/pacman.conf\ --owner root --group root --mode 644 --source $__type/files/pacman.conf.cdist @@ -35,7 +35,7 @@ if [ "${state}" == "present" ]; then __file /etc/pacman.d/plain_file_empty_placeholder\ --owner root --group root --mode 644 -elif [ "${state}" == "absent" ]; then +elif [ "${state}" = "absent" ]; then __file /etc/pacman.conf\ --owner root --group root --mode 644 --source $__type/files/pacman.conf.pacman diff --git a/cdist/conf/type/__qemu_img/gencode-remote b/cdist/conf/type/__qemu_img/gencode-remote index 6e4bb4d0..bffedd26 100644 --- a/cdist/conf/type/__qemu_img/gencode-remote +++ b/cdist/conf/type/__qemu_img/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh +# ################################################################################ # State: absent is handled by manifest - we need only to do stuff if image is # not existing and state != absent diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest index bb2c9366..e0ff6e03 100644 --- a/cdist/conf/type/__qemu_img/manifest +++ b/cdist/conf/type/__qemu_img/manifest @@ -1,3 +1,5 @@ +#!/bin/sh +# ################################################################################ # Default settings # diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state index 1cad6602..2f94a521 100644 --- a/cdist/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -28,7 +28,7 @@ init=$("$__explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" name="$__object_id" -if [ "$init" == 'systemd' ]; then +if [ "$init" = 'systemd' ]; then # this handles ALL linux distros with systemd # e.g. archlinux, gentoo, new RHEL and SLES versions state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote index c8488e3a..8d3678d3 100644 --- a/cdist/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -34,7 +34,7 @@ name="$__object_id" case "$state_should" in present) - if [ "$init" == 'systemd' ]; then + if [ "$init" = 'systemd' ]; then # this handles ALL linux distros with systemd # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions echo "systemctl -q enable \"$name\"" @@ -85,7 +85,7 @@ case "$state_should" in ;; absent) - if [ "$init" == 'systemd' ]; then + if [ "$init" = 'systemd' ]; then # this handles ALL linux distros with systemd # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions echo "systemctl -q disable \"$name\"" From ee3e9a56f12016be5d8e6eb9914c897d38ab9529 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 31 Mar 2016 12:34:59 +0200 Subject: [PATCH 17/18] Remove commented old code. --- cdist/conf/type/__pacman_conf/manifest | 2 -- 1 file changed, 2 deletions(-) diff --git a/cdist/conf/type/__pacman_conf/manifest b/cdist/conf/type/__pacman_conf/manifest index 903be087..b9679577 100644 --- a/cdist/conf/type/__pacman_conf/manifest +++ b/cdist/conf/type/__pacman_conf/manifest @@ -42,10 +42,8 @@ contains_element() { MATCH=0 target=$1 - # keys="${@:2}" shift - # for key in ${keys}; do for key in "$@"; do if [ "${key}" = "${target}" ]; then MATCH=1 From de74b857478056cd8e7acb6c34d6862bffeb6cde Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 31 Mar 2016 13:21:35 +0200 Subject: [PATCH 18/18] Update changelog. --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index fa3e6f7d..bd0bc324 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,6 +2,9 @@ Changelog --------- next: + * Types: Remove bashisms in scripts (Darko Poljak) + * Core: Fix bug in remote command with environment (Darko Poljak) + * Core: Fix bug in local code execution (Darko Poljak) * Documentation: Fix spelling in manual pages (Dmitry Bogatov) * New type: __pacman_conf: Manage pacman.conf (Dominique Roux) * New type: __pacman_conf_integrate: cdist compatible pacman.conf (Dominique Roux)