From f55d00fe96dd7c1ab7dd1431784329ade9ac3da7 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 30 Mar 2016 12:43:59 +0200 Subject: [PATCH 1/2] 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 2/2] 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