Merge pull request #712 from darko-poljak/shellcheck-type-explorers

Fix problems found by sellcheck in type explorers.
This commit is contained in:
Darko Poljak 2018-10-08 18:01:03 +02:00 committed by GitHub
commit 52b45d4add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 53 additions and 26 deletions

View file

@ -23,10 +23,11 @@
name="$__object_id" name="$__object_id"
# shellcheck disable=SC1091
. /etc/lsb-release . /etc/lsb-release
repo_name="${name#ppa:}" repo_name="${name#ppa:}"
repo_file_name="$(echo "$repo_name" | sed -e "s|[/:]|-|" -e "s|\.|_|")-${DISTRIB_CODENAME}.list" repo_file_name="$(echo "$repo_name" | sed -e 's|[/:]|-|' -e 's|\.|_|')-${DISTRIB_CODENAME}.list"
[ -s "/etc/apt/sources.list.d/${repo_file_name}" ] \ [ -s "/etc/apt/sources.list.d/${repo_file_name}" ] \
&& echo present || echo absent && echo present || echo absent

View file

@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC1091
[ -f /etc/environment ] && . /etc/environment [ -f /etc/environment ] && . /etc/environment
# shellcheck disable=SC1091
[ -f /etc/profile ] && . /etc/profile [ -f /etc/profile ] && . /etc/profile
go version 2>/dev/null || true go version 2>/dev/null || true

View file

@ -39,7 +39,7 @@ fi
# backslash-escaped $jaildir # backslash-escaped $jaildir
sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')"
jls_output="$(jls | grep "[ ]${sjaildir}\/${name}\$")" || true jls_output="$(jls | grep "[ ]${sjaildir}\\/${name}\$")" || true
if [ -n "${jls_output}" ]; then if [ -n "${jls_output}" ]; then
echo "STARTED" echo "STARTED"

View file

@ -39,7 +39,7 @@ fi
# backslash-escaped $jaildir # backslash-escaped $jaildir
sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')"
jls_output="$(jls | grep "[ ]${sjaildir}\/${name}\$")" || true jls_output="$(jls | grep "[ ]${sjaildir}\\/${name}\$")" || true
if [ -n "${jls_output}" ]; then if [ -n "${jls_output}" ]; then
echo "STARTED" echo "STARTED"

View file

@ -33,7 +33,7 @@ destination_dir="${destination%/*}"
case "$type" in case "$type" in
symbolic) symbolic)
cd "$destination_dir" || exit 1 cd "$destination_dir" || exit 1
source_is=$(ls -l "$destination" | sed 's/.*-> //g') source_is=$(readlink "$destination")
if [ -h "$destination" ]; then if [ -h "$destination" ]; then
# ignore trailing slashes for comparison # ignore trailing slashes for comparison
if [ "${source_is%/}" = "${source%/}" ]; then if [ "${source_is%/}" = "${source%/}" ]; then
@ -52,7 +52,13 @@ case "$type" in
echo sourcemissing echo sourcemissing
exit 0 exit 0
fi fi
# Currently not worth the effor to change it, stat is not defined by POSIX
# and different OSes has different implementations for it.
# shellcheck disable=SC2012
destination_inode=$(ls -i "$destination" | awk '{print $1}') destination_inode=$(ls -i "$destination" | awk '{print $1}')
# Currently not worth the effor to change it, stat is not defined by POSIX
# and different OSes has different implementations for it.
# shellcheck disable=SC2012
source_inode=$(ls -i "$source" | awk '{print $1}') source_inode=$(ls -i "$source" | awk '{print $1}')
if [ "$destination_inode" -eq "$source_inode" ]; then if [ "$destination_inode" -eq "$source_inode" ]; then
echo present echo present

View file

@ -24,23 +24,26 @@
destination="/$__object_id" destination="/$__object_id"
if [ ! -e "$destination" ]; then if [ ! -e "$destination" ]; then
echo none echo none
elif [ -h "$destination" ]; then elif [ -h "$destination" ]; then
echo symlink echo symlink
elif [ -f "$destination" ]; then elif [ -f "$destination" ]; then
type="$(cat "$__object/parameter/type")" type="$(cat "$__object/parameter/type")"
case "$type" in case "$type" in
hard) hard)
link_count=$(ls -l "$destination" | awk '{ print $2 }') # Currently not worth the effor to change it, stat is not defined by POSIX
if [ "$link_count" -gt 1 ]; then # and different OSes has different implementations for it.
echo hardlink # shellcheck disable=SC2012
exit 0 link_count=$(ls -l "$destination" | awk '{ print $2 }')
fi if [ "$link_count" -gt 1 ]; then
;; echo hardlink
esac exit 0
echo file fi
;;
esac
echo file
elif [ -d "$destination" ]; then elif [ -d "$destination" ]; then
echo directory echo directory
else else
echo unknown echo unknown
fi fi

View file

@ -20,7 +20,7 @@
name="$__object_id" name="$__object_id"
if su - postgres -c "echo '\q' | psql '$name'" 2>/dev/null; then if su - postgres -c "echo '\\q' | psql '$name'" 2>/dev/null; then
echo "present" echo "present"
else else
echo "absent" echo "absent"

View file

@ -20,7 +20,7 @@
name="$__object_id" name="$__object_id"
if su - postgres -c "psql -c '\du' | grep -q '^ *$name *|'"; then if su - postgres -c "psql -c '\\du' | grep -q '^ *$name *|'"; then
echo "present" echo "present"
else else
echo "absent" echo "absent"

View file

@ -27,5 +27,5 @@ then
file="$(cat "$__object/parameter/file")" file="$(cat "$__object/parameter/file")"
# get any entries that match the type and key # get any entries that match the type and key
grep ".*$type_and_key\([ \n]\|$\)" "$file" || true grep ".*$type_and_key\\([ \\n]\\|$\\)" "$file" || true
fi fi

View file

@ -38,12 +38,27 @@ if [ "$init" = 'systemd' ]; then
else else
case "$os" in case "$os" in
debian|openwrt|devuan) debian|openwrt|devuan)
state="present" state="absent"
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" for file in "/etc/rc$runlevel.d/S"??"$name"
do
if [ -f "$file" ]
then
state="present"
break
fi
done
;; ;;
ubuntu) ubuntu)
state="absent" state="absent"
[ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" for file in "/etc/rc$runlevel.d/S"??"$name"
do
if [ -f "$file" ]
then
state="present"
break
fi
done
[ -f "/etc/init/${name}.conf" ] && state="present" [ -f "/etc/init/${name}.conf" ] && state="present"
;; ;;

View file

@ -27,4 +27,4 @@ else
fi fi
# simpler command which works only on SLES11 SP3 or newer: # simpler command which works only on SLES11 SP3 or newer:
# echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 1 ) # echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 1 )
zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | cut -d'|' -f 1 zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\\<$uri\\>" | cut -d'|' -f 1