forked from ungleich-public/cdist
Merge pull request #708 from darko-poljak/shellcheck-various
Fix for various problems (shellcheck)
This commit is contained in:
commit
a46016242b
16 changed files with 34 additions and 29 deletions
|
@ -35,8 +35,13 @@ if [ ! -f "$__object/parameter/source" ] && [ ! -f "$__object/parameter/source-f
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/source-file" ]; then
|
||||
destination="${template_dir}/${name}"
|
||||
require="__file${destination}"
|
||||
fi
|
||||
|
||||
# Generate hcl config file
|
||||
(
|
||||
{
|
||||
printf 'template {\n'
|
||||
cd "$__object/parameter/"
|
||||
for param in *; do
|
||||
|
@ -46,13 +51,11 @@ for param in *; do
|
|||
if [ "$source" = "-" ]; then
|
||||
source="$__object/stdin"
|
||||
fi
|
||||
destination="${template_dir}/${name}"
|
||||
require="__directory${template_dir}" \
|
||||
__file "$destination" \
|
||||
--owner root --group root --mode 640 \
|
||||
--source "$source" \
|
||||
--state "$state"
|
||||
export require="__file${destination}"
|
||||
printf ' source = "%s"\n' "$destination"
|
||||
|
||||
;;
|
||||
|
@ -66,7 +69,7 @@ for param in *; do
|
|||
esac
|
||||
done
|
||||
printf '}\n'
|
||||
) | \
|
||||
} | \
|
||||
require="$require __directory${conf_dir}" \
|
||||
__config_file "${conf_dir}/${conf_file}" \
|
||||
--owner root --group root --mode 640 \
|
||||
|
|
|
@ -24,6 +24,7 @@ state=$(cat "$__object/parameter/state")
|
|||
|
||||
case "$os" in
|
||||
centos)
|
||||
# shellcheck source=/dev/null
|
||||
if (. "$__global/explorer/os_release" && [ "${VERSION_ID}" = "7" ]); then
|
||||
__yum_repo docker-ce-stable \
|
||||
--name 'Docker CE Stable' \
|
||||
|
|
|
@ -19,7 +19,7 @@ set -eu
|
|||
|
||||
user="$(cat "${__object}/parameter/user")"
|
||||
|
||||
if which getent >/dev/null 2>&1; then
|
||||
if command -v getent >/dev/null 2>&1; then
|
||||
line=$(getent passwd "${user}")
|
||||
else
|
||||
line=$(grep "^${user}:" /etc/passwd)
|
||||
|
|
|
@ -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")
|
||||
|
@ -59,7 +59,7 @@ echo changed >> "$__messages_out"
|
|||
# Use the good old way to set the hostname even on machines running systemd.
|
||||
case "$os" in
|
||||
archlinux|debian|ubuntu|devuan|centos|coreos)
|
||||
echo "printf '%s\n' '$name_should' > /etc/hostname"
|
||||
printf "printf '%s\\n' '$name_should' > /etc/hostname\\n"
|
||||
echo "hostname -F /etc/hostname"
|
||||
;;
|
||||
freebsd|openbsd)
|
||||
|
@ -67,7 +67,7 @@ case "$os" in
|
|||
;;
|
||||
suse)
|
||||
echo "hostname '$name_should'"
|
||||
echo "printf '%s\n' '$name_should' > /etc/HOSTNAME"
|
||||
printf "printf '%s\\n' '$name_should' > /etc/HOSTNAME\\n"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
#set -x
|
||||
|
||||
die() {
|
||||
echo "[__install_partition_msdos_apply] $@" >&2
|
||||
echo "[__install_partition_msdos_apply] $*" >&2
|
||||
exit 1
|
||||
}
|
||||
debug() {
|
||||
#echo "[__install_partition_msdos_apply] $@" >&2
|
||||
#echo "[__install_partition_msdos_apply] $*" >&2
|
||||
:
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ 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 grep -q '^10\.' "$(cat "$__global/explorer/os_version")" ; then # Version is 10.x
|
||||
__jail_freebsd10 "$@"
|
||||
else
|
||||
__jail_freebsd9 "$@"
|
||||
|
|
|
@ -83,7 +83,7 @@ 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
|
||||
|
@ -121,12 +121,12 @@ deleteJail() {
|
|||
output="\$(mount | grep "\/rw\/${name}\/")" || true
|
||||
if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
|
||||
for DIR in "${output}"; do
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print $3}')"
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print \$3}')"
|
||||
done
|
||||
fi
|
||||
output="\$(mount | grep "\/${name} (")" || true
|
||||
if [ -n "\${output}" ]; then # ro mount is mounted still
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print $3}')"
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print \$3}')"
|
||||
fi
|
||||
EOF
|
||||
# Remove the jail's rw mountpoints
|
||||
|
@ -298,7 +298,7 @@ END
|
|||
fi
|
||||
|
||||
EOF
|
||||
|
||||
# shellcheck disable=SC2028
|
||||
echo "printf \"%s\\n%s\n%s\n\" \"\$jailheader\" \"\$jaildata\" \"\$jailtrailer\" >>\"\$jailfile\""
|
||||
|
||||
# Add $name to jail_list if $onboot=yes
|
||||
|
|
|
@ -86,7 +86,7 @@ present="$(cat "$__object/explorer/present")"
|
|||
status="$(cat "$__object/explorer/status")"
|
||||
|
||||
# Handle ip="iface|addr, iface|addr" format
|
||||
if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then
|
||||
if [ "$(expr "${ip}" : ".*|.*")" -gt "0" ]; then
|
||||
# If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it
|
||||
interface=""
|
||||
SAVE_IFS="$IFS"
|
||||
|
@ -126,12 +126,12 @@ deleteJail() {
|
|||
output="\$(mount | grep "\/rw\/${name}\/")" || true
|
||||
if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
|
||||
for DIR in "${output}"; do
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print $3}')"
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print \$3}')"
|
||||
done
|
||||
fi
|
||||
output="\$(mount | grep "\/${name} (")" || true
|
||||
if [ -n "\${output}" ]; then # ro mount is mounted still
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print $3}')"
|
||||
umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print \$3}')"
|
||||
fi
|
||||
EOF
|
||||
# Remove the jail's rw mountpoints
|
||||
|
|
|
@ -38,11 +38,11 @@ fi
|
|||
pkg_version="$(cat "$__object/explorer/pkg_version")"
|
||||
if [ -z "$pkg_version" ]; then
|
||||
state_is="absent"
|
||||
elif [ -z "$version" ] && [ $(echo "$pkg_version" | wc -l) -gt 1 ]; then
|
||||
elif [ -z "$version" ] && [ "$(echo "$pkg_version" | wc -l)" -gt 1 ]; then
|
||||
echo "Package name is not unique! The following packages are installed:"
|
||||
echo "$pkg_version"
|
||||
exit 1
|
||||
elif [ -n "$version" ] && [ $(echo "$pkg_version" | cut -d " " -f 1 | sort | uniq | wc -l) -gt 1 ]; then
|
||||
elif [ -n "$version" ] && [ "$(echo "$pkg_version" | cut -d " " -f 1 | sort | uniq | wc -l)" -gt 1 ]; then
|
||||
echo "Package name is not unique! The following packages are installed:"
|
||||
echo "$pkg_version"
|
||||
exit 1
|
||||
|
@ -57,7 +57,7 @@ fi
|
|||
|
||||
|
||||
# Exit if nothing is needed to be done
|
||||
[ "$state_is" = "$state_should" ] && ( [ -z "$version" ] || [ "$installed_version" = "$version" ] ) && exit 0
|
||||
[ "$state_is" = "$state_should" ] && { [ -z "$version" ] || [ "$installed_version" = "$version" ]; } && exit 0
|
||||
[ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0
|
||||
|
||||
|
||||
|
|
|
@ -28,4 +28,4 @@ else
|
|||
fi
|
||||
|
||||
# Accept luarocks failing if package is not known/installed
|
||||
luarocks list "$name" | egrep -A1 "^$name$" || exit 0
|
||||
luarocks list "$name" | grep -E -A1 "^$name$" || exit 0
|
||||
|
|
|
@ -36,6 +36,7 @@ assert () # If condition false,
|
|||
if [ ! "$1" ]
|
||||
then
|
||||
echo "Assertion failed: \"$1\""
|
||||
# shellcheck disable=SC2039
|
||||
echo "File \"$0\", line $lineno, called by $(caller 0)"
|
||||
exit $E_ASSERT_FAILED
|
||||
fi
|
||||
|
@ -95,6 +96,7 @@ if [ -n "$curr_version" ]; then # PKG *is* installed
|
|||
exit 0
|
||||
else # Current version is wrong, fix
|
||||
#updatepkg "$name" "$version"
|
||||
# shellcheck disable=SC2039
|
||||
assert "! ${version} = ${curr_version}" $LINENO
|
||||
cmd="${rm_cmd} ${name}-${curr_version}"
|
||||
execcmd "remove" "${cmd}"
|
||||
|
|
|
@ -54,7 +54,7 @@ case $uname in
|
|||
currentSum=\$(cksum -o 1 ${source} | cut -d= -f2 | sed 's/ //g')
|
||||
;;
|
||||
*)
|
||||
echo "Sorry, I do not know how to find a cksum on ${UNAME}." >&2
|
||||
echo "Sorry, I do not know how to find a cksum on ${uname}." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -34,7 +34,7 @@ case "$state_should" in
|
|||
if [ ! -f "$__object/parameter/$boolean" ]; then
|
||||
boolean="no${boolean}"
|
||||
fi
|
||||
upper=$(echo $boolean | tr '[a-z]' '[A-Z]')
|
||||
upper=$(echo $boolean | tr '[:lower:]' '[:upper:]')
|
||||
booleans="$booleans $upper"
|
||||
done
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ fi
|
|||
|
||||
set --
|
||||
if [ -f "$__object/parameter/rsync-opts" ]; then
|
||||
while read opts; do
|
||||
while read -r opts; do
|
||||
set -- "$@" "--$opts"
|
||||
done < "$__object/parameter/rsync-opts"
|
||||
fi
|
||||
|
|
|
@ -78,7 +78,7 @@ if [ -s "$__object/explorer/entry" ]; then
|
|||
# Note that the files have to be sorted for comparison with `comm`.
|
||||
sort "$__object/explorer/entry" > "$__object/files/is"
|
||||
comm -13 "$__object/files/should" "$__object/files/is" | {
|
||||
while read entry; do
|
||||
while read -r entry; do
|
||||
remove_line "$file" "$entry"
|
||||
done
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue