From 6b0f8fba22a56e853b97706813e59e98963bc7a5 Mon Sep 17 00:00:00 2001 From: Jonas Weber Date: Wed, 3 Oct 2018 21:11:59 +0200 Subject: [PATCH 1/4] Remove unused variables (almost, found bugs?) Solves SC2034 references #540. --- cdist/conf/type/__apt_ppa/manifest | 2 -- cdist/conf/type/__block/manifest | 2 -- cdist/conf/type/__ccollect_source/gencode-remote | 1 - cdist/conf/type/__file/gencode-remote | 1 - cdist/conf/type/__firewalld_rule/gencode-remote | 1 - cdist/conf/type/__group/gencode-remote | 2 -- cdist/conf/type/__install_generate_fstab/gencode-local | 1 - cdist/conf/type/__install_mkfs/manifest | 8 +------- cdist/conf/type/__install_reboot/gencode-remote | 2 -- cdist/conf/type/__install_reboot/manifest | 6 ++++-- cdist/conf/type/__install_umount/manifest | 6 ++++-- cdist/conf/type/__jail_freebsd10/gencode-remote | 1 + cdist/conf/type/__jail_freebsd9/gencode-remote | 1 + cdist/conf/type/__pacman_conf_integrate/manifest | 2 -- cdist/conf/type/__postfix_master/manifest | 1 - cdist/conf/type/__qemu_img/manifest | 1 - cdist/conf/type/__rvm_gem/gencode-remote | 2 -- cdist/conf/type/__rvm_gemset/explorer/state | 3 --- cdist/conf/type/__rvm_ruby/gencode-remote | 1 - cdist/conf/type/__staged_file/gencode-local | 1 - cdist/conf/type/__staged_file/manifest | 4 ---- 21 files changed, 11 insertions(+), 38 deletions(-) diff --git a/cdist/conf/type/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest index e1af21bd..c6f4e876 100755 --- a/cdist/conf/type/__apt_ppa/manifest +++ b/cdist/conf/type/__apt_ppa/manifest @@ -18,8 +18,6 @@ # along with cdist. If not, see . # -name="$__object_id" - __package software-properties-common require="__package/software-properties-common" \ diff --git a/cdist/conf/type/__block/manifest b/cdist/conf/type/__block/manifest index 8fea3e83..726950d3 100755 --- a/cdist/conf/type/__block/manifest +++ b/cdist/conf/type/__block/manifest @@ -18,8 +18,6 @@ # along with cdist. If not, see . # - -file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")" prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id") suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id") text=$(cat "$__object/parameter/text") diff --git a/cdist/conf/type/__ccollect_source/gencode-remote b/cdist/conf/type/__ccollect_source/gencode-remote index 763f219e..c8892c9e 100755 --- a/cdist/conf/type/__ccollect_source/gencode-remote +++ b/cdist/conf/type/__ccollect_source/gencode-remote @@ -56,7 +56,6 @@ set_mode() { echo chmod $1 >> "$__messages_out" } -set_attributes= case "$state_should" in present|exists) # Note: Mode - needs to happen last as a chown/chgrp can alter mode by diff --git a/cdist/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote index 9dfd1833..6632935c 100755 --- a/cdist/conf/type/__file/gencode-remote +++ b/cdist/conf/type/__file/gencode-remote @@ -57,7 +57,6 @@ set_mode() { echo chmod $1 >> "$__messages_out" } -set_attributes= case "$state_should" in present|exists|pre-exists) # Note: Mode - needs to happen last as a chown/chgrp can alter mode by diff --git a/cdist/conf/type/__firewalld_rule/gencode-remote b/cdist/conf/type/__firewalld_rule/gencode-remote index 4c824d39..b9b930e7 100755 --- a/cdist/conf/type/__firewalld_rule/gencode-remote +++ b/cdist/conf/type/__firewalld_rule/gencode-remote @@ -19,7 +19,6 @@ # # -name="$__object_id" state_should="$(cat "$__object/parameter/state")" state_is="$(cat "$__object/explorer/rule")" diff --git a/cdist/conf/type/__group/gencode-remote b/cdist/conf/type/__group/gencode-remote index 68475178..033228c5 100755 --- a/cdist/conf/type/__group/gencode-remote +++ b/cdist/conf/type/__group/gencode-remote @@ -40,11 +40,9 @@ shorten_property() { if [ "$state" = "present" ]; then case "$os" in freebsd) - supported_add_properties="gid" supported_change_properties="gid" ;; *) - supported_add_properties="gid password system" supported_change_properties="gid password" ;; esac diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local index 5cc7d877..b5158a39 100755 --- a/cdist/conf/type/__install_generate_fstab/gencode-local +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -28,7 +28,6 @@ $__remote_exec $__target_host blkid > "$__object/files/blkid" for object in $(find "$__global/object/__install_mount" -type d -name "$__cdist_object_marker"); do device="$(cat "$object/parameter/device")" dir="$(cat "$object/parameter/dir")" - prefix="$(cat "$object/parameter/prefix")" type="$(cat "$object/parameter/type")" if [ -f "$object/parameter/options" ]; then options="$(cat "$object/parameter/options")" diff --git a/cdist/conf/type/__install_mkfs/manifest b/cdist/conf/type/__install_mkfs/manifest index eb65757f..b0a21dae 100755 --- a/cdist/conf/type/__install_mkfs/manifest +++ b/cdist/conf/type/__install_mkfs/manifest @@ -19,13 +19,7 @@ # # set defaults -if [ -f "$__object/parameter/device" ]; then - device="(cat "$__object/parameter/device")" -else +if [ ! -f "$__object/parameter/device" ]; then device="/$__object_id" echo "$device" > "$__object/parameter/device" fi - -type="(cat "$__object/parameter/type")" - -options="(cat "$__object/parameter/options")" diff --git a/cdist/conf/type/__install_reboot/gencode-remote b/cdist/conf/type/__install_reboot/gencode-remote index 00c04523..9a6322c1 100755 --- a/cdist/conf/type/__install_reboot/gencode-remote +++ b/cdist/conf/type/__install_reboot/gencode-remote @@ -18,8 +18,6 @@ # along with cdist. If not, see . # -options="$(cat "$__object/parameter/options")" - #echo "reboot $options" cat << DONE echo 1 > /proc/sys/kernel/sysrq diff --git a/cdist/conf/type/__install_reboot/manifest b/cdist/conf/type/__install_reboot/manifest index 02689d82..46a6356e 100755 --- a/cdist/conf/type/__install_reboot/manifest +++ b/cdist/conf/type/__install_reboot/manifest @@ -19,5 +19,7 @@ # # set defaults -options="$(cat "$__object/parameter/options" 2>/dev/null \ - || echo "" | tee "$__object/parameter/options")" +# TODO is this neccesary or should this be handled using the usual parameter/default workflow? +if [ ! -f "$__object/parameter/options" ]; then + touch "$__object/parameter/options" +fi diff --git a/cdist/conf/type/__install_umount/manifest b/cdist/conf/type/__install_umount/manifest index 42cd19bf..d900df1b 100755 --- a/cdist/conf/type/__install_umount/manifest +++ b/cdist/conf/type/__install_umount/manifest @@ -19,5 +19,7 @@ # # set defaults -target="$(cat "$__object/parameter/target" 2>/dev/null \ - || echo "/target" | tee "$__object/parameter/target")" +# TODO is this neccesary or should this be handled using the usual parameter/default workflow? +if [ ! -f "$__object/parameter/target" ]; then + echo "/target" > "$__object/parameter/target" +fi diff --git a/cdist/conf/type/__jail_freebsd10/gencode-remote b/cdist/conf/type/__jail_freebsd10/gencode-remote index d8bc5eb7..8ce77768 100755 --- a/cdist/conf/type/__jail_freebsd10/gencode-remote +++ b/cdist/conf/type/__jail_freebsd10/gencode-remote @@ -87,6 +87,7 @@ if [ $(expr "${ip}" : ".*, .*") -gt "0" ]; then SAVE_IFS="$IFS" IFS=", " for cur_ip in ${ip}; do + # TODO BUG? Why is cur_ip unused in the following line? # Just get the last IP address for SSH to listen on mgmt_ip=$(echo "${ip}" | cut '-d ' -f1) # In case using "ip netmask" format rather than CIDR done diff --git a/cdist/conf/type/__jail_freebsd9/gencode-remote b/cdist/conf/type/__jail_freebsd9/gencode-remote index d883dec4..c76bb014 100755 --- a/cdist/conf/type/__jail_freebsd9/gencode-remote +++ b/cdist/conf/type/__jail_freebsd9/gencode-remote @@ -92,6 +92,7 @@ if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then SAVE_IFS="$IFS" IFS=", " for cur_ip in ${ip}; do + # TODO BUG? Why is cur_ip unused in the following line? # Just get the last IP address for SSH to listen on mgmt_ip=$(echo "${ip}" | sed -E -e 's/^.*\|(.*)\/[0-9]+$/\1/') done diff --git a/cdist/conf/type/__pacman_conf_integrate/manifest b/cdist/conf/type/__pacman_conf_integrate/manifest index b26bca50..829fb34b 100755 --- a/cdist/conf/type/__pacman_conf_integrate/manifest +++ b/cdist/conf/type/__pacman_conf_integrate/manifest @@ -20,8 +20,6 @@ state=$(cat $__object/parameter/state 2>/dev/null) -path="/etc/" - if [ "${state}" = "present" ]; then __file /etc/pacman.conf\ --owner root --group root --mode 644 --source $__type/files/pacman.conf.cdist diff --git a/cdist/conf/type/__postfix_master/manifest b/cdist/conf/type/__postfix_master/manifest index 4991a13d..94b5044f 100755 --- a/cdist/conf/type/__postfix_master/manifest +++ b/cdist/conf/type/__postfix_master/manifest @@ -36,7 +36,6 @@ __postfix # Default to object_id service="$(cat "$__object/parameter/service" 2>/dev/null || echo "$__object_id")" -state="$(cat "$__object/parameter/state")" # NOTE: keep variables in sync in manifest,explorer,gencode-* prefix="#cdist:$__object_name" diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest index e7417389..55f3bf16 100755 --- a/cdist/conf/type/__qemu_img/manifest +++ b/cdist/conf/type/__qemu_img/manifest @@ -4,7 +4,6 @@ # Default settings # -format="$(cat "$__object/parameter/format")" state_should="$(cat "$__object/parameter/state")" diskimage="/$__object_id" diff --git a/cdist/conf/type/__rvm_gem/gencode-remote b/cdist/conf/type/__rvm_gem/gencode-remote index 1fe6e78e..9212de91 100755 --- a/cdist/conf/type/__rvm_gem/gencode-remote +++ b/cdist/conf/type/__rvm_gem/gencode-remote @@ -20,8 +20,6 @@ gem="$__object_id" gemset="$(cat "$__object/parameter/gemset")" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" state_should="$(cat "$__object/parameter/state")" diff --git a/cdist/conf/type/__rvm_gemset/explorer/state b/cdist/conf/type/__rvm_gemset/explorer/state index fa643a6e..d1462134 100755 --- a/cdist/conf/type/__rvm_gemset/explorer/state +++ b/cdist/conf/type/__rvm_gemset/explorer/state @@ -18,9 +18,6 @@ # along with cdist. If not, see . # -gemset="$__object_id" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f2)" user="$(cat "$__object/parameter/user")" if [ ! -e "~$user/.rvm/scripts/rvm" ] ; then diff --git a/cdist/conf/type/__rvm_ruby/gencode-remote b/cdist/conf/type/__rvm_ruby/gencode-remote index 9bbc6031..f2fd41ef 100755 --- a/cdist/conf/type/__rvm_ruby/gencode-remote +++ b/cdist/conf/type/__rvm_ruby/gencode-remote @@ -21,7 +21,6 @@ ruby="$__object_id" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" -default="$(cat "$__object/parameter/default" 2>/dev/null || true)" state_should="$(cat "$__object/parameter/state")" [ "$state_is" = "$state_should" ] && exit 0 diff --git a/cdist/conf/type/__staged_file/gencode-local b/cdist/conf/type/__staged_file/gencode-local index 18bf09f5..851970e8 100755 --- a/cdist/conf/type/__staged_file/gencode-local +++ b/cdist/conf/type/__staged_file/gencode-local @@ -23,7 +23,6 @@ destination="$__object_id" source="$(cat "$__object/parameter/source")" -cksum="$(cat "$__object/parameter/cksum")" stage_dir="$(cat "$__object/parameter/stage-dir")" state="$(cat "$__object/parameter/state")" fetch_command="$(cat "$__object/parameter/fetch-command")" diff --git a/cdist/conf/type/__staged_file/manifest b/cdist/conf/type/__staged_file/manifest index 1654e1d9..c8e1fbbb 100755 --- a/cdist/conf/type/__staged_file/manifest +++ b/cdist/conf/type/__staged_file/manifest @@ -19,11 +19,7 @@ # destination="$__object_id" -source="$(cat "$__object/parameter/source")" -cksum="$(cat "$__object/parameter/cksum")" stage_dir="$(cat "$__object/parameter/stage-dir")" -state="$(cat "$__object/parameter/state")" -fetch_command="$(cat "$__object/parameter/fetch-command")" stage_file="${stage_dir}/${destination}" set -- "/${destination}" From b3f4d3849a687a1795302cb25d3c50c251a4417c Mon Sep 17 00:00:00 2001 From: Jonas Weber Date: Thu, 4 Oct 2018 13:34:11 +0200 Subject: [PATCH 2/4] Fix __install_umount target parameter --- cdist/conf/type/__install_umount/manifest | 25 ------------------- .../__install_umount/parameter/default/target | 1 + .../type/__install_umount/parameter/optional | 1 + 3 files changed, 2 insertions(+), 25 deletions(-) delete mode 100755 cdist/conf/type/__install_umount/manifest create mode 100644 cdist/conf/type/__install_umount/parameter/default/target create mode 100644 cdist/conf/type/__install_umount/parameter/optional diff --git a/cdist/conf/type/__install_umount/manifest b/cdist/conf/type/__install_umount/manifest deleted file mode 100755 index d900df1b..00000000 --- a/cdist/conf/type/__install_umount/manifest +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -e -# -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# - -# set defaults -# TODO is this neccesary or should this be handled using the usual parameter/default workflow? -if [ ! -f "$__object/parameter/target" ]; then - echo "/target" > "$__object/parameter/target" -fi diff --git a/cdist/conf/type/__install_umount/parameter/default/target b/cdist/conf/type/__install_umount/parameter/default/target new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/cdist/conf/type/__install_umount/parameter/default/target @@ -0,0 +1 @@ +/target diff --git a/cdist/conf/type/__install_umount/parameter/optional b/cdist/conf/type/__install_umount/parameter/optional new file mode 100644 index 00000000..eb5a316c --- /dev/null +++ b/cdist/conf/type/__install_umount/parameter/optional @@ -0,0 +1 @@ +target From 352679386dc9acd18b7e98de0dfb3d2b8a75b81c Mon Sep 17 00:00:00 2001 From: Jonas Weber Date: Thu, 4 Oct 2018 13:36:45 +0200 Subject: [PATCH 3/4] Drop unused options parameter in __install_reboot --- cdist/conf/type/__install_reboot/man.rst | 3 +-- cdist/conf/type/__install_reboot/manifest | 25 ----------------------- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100755 cdist/conf/type/__install_reboot/manifest diff --git a/cdist/conf/type/__install_reboot/man.rst b/cdist/conf/type/__install_reboot/man.rst index ecf78ca7..9a53b37a 100644 --- a/cdist/conf/type/__install_reboot/man.rst +++ b/cdist/conf/type/__install_reboot/man.rst @@ -18,8 +18,7 @@ None OPTIONAL PARAMETERS ------------------- -options - options to pass to the reboot command. e.g. -f +None EXAMPLES diff --git a/cdist/conf/type/__install_reboot/manifest b/cdist/conf/type/__install_reboot/manifest deleted file mode 100755 index 46a6356e..00000000 --- a/cdist/conf/type/__install_reboot/manifest +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -e -# -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# - -# set defaults -# TODO is this neccesary or should this be handled using the usual parameter/default workflow? -if [ ! -f "$__object/parameter/options" ]; then - touch "$__object/parameter/options" -fi From 23debd5b6f27bcafd6b91149af9280f4398016df Mon Sep 17 00:00:00 2001 From: Jonas Weber Date: Thu, 4 Oct 2018 19:21:59 +0200 Subject: [PATCH 4/4] Use cur_ip in jail for freebsd --- cdist/conf/type/__jail_freebsd10/gencode-remote | 3 +-- cdist/conf/type/__jail_freebsd9/gencode-remote | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__jail_freebsd10/gencode-remote b/cdist/conf/type/__jail_freebsd10/gencode-remote index 8ce77768..5be04bc6 100755 --- a/cdist/conf/type/__jail_freebsd10/gencode-remote +++ b/cdist/conf/type/__jail_freebsd10/gencode-remote @@ -87,9 +87,8 @@ if [ $(expr "${ip}" : ".*, .*") -gt "0" ]; then SAVE_IFS="$IFS" IFS=", " for cur_ip in ${ip}; do - # TODO BUG? Why is cur_ip unused in the following line? # Just get the last IP address for SSH to listen on - mgmt_ip=$(echo "${ip}" | cut '-d ' -f1) # In case using "ip netmask" format rather than CIDR + mgmt_ip=$(echo "${cur_ip}" | cut '-d ' -f1) # In case using "ip netmask" format rather than CIDR done IFS="$SAVE_IFS" else diff --git a/cdist/conf/type/__jail_freebsd9/gencode-remote b/cdist/conf/type/__jail_freebsd9/gencode-remote index c76bb014..177bdf74 100755 --- a/cdist/conf/type/__jail_freebsd9/gencode-remote +++ b/cdist/conf/type/__jail_freebsd9/gencode-remote @@ -92,9 +92,8 @@ if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then SAVE_IFS="$IFS" IFS=", " for cur_ip in ${ip}; do - # TODO BUG? Why is cur_ip unused in the following line? # Just get the last IP address for SSH to listen on - mgmt_ip=$(echo "${ip}" | sed -E -e 's/^.*\|(.*)\/[0-9]+$/\1/') + mgmt_ip=$(echo "${cur_ip}" | sed -E -e 's/^.*\|(.*)\/[0-9]+$/\1/') done IFS="$SAVE_IFS" else