diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init new file mode 100755 index 00000000..2693a0d3 --- /dev/null +++ b/cdist/conf/explorer/init @@ -0,0 +1,35 @@ +#!/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 . +# +# +# Returns the process name of pid 1 ( normaly the init system ) +# for example at linux this value is "init" or "systemd" in most cases +# + +uname_s="$(uname -s)" + +case "$uname_s" in + Linux|FreeBSD) + ps -o comm= -p 1 || true + ;; + *) + # return a empty string as unknown value + echo "" + ;; +esac 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/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 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..b9679577 100644 --- a/cdist/conf/type/__pacman_conf/manifest +++ b/cdist/conf/type/__pacman_conf/manifest @@ -42,11 +42,10 @@ contains_element() { MATCH=0 target=$1 - keys="${@:2}" + shift - - for key in ${keys}; do - if [ "${key}" == "${target}" ]; then + for key in "$@"; do + if [ "${key}" = "${target}" ]; then MATCH=1 return 0 fi @@ -58,14 +57,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 +75,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 +86,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 +110,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 +121,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 old mode 100755 new mode 100644 index 1906033c..2f94a521 --- 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..8d3678d3 --- 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 ;; *) diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri index bcad4ec8..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\>" | cut -d'|' -f 7 ) +echo $(zypper ls -u | awk 'BEGIN { FS = "[ ]+\\|[ ]+" } ; $4 == "Yes" && $NF == "'$uri'" {print $NF}') 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() 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() diff --git a/docs/changelog b/docs/changelog index a93a3e7f..b1acf329 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,6 +2,10 @@ Changelog --------- next: + * 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) + * 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) @@ -16,6 +20,7 @@ next: * Type __file: Add NetBSD support (Jonathan A. Kollasch) * Type __group: Add NetBSD support (Jonathan A. Kollasch) * Type __consul: Add new consul versions (Nico Schottelius) + * Type __apt_ppa: Do not install legacy package python-software-properties (Steven Armstrong) 3.1.13: 2015-05-16