Compare commits

...

12 Commits

Author SHA1 Message Date
Darko Poljak ecc1dccd03 quoting; posix sed; 2018-09-30 14:45:47 +02:00
Darko Poljak 9e0cfd5df5 Fix vim typo. 2018-09-30 14:45:47 +02:00
Darko Poljak 4bec22d726 Revert changes in for loop because param value is changed. 2018-09-30 14:45:47 +02:00
Darko Poljak 33a0e05e3d Revert changes in for loop because param value is changed. 2018-09-30 14:45:47 +02:00
Darko Poljak 1388487199 Clean quotes; su - -> su -l 2018-09-30 14:45:47 +02:00
Darko Poljak 62f1e1db00 Applying uqam-fob's suggestions. 2018-09-30 14:43:39 +02:00
Darko Poljak b55520e987 Applying uqam-fob's suggestions. 2018-09-30 14:43:39 +02:00
Darko Poljak 775d3dfc2c shellcheck fixes 2018-09-30 14:43:07 +02:00
Darko Poljak 309315910e Add shellcheck makefile target. 2018-09-30 14:42:38 +02:00
Darko Poljak 6d0e1a2e73 --tmpdir -> TMPDIR env var 2018-09-30 14:42:38 +02:00
Darko Poljak 3759a37fbd Fix tr reading from file. 2018-09-30 14:42:38 +02:00
Darko Poljak b371c42d53 shellcheck 2018-09-30 14:42:37 +02:00
125 changed files with 412 additions and 379 deletions

View File

@ -39,6 +39,8 @@ PYTHON_VERSION=cdist/version.py
SPHINXM=make -C $(DOCS_SRC_DIR) man
SPHINXH=make -C $(DOCS_SRC_DIR) html
SPHINXC=make -C $(DOCS_SRC_DIR) clean
SHELLCHECKCMD=shellcheck -s sh -f gcc -x -e SC2154,SC1091
################################################################################
# Manpages
#
@ -253,3 +255,22 @@ test-remote:
pep8:
$(helper) $@
shellcheck-global-explorers:
@find cdist/conf/explorer -type f -exec $(SHELLCHECKCMD) {} + || exit 0
shellcheck-manifests:
@find cdist/conf/type -type f -name manifest -exec $(SHELLCHECKCMD) {} + || exit 0
shellcheck-local-gencodes:
@find cdist/conf/type -type f -name gencode-local -exec $(SHELLCHECKCMD) {} + || exit 0
shellcheck-remote-gencodes:
@find cdist/conf/type -type f -name gencode-remote -exec $(SHELLCHECKCMD) {} + || exit 0
shellcheck-gencodes: shellcheck-local-gencodes shellcheck-remote-gencodes
shellcheck-types: shellcheck-manifests shellcheck-gencodes
shellcheck: shellcheck-global-explorers shellcheck-types

View File

@ -25,13 +25,13 @@
os=$("$__explorer/os")
case "$os" in
"macosx")
echo "$(sysctl -n hw.physicalcpu)"
sysctl -n hw.physicalcpu
;;
*)
if [ -r /proc/cpuinfo ]; then
cores="$(grep "core id" /proc/cpuinfo | sort | uniq | wc -l)"
if [ ${cores} -eq 0 ]; then
if [ "${cores}" -eq 0 ]; then
cores="1"
fi
echo "$cores"

View File

@ -25,14 +25,14 @@
os=$("$__explorer/os")
case "$os" in
"macosx")
echo "$(system_profiler SPHardwareDataType | grep "Number of Processors" | awk -F': ' '{print $2}')"
system_profiler SPHardwareDataType | grep "Number of Processors" | awk -F ': ' '/Number of Processors/ {print $2}'
;;
*)
if [ -r /proc/cpuinfo ]; then
sockets="$(grep "physical id" /proc/cpuinfo | sort | uniq | wc -l)"
if [ ${sockets} -eq 0 ]; then
sockets="$(cat /proc/cpuinfo | grep "processor" | wc -l)"
sockets=$(grep "physical id" /proc/cpuinfo | sort -u | wc -l)
if [ "${sockets}" -eq 0 ]; then
sockets=$(grep -cE "^processor\s+:" /proc/cpuinfo)
fi
echo "${sockets}"
fi

View File

@ -1,2 +1,2 @@
cd /dev
cd /dev || exit 0
echo sd? hd? vd?

View File

@ -20,7 +20,7 @@
#
set +e
case "$($__explorer/os)" in
case "$("${__explorer}"/os)" in
openwrt)
(. /etc/openwrt_release && echo "$DISTRIB_CODENAME")
;;

View File

@ -20,7 +20,7 @@
#
set +e
case "$($__explorer/os)" in
case "$("${__explorer}"/os)" in
openwrt)
(. /etc/openwrt_release && echo "$DISTRIB_DESCRIPTION")
;;

View File

@ -20,7 +20,7 @@
#
set +e
case "$($__explorer/os)" in
case "$("${__explorer}"/os)" in
openwrt)
(. /etc/openwrt_release && echo "$DISTRIB_ID")
;;

View File

@ -20,7 +20,7 @@
#
set +e
case "$($__explorer/os)" in
case "$("${__explorer}"/os)" in
openwrt)
(. /etc/openwrt_release && echo "$DISTRIB_RELEASE")
;;

View File

@ -22,6 +22,6 @@
#
#
if command -v uname 2>&1 >/dev/null; then
if command -v uname > /dev/null 2>&1; then
uname -m
fi

View File

@ -22,13 +22,13 @@
# FIXME: other system types (not linux ...)
if [ -d "/proc/vz" -a ! -d "/proc/bc" ]; then
if [ -d "/proc/vz" ] && [ ! -d "/proc/bc" ]; then
echo openvz
exit
fi
if [ -e "/proc/1/environ" ] &&
cat "/proc/1/environ" | tr '\000' '\n' | grep -Eiq '^container='; then
tr '\000' '\n' < "/proc/1/environ" | grep -Eiq '^container='; then
echo lxc
exit
fi

View File

@ -22,7 +22,7 @@
#
#
case "$($__explorer/os)" in
case "$("${__explorer}"/os)" in
amazon)
cat /etc/system-release
;;

View File

@ -34,9 +34,9 @@ fi
case "$state_should" in
present)
keyserver="$(cat "$__object/parameter/keyserver")"
echo "apt-key adv --keyserver \"$keyserver\" --recv-keys \"$keyid\""
echo "apt-key adv --keyserver '$keyserver' --recv-keys '$keyid'"
;;
absent)
echo "apt-key del \"$keyid\""
echo "apt-key del '$keyid'"
;;
esac

View File

@ -29,9 +29,9 @@ fi
case "$state_should" in
present)
echo add-apt-repository \"$name\"
echo "add-apt-repository '$name'"
;;
absent)
echo remove-apt-repository \"$name\"
echo "remove-apt-repository '$name'"
;;
esac

View File

@ -18,7 +18,7 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
name="$__object_id"
# name="$__object_id"
__package software-properties-common

View File

@ -19,7 +19,7 @@
#
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
# 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")

View File

@ -42,21 +42,20 @@ get_current_value() {
}
set_group() {
echo chgrp \"$1\" \"$destination\"
echo chgrp $1 >> "$__messages_out"
echo "chgrp '$1' '$destination'"
echo "chgrp $1" >> "$__messages_out"
}
set_owner() {
echo chown \"$1\" \"$destination\"
echo chown $1 >> "$__messages_out"
echo "chown '$1' '$destination'"
echo "chown $1" >> "$__messages_out"
}
set_mode() {
echo chmod \"$1\" \"$destination\"
echo chmod $1 >> "$__messages_out"
echo "chmod '$1' '$destination'"
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
@ -67,11 +66,11 @@ case "$state_should" in
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
fi
value_is="$(get_current_value "$attribute" "$value_should")"
if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
if [ -f "$__object/files/set-attributes" ] || [ "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi
@ -81,7 +80,7 @@ case "$state_should" in
absent)
if [ "$type" = "file" ]; then
echo rm -f \"$destination\"
echo "rm -f '$destination'"
echo remove >> "$__messages_out"
fi
;;

View File

@ -22,7 +22,7 @@ name="$__object_id"
state="$(cat "$__object/parameter/state")"
source="$(cat "$__object/parameter/source")"
destination="$(cat "$__object/parameter/destination")"
ccollectconf="$(cat "$__object/parameter/ccollectconf" | sed 's,/$,,')"
ccollectconf="$(sed -E 's,/+$,,' "$__object/parameter/ccollectconf")"
sourcedir="$ccollectconf/sources"
basedir="$sourcedir/$name"

View File

@ -66,7 +66,7 @@ require="__directory/etc/consul" \
__directory "$conf_dir" \
--owner root --group "$group" --mode 750 --state "$state"
if [ -f "$__object/parameter/ca-file-source" -o -f "$__object/parameter/cert-file-source" -o -f "$__object/parameter/key-file-source" ]; then
if [ -f "$__object/parameter/ca-file-source" ] || [ -f "$__object/parameter/cert-file-source" ] || [ -f "$__object/parameter/key-file-source" ]; then
# create directory for ssl certs
require="__directory/etc/consul" \
__directory /etc/consul/ssl \

View File

@ -40,7 +40,7 @@ if [ ! -f "$__object/parameter/interval" ]; then
fi
done
fi
if [ -f "$__object/parameter/docker-container-id" -a ! -f "$__object/parameter/script" ]; then
if [ -f "$__object/parameter/docker-container-id" ] && [ ! -f "$__object/parameter/script" ]; then
echo "When using --docker-container-id you must also define --script." >&2
exit 1
fi

View File

@ -24,15 +24,15 @@ conf_file="service_${name}.json"
state="$(cat "$__object/parameter/state")"
# Sanity checks
if [ -f "$__object/parameter/check-script" -a -f "$__object/parameter/check-ttl" ]; then
if [ -f "$__object/parameter/check-script" ] && [ -f "$__object/parameter/check-ttl" ]; then
echo "Use either --check-script together with --check-interval OR --check-ttl, but not both" >&2
exit 1
fi
if [ -f "$__object/parameter/check-script" -a ! -f "$__object/parameter/check-interval" ]; then
if [ -f "$__object/parameter/check-script" ] && [ ! -f "$__object/parameter/check-interval" ]; then
echo "When using --check-script you must also define --check-interval" >&2
exit 1
fi
if [ -f "$__object/parameter/check-http" -a ! -f "$__object/parameter/check-interval" ]; then
if [ -f "$__object/parameter/check-http" ] && [ ! -f "$__object/parameter/check-interval" ]; then
echo "When using --check-http you must also define --check-interval" >&2
exit 1
fi

View File

@ -26,11 +26,11 @@ template_dir="/etc/consul-template/template"
require=""
# Sanity checks
if [ -f "$__object/parameter/source" -a -f "$__object/parameter/source-file" ]; then
if [ -f "$__object/parameter/source" ] && [ -f "$__object/parameter/source-file" ]; then
echo "Use either --source OR --source-file, but not both." >&2
exit 1
fi
if [ ! -f "$__object/parameter/source" -a ! -f "$__object/parameter/source-file" ]; then
if [ ! -f "$__object/parameter/source" ] && [ ! -f "$__object/parameter/source-file" ]; then
echo "Either --source OR --source-file must be given." >&2
exit 1
fi

View File

@ -25,7 +25,7 @@ conf_file="watch_${watch_type}_${__object_id}.json"
state="$(cat "$__object/parameter/state")"
# Sanity checks
if [ -f "$__object/parameter/filter-service" -a -f "$__object/parameter/filter-state" ]; then
if [ -f "$__object/parameter/filter-service" ] && [ -f "$__object/parameter/filter-state" ]; then
echo "Use either --filter-service or --filter-state but not both." >&2
exit 1
fi

View File

@ -24,7 +24,7 @@ user="$(cat "$__object/parameter/user")"
if [ -f "$__object/parameter/raw_command" ]; then
command="$(cat "$__object/parameter/command")"
crontab -u $user -l 2>/dev/null | grep "^$command\$" || true
crontab -u "$user" -l 2>/dev/null | grep "^$command\$" || true
else
crontab -u $user -l 2>/dev/null | grep "# $name\$" || true
crontab -u "$user" -l 2>/dev/null | grep "# $name\$" || true
fi

View File

@ -60,7 +60,7 @@ prefix="#cdist:__cron/$__object_id"
suffix="#/cdist:__cron/$__object_id"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$"
cat << DONE
crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
crontab -u '$user' -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
triggered=1
@ -73,24 +73,30 @@ crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix"
print
}
}
' | crontab -u $user -
' | crontab -u '$user' -
DONE
case "$state_should" in
present)
# if we insert new entry, filter also all entrys out with the same id
echo "("
echo "crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" | grep -v \"# $name\\$\" 2>/dev/null || true"
echo "echo '$entry'"
echo ") | crontab -u $user -"
cat <<EOF
(
crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' | grep -v '# $name\\$' 2>/dev/null || true
echo '$entry'
) | crontab -u '$user' -
EOF
;;
absent)
if [ -f "$__object/parameter/raw_command" ]; then
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"^$entry\\$\" | crontab -u $user -"
cat <<EOF
( crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\
grep -v '^$entry\\$' | crontab -u '$user' -
EOF
else
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"# $name\\$\" | crontab -u $user -"
cat <<EOF
( crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\
grep -v '# $name\\$' | crontab -u '$user' -
EOF
fi
;;
esac

View File

@ -3,8 +3,8 @@
pkg=$(cat "$__object/parameter/from-package")
servicedir=$(cat "$__object/parameter/servicedir")
__package $pkg
__directory $servicedir --mode 700
__package "$pkg"
__directory "$servicedir" --mode 700
os=$(cat "$__global/explorer/os")
init=$(cat "$__global/explorer/init")

View File

@ -25,14 +25,14 @@ badusage() {
[ -z "$run$runfile" ] && badusage
[ -n "$run" ] && [ -n "$runfile" ] && badusage
__directory $servicedir/$name/log/main --parents
__directory "$servicedir/$name/log/main" --parents
echo "$RUN_PREFIX$run" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/run" \
--onchange "svc -t '$servicedir/$name' 2>/dev/null" \
--mode 755 \
--source "${runfile:--}"
echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file $servicedir/$name/log/run \
echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/log/run" \
--onchange "svc -t '$servicedir/$name/log' 2>/dev/null" \
--mode 755 \
--source "-"

View File

@ -57,18 +57,18 @@ get_current_value() {
}
set_group() {
echo chgrp $recursive \"$1\" \"$destination\"
echo chgrp $recursive $1 >> "$__messages_out"
echo "chgrp '$recursive' '$1' '$destination'"
echo "chgrp $recursive $1" >> "$__messages_out"
}
set_owner() {
echo chown $recursive \"$1\" \"$destination\"
echo chown $recursive $1 >> "$__messages_out"
echo "chown '$recursive' '$1' '$destination'"
echo "chown $recursive $1" >> "$__messages_out"
}
set_mode() {
echo chmod $recursive \"$1\" \"$destination\"
echo chmod $recursive $1 >> "$__messages_out"
echo "chmod '$recursive' '$1' '$destination'"
echo "chmod $recursive $1" >> "$__messages_out"
}
case "$state_should" in
@ -78,10 +78,10 @@ case "$state_should" in
if [ "$type" != "none" ]; then
# our destination is not a directory, remove whatever is there
# and then create our directory and set all attributes
echo rm -f "\"$destination\""
echo "rm -f '$destination'"
echo "remove non directory" >> "$__messages_out"
fi
echo "mkdir $mkdiropt \"$destination\""
echo "mkdir $mkdiropt '$destination'"
echo "create" >> "$__messages_out"
fi
@ -94,7 +94,7 @@ case "$state_should" in
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
fi
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
@ -105,7 +105,7 @@ case "$state_should" in
;;
absent)
if [ "$type" = "directory" ]; then
echo rm -rf \"$destination\"
echo "rm -rf '$destination'"
echo remove >> "$__messages_out"
fi
;;

View File

@ -22,10 +22,10 @@
version="$(cat "$__object/parameter/version")"
state="$(cat "$__object/parameter/state")"
if [ ${state} = "present" ]; then
if [ "${state}" = "present" ]; then
# Download docker-compose file
echo 'curl -L "https://github.com/docker/compose/releases/download/'${version}'/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose'
echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose'
echo "curl -L 'https://github.com/docker/compose/releases/download/${version}/docker-compose-$(uname -s)-$(uname -m)' -o /tmp/docker-compose"
echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose'
# Change permissions
echo 'chmod +x /usr/local/bin/docker-compose'
fi

View File

@ -22,10 +22,10 @@
state="$(cat "$__object/parameter/state")"
# Needed packages
if [ ${state} = "present" ]; then
if [ "${state}" = "present" ]; then
__docker
__package curl
elif [ ${state} = "absent" ]; then
elif [ "${state}" = "absent" ]; then
__file /usr/local/bin/docker-compose --state absent
else
echo "Unknown state: ${state}" >&2

View File

@ -23,7 +23,7 @@ destination="/$__object_id"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
[ "$state_should" = "exists" -a "$type" = "file" ] && exit 0 # nothing to do
[ "$state_should" = "exists" ] && [ "$type" = "file" ] && exit 0 # nothing to do
if [ "$state_should" = "pre-exists" ]; then
if [ -f "$__object/parameter/source" ]; then
@ -41,7 +41,7 @@ fi
upload_file=
create_file=
if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
if [ "$state_should" = "present" ] || [ "$state_should" = "exists" ]; then
if [ ! -f "$__object/parameter/source" ]; then
remote_stat="$(cat "$__object/explorer/stat")"
if [ -z "$remote_stat" ]; then
@ -54,7 +54,7 @@ if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
source="$__object/stdin"
fi
if [ ! -f "$source" ]; then
echo "Source \"$source\" does not exist." >&2
echo "Source '$source' does not exist." >&2
exit 1
else
if [ "$type" != "file" ]; then
@ -70,7 +70,7 @@ if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
fi
fi
fi
if [ "$create_file" -o "$upload_file" ]; then
if [ "$create_file" ] || [ "$upload_file" ]; then
# tell gencode-remote that we created or uploaded a file and that it must
# set all attributes no matter what the explorer retreived
mkdir "$__object/files"
@ -84,7 +84,7 @@ DONE
if [ "$upload_file" ]; then
echo upload >> "$__messages_out"
# IPv6 fix
if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$')
if echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$'
then
my_target_host="[${__target_host}]"
else
@ -96,7 +96,7 @@ DONE
fi
# move uploaded file into place
cat << DONE
$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\""
$__remote_exec $__target_host "rm -rf '$destination'; mv \"\$destination_upload\" '$destination'"
DONE
fi
fi

View File

@ -43,21 +43,20 @@ get_current_value() {
}
set_group() {
echo chgrp \"$1\" \"$destination\"
echo chgrp $1 >> "$__messages_out"
echo "chgrp '$1' '$destination'"
echo "chgrp $1" >> "$__messages_out"
}
set_owner() {
echo chown \"$1\" \"$destination\"
echo chown $1 >> "$__messages_out"
echo "chown '$1' '$destination'"
echo "chown $1" >> "$__messages_out"
}
set_mode() {
echo chmod \"$1\" \"$destination\"
echo chmod $1 >> "$__messages_out"
echo "chmod '$1' '$destination'"
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
@ -68,11 +67,11 @@ case "$state_should" in
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
fi
value_is="$(get_current_value "$attribute" "$value_should")"
if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
if [ -f "$__object/files/set-attributes" ] || [ "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi
@ -82,7 +81,7 @@ case "$state_should" in
absent)
if [ "$type" = "file" ]; then
echo rm -f \"$destination\"
echo "rm -f '$destination'"
echo remove >> "$__messages_out"
fi
;;

View File

@ -25,7 +25,7 @@ chain="$(cat "$__object/parameter/chain")"
priority="$(cat "$__object/parameter/priority")"
rule="$(cat "$__object/parameter/rule")"
if firewall-cmd --permanent --direct --query-rule "$protocol" "$table" "$chain" "$priority" $rule >/dev/null; then
if firewall-cmd --permanent --direct --query-rule "$protocol" "$table" "$chain" "$priority" "$rule" >/dev/null; then
echo present
else
echo absent

View File

@ -19,7 +19,7 @@
#
#
name="$__object_id"
# name="$__object_id"
state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/rule")"
@ -33,13 +33,13 @@ rule="$(cat "$__object/parameter/rule")"
case "$state_should" in
present)
echo firewall-cmd --quiet --permanent --direct --add-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule
echo firewall-cmd --quiet --direct --add-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule
echo "firewall-cmd --quiet --permanent --direct --add-rule '$protocol' '$table' '$chain' '$priority' $rule"
echo "firewall-cmd --quiet --direct --add-rule '$protocol' '$table' '$chain' '$priority' $rule"
;;
absent)
echo firewall-cmd --quiet --permanent --direct --remove-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule
echo firewall-cmd --quiet --direct --remove-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule
echo "firewall-cmd --quiet --permanent --direct --remove-rule '$protocol' '$table' '$chain' '$priority' $rule"
echo "firewall-cmd --quiet --direct --remove-rule '$protocol' '$table' '$chain' '$priority' $rule"
;;
*)
echo "Unknown state $state_should" >&2

View File

@ -42,16 +42,16 @@ 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 \"$cmd\" \"$name\""
echo "systemctl '$cmd' '$name'"
else
case "$os" in
debian)
case "$os_version" in
[1-7]*)
echo "service \"$name\" \"$cmd\""
echo "service '$name' '$cmd'"
;;
8*)
echo "systemctl \"$cmd\" \"$name\""
echo "systemctl '$cmd' '$name'"
;;
*)
echo "Unsupported version $os_version of $os" >&2
@ -61,19 +61,19 @@ else
;;
gentoo)
echo service \"$name\" \"$cmd\"
echo "service '$name' '$cmd'"
;;
amazon|scientific|centos|fedora|owl|redhat|suse)
echo service \"$name\" \"$cmd\"
echo "service '$name' '$cmd'"
;;
openwrt)
echo "/etc/init.d/\"$name\" \"$cmd\""
echo "'/etc/init.d/$name' '$cmd'"
;;
ubuntu)
echo "service \"$name\" \"$cmd\""
echo "service '$name' '$cmd'"
;;
*)

View File

@ -2,4 +2,4 @@
destination="/$__object_id/.git"
stat --print "%G" ${destination} 2>/dev/null || exit 0
stat --print "%G" "${destination}" 2>/dev/null || exit 0

View File

@ -2,4 +2,4 @@
destination="/$__object_id/.git"
stat --print "%U" ${destination} 2>/dev/null || exit 0
stat --print "%U" "${destination}" 2>/dev/null || exit 0

View File

@ -35,10 +35,10 @@ owner="$(cat "$__object/parameter/owner")"
group="$(cat "$__object/parameter/group")"
mode="$(cat "$__object/parameter/mode")"
[ "$state_should" = "$state_is" -a \
"$owner" = "$owner_is" -a \
"$group" = "$group_is" -a \
-n "$mode" ] && exit 0
[ "$state_should" = "$state_is" ] && \
[ "$owner" = "$owner_is" ] && \
[ "$group" = "$group_is" ] && \
[ -n "$mode" ] && exit 0
case $state_should in
present)
@ -46,8 +46,8 @@ case $state_should in
if [ "$state_should" != "$state_is" ]; then
echo git clone --quiet --branch "$branch" "$source" "$destination"
fi
if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \
\( -n "$group" -a "$group_is" != "$group" \) ]; then
if ([ -n "$owner" ] && [ "$owner_is" != "$owner" ]) || \
([ -n "$group" ] && [ "$group_is" != "$group" ]); then
echo chown -R "${owner}:${group}" "$destination"
fi
if [ -n "$mode" ]; then

View File

@ -2,7 +2,7 @@
version=$(cat "$__object/parameter/version")
kernel_name=$(cat "$__global/explorer/kernel_name" | tr '[:upper:]' '[:lower:]')
kernel_name=$(tr '[:upper:]' '[:lower:]' < "$__global/explorer/kernel_name")
machine=$(cat "$__global/explorer/machine")
case $machine in
x86_64|amd64)

View File

@ -1,7 +1,7 @@
#!/bin/sh -e
os=$(cat $__global/explorer/os)
os_version=$(cat $__global/explorer/os_version)
os="$(cat "$__global/explorer/os")"
os_version="$(cat "$__global/explorer/os_version")"
case $os in
debian|devuan)

View File

@ -22,7 +22,7 @@
#
name=$__object_id
os="$($__explorer/os)"
os="$("${__explorer}"/os)"
case "$os" in
"freebsd"|"netbsd")

View File

@ -30,9 +30,9 @@ state="$(cat "$__object/parameter/state")"
# Use short option names for portability
shorten_property() {
case "$1" in
gid) echo "-g";;
password) echo "-p";;
system) echo "-r";;
gid) printf -- "-g\n";;
password) printf -- "-p\n";;
system) printf -- "-r\n";;
esac
}
@ -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
@ -63,8 +61,8 @@ if [ "$state" = "present" ]; then
;;
esac
if [ "$new_value" != "$current_value" ]; then
set -- "$@" "$(shorten_property $property)" \'$new_value\'
echo change $property $new_value $current_value >> "$__messages_out"
set -- "$@" "$(shorten_property "$property")" \'"$new_value"\'
echo change "$property" "$new_value" "$current_value" >> "$__messages_out"
fi
fi
done
@ -83,9 +81,9 @@ if [ "$state" = "present" ]; then
new_value="$(cat "$__object/parameter/$property")"
if [ -z "$new_value" ]; then
# Boolean parameters have no value
set -- "$@" "$(shorten_property $property)"
set -- "$@" "$(shorten_property "$property")"
else
set -- "$@" "$(shorten_property $property)" \'$new_value\'
set -- "$@" "$(shorten_property "$property")" \'"$new_value"\'
fi
fi
done

View File

@ -22,7 +22,7 @@
if [ -f "$__object/parameter/name" ]; then
name_should="$(cat "$__object/parameter/name")"
else
name_should="$(echo "${__target_host%%.*}")"
name_should="${__target_host%%.*}"
fi
os=$(cat "$__global/explorer/os")
@ -36,12 +36,12 @@ has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
#
case "$os" in
archlinux|debian|suse|ubuntu|devuan|coreos)
if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
if [ "$name_config" = "$name_should" ] && [ "$name_running" = "$name_should" ]; then
exit 0
fi
;;
scientific|centos|freebsd|openbsd)
if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then
if [ "$name_sysconfig" = "$name_should" ] && [ "$name_running" = "$name_should" ]; then
exit 0
fi
;;

View File

@ -25,10 +25,10 @@ if [ -f "$__object/parameter/name" ]; then
else
case "$os" in
openbsd)
name_should="$(echo "${__target_host}")"
name_should="${__target_host}"
;;
*)
name_should="$(echo "${__target_host%%.*}")"
name_should="${__target_host%%.*}"
;;
esac
fi

View File

@ -28,7 +28,7 @@ install_script="$__object/files/install_script"
# Link file descriptor #6 with stdout
exec 6>&1
# Link stdout with $install_script
exec > $install_script
exec > "$install_script"
# Generate script to install bootloader on distro
printf '#!/bin/sh -l\n'

View File

@ -23,12 +23,13 @@ cat "$__type/files/fstab.header" > "$destination"
mkdir "$__object/files"
# get current UUID's from target_host
$__remote_exec $__target_host blkid > "$__object/files/blkid"
$__remote_exec "$__target_host" blkid > "$__object/files/blkid"
for object in $(find "$__global/object/__install_mount" -type d -name "$__cdist_object_marker"); do
find "$__global/object/__install_mount" -type d -name "$__cdist_object_marker" |
while IFS= read -r object
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")"
@ -54,7 +55,7 @@ for object in $(find "$__global/object/__install_mount" -type d -name "$__cdist_
;;
esac
if [ -f "$__object/parameter/uuid" ]; then
uuid="$(grep -w $device "$__object/files/blkid" | awk '{print $2}')"
uuid="$(grep -w "$device" "$__object/files/blkid" | awk '{print $2}')"
if [ -n "$uuid" ]; then
echo "# $dir was on $device during installation" >> "$destination"
device="$uuid"

View File

@ -19,13 +19,18 @@
#
# set defaults
if [ -f "$__object/parameter/device" ]; then
device="(cat "$__object/parameter/device")"
else
# if [ -f "$__object/parameter/device" ]; then
# device="(cat "$__object/parameter/device")"
# else
# device="/$__object_id"
# echo "$device" > "$__object/parameter/device"
# fi
# type="(cat "$__object/parameter/type")"
# options="(cat "$__object/parameter/options")"
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")"

View File

@ -20,7 +20,9 @@
get_type_from_mkfs() {
_device="$1"
for mkfs_object in $(find "$__global/object/__install_mkfs" -type d -name "$__cdist_object_marker"); do
find "$__global/object/__install_mkfs" -type d -name "$__cdist_object_marker" |
while IFS= read -r mkfs_object
do
mkfs_device="$(cat "$mkfs_object/parameter/device")"
if [ "$_device" = "$mkfs_device" ]; then
cat "$mkfs_object/parameter/type"

View File

@ -21,7 +21,7 @@
#set -x
die() {
echo "[__install_partition_msdos_apply] $@" >&2
echo "[__install_partition_msdos_apply]" "$@" >&2
exit 1
}
debug() {
@ -31,25 +31,25 @@ debug() {
# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB.
size_to_mb() {
local size=$1
local available_size="$2"
size=$1
available_size="$2"
local number_suffix="$(echo ${size} | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([KkMmGg%]\)[Bb]\?:\1|\2:')"
local number="$(echo ${number_suffix} | cut -d '|' -f1)"
local suffix="$(echo ${number_suffix} | cut -d '|' -f2)"
number_suffix="$(echo "${size}" | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([KkMmGg%]\)[Bb]\?:\1|\2:')"
number="$(echo "${number_suffix}" | cut -d '|' -f1)"
suffix="$(echo "${number_suffix}" | cut -d '|' -f2)"
case "$suffix" in
K|k)
size="$(( $number / 1024 ))"
size="$(( number / 1024 ))"
;;
M|m)
size="$number"
;;
G|g)
size="$(( $number * 1024 ))"
size="$(( number * 1024 ))"
;;
%)
size="$(( $available_size * $number / 100 ))"
size="$(( available_size * number / 100 ))"
;;
*)
size="-1"
@ -59,13 +59,15 @@ size_to_mb() {
get_objects() {
objects_file=$(mktemp)
for object in $(find "$__global/object/__install_partition_msdos" -type d -name "$__cdist_object_marker"); do
find "$__global/object/__install_partition_msdos" -type d -name "$__cdist_object_marker" |
while IFS= read -r object
do
object_device="$(cat "$object/parameter/device")"
object_minor="$(cat "$object/parameter/minor")"
echo "$object_device $object_minor $object" >> $objects_file
echo "$object_device $object_minor $object" >> "$objects_file"
done
sort -k 1,2 $objects_file | cut -d' ' -f 3
rm $objects_file
sort -k 1,2 "$objects_file" | cut -d' ' -f 3
rm "$objects_file"
unset objects_file
unset object
unset object_device
@ -85,9 +87,9 @@ primary_count=0
for object in $objects; do
device="$(cat "$object/parameter/device")"
if [ "$current_device" != "$device" ]; then
echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'"
echo "create_disklabel '$device' || die 'Failed to create disklabel for $device'"
current_device="$device"
device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g')
device_name=$(echo "${device}" | sed -e 's:^/dev/::;s:/:\\/:g')
available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024))
# make sure we don't go past the end of the drive
available_device_size=$((available_device_size - 2))
@ -108,7 +110,7 @@ for object in $objects; do
if [ "${minor}" -lt "5" ]; then
# Primary partitions
primary_count=$(( $primary_count + 1 ))
primary_count=$(( primary_count + 1 ))
available_size=$available_device_size
else
# Logical partitions
@ -121,13 +123,13 @@ for object in $objects; do
available_size=0
else
partition_size=$(size_to_mb "$size" "$available_size")
available_size="$(( $available_size - $partition_size ))"
available_size="$(( available_size - partition_size ))"
fi
if [ "${minor}" -lt "5" ]; then
# Primary partitions
available_device_size=$available_size
if [ "$type" = "extended" -o "$type" = "5" ]; then
if [ "$type" = "extended" ] || [ "$type" = "5" ]; then
# Extended partition
available_extended_size=$partition_size
fi

View File

@ -18,7 +18,7 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
options="$(cat "$__object/parameter/options")"
# options="$(cat "$__object/parameter/options")"
#echo "reboot $options"
cat << DONE

View File

@ -19,5 +19,6 @@
#
# set defaults
options="$(cat "$__object/parameter/options" 2>/dev/null \
|| echo "" | tee "$__object/parameter/options")"
# options="$(cat "$__object/parameter/options" 2>/dev/null \
# || echo "" | tee "$__object/parameter/options")"
[ -f "$__object/parameter/options" ] || touch "$__object/parameter/options"

View File

@ -19,5 +19,6 @@
#
# set defaults
target="$(cat "$__object/parameter/target" 2>/dev/null \
|| echo "/target" | tee "$__object/parameter/target")"
# target="$(cat "$__object/parameter/target" 2>/dev/null \
# || echo "/target" | tee "$__object/parameter/target")"
cat "$__object/parameter/target" 2>/dev/null 1>/dev/null || echo "/target" > "$__object/parameter/target"

View File

@ -35,16 +35,16 @@ fi
jaildir="$(cat "$__object/parameter/jaildir")"
__directory ${jaildir} --parents
__directory "${jaildir}" --parents
set -- "$@" "$__object_id" "--state" "$state"
cd "$__object/parameter"
for property in $(ls .); do
for property in *; do
set -- "$@" "--$property" "$(cat "$property")"
done
ver="$(cat "$__global/explorer/os_version")"
if [ -n "$(echo "$ver" | grep '^10\.' )" ]; then # Version is 10.x
if echo "$ver" | grep -q '^10\.'; then # Version is 10.x
__jail_freebsd10 "$@"
else
__jail_freebsd9 "$@"

View File

@ -44,7 +44,7 @@ basepresent="$(cat "$__object/explorer/basepresent")"
if [ "$state" = "present" ]; then
if [ "$basepresent" = "NONE" ]; then
# IPv6 fix
if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$')
if echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$'
then
my_target_host="[${__target_host}]"
else

View File

@ -36,7 +36,7 @@ state="$(cat "$__object/parameter/state")"
started="true"
# If the user wants the jail gone, it implies it shouldn't be started.
[ -f "$__object/parameter/stopped" -o "$state" = "absent" ] && started="false"
([ -f "$__object/parameter/stopped" ] || [ "$state" = "absent" ]) && started="false"
if [ -f "$__object/parameter/ip" ]; then
ip="$(cat "$__object/parameter/ip")"
@ -66,7 +66,7 @@ devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
# devfs_ruleset being defined without devfs_enable being true
# is pointless. Treat this as an error.
if [ -n "$devfsruleset" -a "$devfsenable" = "false" ]; then
if [ -n "$devfsruleset" ] && [ "$devfsenable" = "false" ]; then
exec >&2
echo "Can't have --devfs-ruleset defined with --devfs-disable"
exit 1
@ -83,13 +83,13 @@ present="$(cat "$__object/explorer/present")"
status="$(cat "$__object/explorer/status")"
# Handle ip="addr, addr" format
if [ $(expr "${ip}" : ".*, .*") -gt "0" ]; then
if [ "$(expr "${ip}" : ".*, .*")" -gt "0" ]; then
SAVE_IFS="$IFS"
IFS=", "
for cur_ip in ${ip}; do
# for cur_ip in ${ip}; do
# 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