forked from ungleich-public/cdist
Merge pull request #712 from darko-poljak/shellcheck-type-explorers
Fix problems found by sellcheck in type explorers.
This commit is contained in:
commit
52b45d4add
11 changed files with 53 additions and 26 deletions
|
@ -23,10 +23,11 @@
|
|||
|
||||
name="$__object_id"
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/lsb-release
|
||||
|
||||
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}" ] \
|
||||
&& echo present || echo absent
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC1091
|
||||
[ -f /etc/environment ] && . /etc/environment
|
||||
# shellcheck disable=SC1091
|
||||
[ -f /etc/profile ] && . /etc/profile
|
||||
go version 2>/dev/null || true
|
||||
|
|
|
@ -39,7 +39,7 @@ fi
|
|||
# backslash-escaped $jaildir
|
||||
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
|
||||
echo "STARTED"
|
||||
|
|
|
@ -39,7 +39,7 @@ fi
|
|||
# backslash-escaped $jaildir
|
||||
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
|
||||
echo "STARTED"
|
||||
|
|
|
@ -33,7 +33,7 @@ destination_dir="${destination%/*}"
|
|||
case "$type" in
|
||||
symbolic)
|
||||
cd "$destination_dir" || exit 1
|
||||
source_is=$(ls -l "$destination" | sed 's/.*-> //g')
|
||||
source_is=$(readlink "$destination")
|
||||
if [ -h "$destination" ]; then
|
||||
# ignore trailing slashes for comparison
|
||||
if [ "${source_is%/}" = "${source%/}" ]; then
|
||||
|
@ -52,7 +52,13 @@ case "$type" in
|
|||
echo sourcemissing
|
||||
exit 0
|
||||
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}')
|
||||
# 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}')
|
||||
if [ "$destination_inode" -eq "$source_inode" ]; then
|
||||
echo present
|
||||
|
|
|
@ -24,23 +24,26 @@
|
|||
destination="/$__object_id"
|
||||
|
||||
if [ ! -e "$destination" ]; then
|
||||
echo none
|
||||
echo none
|
||||
elif [ -h "$destination" ]; then
|
||||
echo symlink
|
||||
echo symlink
|
||||
elif [ -f "$destination" ]; then
|
||||
type="$(cat "$__object/parameter/type")"
|
||||
case "$type" in
|
||||
hard)
|
||||
link_count=$(ls -l "$destination" | awk '{ print $2 }')
|
||||
if [ "$link_count" -gt 1 ]; then
|
||||
echo hardlink
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo file
|
||||
type="$(cat "$__object/parameter/type")"
|
||||
case "$type" in
|
||||
hard)
|
||||
# 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
|
||||
link_count=$(ls -l "$destination" | awk '{ print $2 }')
|
||||
if [ "$link_count" -gt 1 ]; then
|
||||
echo hardlink
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo file
|
||||
elif [ -d "$destination" ]; then
|
||||
echo directory
|
||||
echo directory
|
||||
else
|
||||
echo unknown
|
||||
echo unknown
|
||||
fi
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
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"
|
||||
else
|
||||
echo "absent"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
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"
|
||||
else
|
||||
echo "absent"
|
||||
|
|
|
@ -27,5 +27,5 @@ then
|
|||
file="$(cat "$__object/parameter/file")"
|
||||
|
||||
# get any entries that match the type and key
|
||||
grep ".*$type_and_key\([ \n]\|$\)" "$file" || true
|
||||
grep ".*$type_and_key\\([ \\n]\\|$\\)" "$file" || true
|
||||
fi
|
||||
|
|
|
@ -38,12 +38,27 @@ if [ "$init" = 'systemd' ]; then
|
|||
else
|
||||
case "$os" in
|
||||
debian|openwrt|devuan)
|
||||
state="present"
|
||||
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
|
||||
state="absent"
|
||||
for file in "/etc/rc$runlevel.d/S"??"$name"
|
||||
do
|
||||
if [ -f "$file" ]
|
||||
then
|
||||
state="present"
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
ubuntu)
|
||||
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"
|
||||
;;
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@ else
|
|||
fi
|
||||
# simpler command which works only on SLES11 SP3 or newer:
|
||||
# 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
|
||||
|
|
Loading…
Reference in a new issue