Merge pull request #708 from darko-poljak/shellcheck-various

Fix for various problems (shellcheck)
This commit is contained in:
Darko Poljak 2018-10-06 15:15:38 +02:00 committed by GitHub
commit a46016242b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 29 deletions

View file

@ -35,8 +35,13 @@ if [ ! -f "$__object/parameter/source" ] && [ ! -f "$__object/parameter/source-f
exit 1 exit 1
fi fi
if [ -f "$__object/parameter/source-file" ]; then
destination="${template_dir}/${name}"
require="__file${destination}"
fi
# Generate hcl config file # Generate hcl config file
( {
printf 'template {\n' printf 'template {\n'
cd "$__object/parameter/" cd "$__object/parameter/"
for param in *; do for param in *; do
@ -46,13 +51,11 @@ for param in *; do
if [ "$source" = "-" ]; then if [ "$source" = "-" ]; then
source="$__object/stdin" source="$__object/stdin"
fi fi
destination="${template_dir}/${name}"
require="__directory${template_dir}" \ require="__directory${template_dir}" \
__file "$destination" \ __file "$destination" \
--owner root --group root --mode 640 \ --owner root --group root --mode 640 \
--source "$source" \ --source "$source" \
--state "$state" --state "$state"
export require="__file${destination}"
printf ' source = "%s"\n' "$destination" printf ' source = "%s"\n' "$destination"
;; ;;
@ -66,7 +69,7 @@ for param in *; do
esac esac
done done
printf '}\n' printf '}\n'
) | \ } | \
require="$require __directory${conf_dir}" \ require="$require __directory${conf_dir}" \
__config_file "${conf_dir}/${conf_file}" \ __config_file "${conf_dir}/${conf_file}" \
--owner root --group root --mode 640 \ --owner root --group root --mode 640 \

View file

@ -24,6 +24,7 @@ state=$(cat "$__object/parameter/state")
case "$os" in case "$os" in
centos) centos)
# shellcheck source=/dev/null
if (. "$__global/explorer/os_release" && [ "${VERSION_ID}" = "7" ]); then if (. "$__global/explorer/os_release" && [ "${VERSION_ID}" = "7" ]); then
__yum_repo docker-ce-stable \ __yum_repo docker-ce-stable \
--name 'Docker CE Stable' \ --name 'Docker CE Stable' \

View file

@ -19,7 +19,7 @@ set -eu
user="$(cat "${__object}/parameter/user")" 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}") line=$(getent passwd "${user}")
else else
line=$(grep "^${user}:" /etc/passwd) line=$(grep "^${user}:" /etc/passwd)

View file

@ -22,7 +22,7 @@
if [ -f "$__object/parameter/name" ]; then if [ -f "$__object/parameter/name" ]; then
name_should="$(cat "$__object/parameter/name")" name_should="$(cat "$__object/parameter/name")"
else else
name_should="$(echo "${__target_host%%.*}")" name_should="${__target_host%%.*}"
fi fi
os=$(cat "$__global/explorer/os") 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. # Use the good old way to set the hostname even on machines running systemd.
case "$os" in case "$os" in
archlinux|debian|ubuntu|devuan|centos|coreos) 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" echo "hostname -F /etc/hostname"
;; ;;
freebsd|openbsd) freebsd|openbsd)
@ -67,7 +67,7 @@ case "$os" in
;; ;;
suse) suse)
echo "hostname '$name_should'" echo "hostname '$name_should'"
echo "printf '%s\n' '$name_should' > /etc/HOSTNAME" printf "printf '%s\\n' '$name_should' > /etc/HOSTNAME\\n"
;; ;;
esac esac

View file

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

View file

@ -21,11 +21,11 @@
#set -x #set -x
die() { die() {
echo "[__install_partition_msdos_apply] $@" >&2 echo "[__install_partition_msdos_apply] $*" >&2
exit 1 exit 1
} }
debug() { debug() {
#echo "[__install_partition_msdos_apply] $@" >&2 #echo "[__install_partition_msdos_apply] $*" >&2
: :
} }

View file

@ -43,8 +43,7 @@ for property in *; do
set -- "$@" "--$property" "$(cat "$property")" set -- "$@" "--$property" "$(cat "$property")"
done done
ver="$(cat "$__global/explorer/os_version")" if grep -q '^10\.' "$(cat "$__global/explorer/os_version")" ; then # Version is 10.x
if [ -n "$(echo "$ver" | grep '^10\.' )" ]; then # Version is 10.x
__jail_freebsd10 "$@" __jail_freebsd10 "$@"
else else
__jail_freebsd9 "$@" __jail_freebsd9 "$@"

View file

@ -83,7 +83,7 @@ present="$(cat "$__object/explorer/present")"
status="$(cat "$__object/explorer/status")" status="$(cat "$__object/explorer/status")"
# Handle ip="addr, addr" format # Handle ip="addr, addr" format
if [ $(expr "${ip}" : ".*, .*") -gt "0" ]; then if [ "$(expr "${ip}" : ".*, .*")" -gt "0" ]; then
SAVE_IFS="$IFS" SAVE_IFS="$IFS"
IFS=", " IFS=", "
for cur_ip in ${ip}; do for cur_ip in ${ip}; do
@ -121,12 +121,12 @@ deleteJail() {
output="\$(mount | grep "\/rw\/${name}\/")" || true output="\$(mount | grep "\/rw\/${name}\/")" || true
if [ -n "\${output}" ]; then # >=1 rw mount is mounted still if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
for DIR in "${output}"; do 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 done
fi fi
output="\$(mount | grep "\/${name} (")" || true output="\$(mount | grep "\/${name} (")" || true
if [ -n "\${output}" ]; then # ro mount is mounted still 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 fi
EOF EOF
# Remove the jail's rw mountpoints # Remove the jail's rw mountpoints
@ -298,7 +298,7 @@ END
fi fi
EOF EOF
# shellcheck disable=SC2028
echo "printf \"%s\\n%s\n%s\n\" \"\$jailheader\" \"\$jaildata\" \"\$jailtrailer\" >>\"\$jailfile\"" echo "printf \"%s\\n%s\n%s\n\" \"\$jailheader\" \"\$jaildata\" \"\$jailtrailer\" >>\"\$jailfile\""
# Add $name to jail_list if $onboot=yes # Add $name to jail_list if $onboot=yes

View file

@ -86,7 +86,7 @@ present="$(cat "$__object/explorer/present")"
status="$(cat "$__object/explorer/status")" status="$(cat "$__object/explorer/status")"
# Handle ip="iface|addr, iface|addr" format # 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 # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it
interface="" interface=""
SAVE_IFS="$IFS" SAVE_IFS="$IFS"
@ -126,12 +126,12 @@ deleteJail() {
output="\$(mount | grep "\/rw\/${name}\/")" || true output="\$(mount | grep "\/rw\/${name}\/")" || true
if [ -n "\${output}" ]; then # >=1 rw mount is mounted still if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
for DIR in "${output}"; do 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 done
fi fi
output="\$(mount | grep "\/${name} (")" || true output="\$(mount | grep "\/${name} (")" || true
if [ -n "\${output}" ]; then # ro mount is mounted still 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 fi
EOF EOF
# Remove the jail's rw mountpoints # Remove the jail's rw mountpoints

View file

@ -38,11 +38,11 @@ fi
pkg_version="$(cat "$__object/explorer/pkg_version")" pkg_version="$(cat "$__object/explorer/pkg_version")"
if [ -z "$pkg_version" ]; then if [ -z "$pkg_version" ]; then
state_is="absent" 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 "Package name is not unique! The following packages are installed:"
echo "$pkg_version" echo "$pkg_version"
exit 1 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 "Package name is not unique! The following packages are installed:"
echo "$pkg_version" echo "$pkg_version"
exit 1 exit 1
@ -57,7 +57,7 @@ fi
# Exit if nothing is needed to be done # 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 [ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0

View file

@ -28,4 +28,4 @@ else
fi fi
# Accept luarocks failing if package is not known/installed # 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

View file

@ -36,6 +36,7 @@ assert () # If condition false,
if [ ! "$1" ] if [ ! "$1" ]
then then
echo "Assertion failed: \"$1\"" echo "Assertion failed: \"$1\""
# shellcheck disable=SC2039
echo "File \"$0\", line $lineno, called by $(caller 0)" echo "File \"$0\", line $lineno, called by $(caller 0)"
exit $E_ASSERT_FAILED exit $E_ASSERT_FAILED
fi fi
@ -95,6 +96,7 @@ if [ -n "$curr_version" ]; then # PKG *is* installed
exit 0 exit 0
else # Current version is wrong, fix else # Current version is wrong, fix
#updatepkg "$name" "$version" #updatepkg "$name" "$version"
# shellcheck disable=SC2039
assert "! ${version} = ${curr_version}" $LINENO assert "! ${version} = ${curr_version}" $LINENO
cmd="${rm_cmd} ${name}-${curr_version}" cmd="${rm_cmd} ${name}-${curr_version}"
execcmd "remove" "${cmd}" execcmd "remove" "${cmd}"

View file

@ -54,7 +54,7 @@ case $uname in
currentSum=\$(cksum -o 1 ${source} | cut -d= -f2 | sed 's/ //g') 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 exit 1
;; ;;
esac esac

View file

@ -34,7 +34,7 @@ case "$state_should" in
if [ ! -f "$__object/parameter/$boolean" ]; then if [ ! -f "$__object/parameter/$boolean" ]; then
boolean="no${boolean}" boolean="no${boolean}"
fi fi
upper=$(echo $boolean | tr '[a-z]' '[A-Z]') upper=$(echo $boolean | tr '[:lower:]' '[:upper:]')
booleans="$booleans $upper" booleans="$booleans $upper"
done done

View file

@ -29,7 +29,7 @@ fi
set -- set --
if [ -f "$__object/parameter/rsync-opts" ]; then if [ -f "$__object/parameter/rsync-opts" ]; then
while read opts; do while read -r opts; do
set -- "$@" "--$opts" set -- "$@" "--$opts"
done < "$__object/parameter/rsync-opts" done < "$__object/parameter/rsync-opts"
fi fi

View file

@ -78,7 +78,7 @@ if [ -s "$__object/explorer/entry" ]; then
# Note that the files have to be sorted for comparison with `comm`. # Note that the files have to be sorted for comparison with `comm`.
sort "$__object/explorer/entry" > "$__object/files/is" sort "$__object/explorer/entry" > "$__object/files/is"
comm -13 "$__object/files/should" "$__object/files/is" | { comm -13 "$__object/files/should" "$__object/files/is" | {
while read entry; do while read -r entry; do
remove_line "$file" "$entry" remove_line "$file" "$entry"
done done
} }