Fixed shellcheck warnings

This commit is contained in:
Андрей Лимачко 2022-12-21 15:44:35 +04:00
parent 3e01df34d6
commit 2567f12e36
Signed by untrusted user: liannnix
GPG Key ID: 1D8EEB2E408272C0

View File

@ -39,7 +39,7 @@ print_version()
exit 0; exit 0;
} }
TEMP=`getopt -n "$PROG" -o "v,V,w::,f,l,h" -l "verbose,version,logfile::,force,list,help" -- "$@"` || show_usage TEMP=$(getopt -n "$PROG" -o "v,V,w::,f,l,h" -l "verbose,version,logfile::,force,list,help" -- "$@") || show_usage
eval set -- "$TEMP" eval set -- "$TEMP"
while :; do while :; do
@ -49,7 +49,7 @@ while :; do
-v|--verbose) verbose=1 -v|--verbose) verbose=1
;; ;;
-w|--logfile) shift -w|--logfile) shift
test -n "$1" && logfile="$1" || logfile=domain-diag.log test -n "$1" && logfile="$1" || logfile="domain-diag.log"
;; ;;
-f|--force) force=1 -f|--force) force=1
;; ;;
@ -169,7 +169,7 @@ __newline()
__log() __log()
{ {
test -z $verbose && tee -a "$logfile" 2>&1 >/dev/null || test -z $verbose && tee -a "$logfile" 1>/dev/null 2>&1 ||
tee -a "$logfile" tee -a "$logfile"
} }
@ -195,7 +195,7 @@ print_head()
is_root() is_root()
{ {
if test $(id -u) != 0; then if test "$(id -u)" != 0; then
return 1 return 1
fi fi
return 0 return 0
@ -204,7 +204,7 @@ is_root()
__not_root_skip() __not_root_skip()
{ {
local msg= local msg=
if test -n "${1+x}" && test "$1" = '-m'; then if test -n "${1+x}" && test "$1" = "-m"; then
shift shift
msg="$1" msg="$1"
fi fi
@ -217,7 +217,8 @@ run()
{ {
local retval=126 local retval=126
local func="$1" local func="$1"
local msg=$(printf "| %s |" "$func") local msg
msg=$(printf "| %s |" "$func")
__header | __log __header | __log
@ -238,8 +239,10 @@ run()
check_hostnamectl() check_hostnamectl()
{ {
local retval=0 local retval=0
local static_host="$(hostnamectl --static)" || retval=1 local static_host=
local transient_host="$(hostname)" || retval=1 local transient_host=
transient_host="$(hostname)" || retval=1
static_host="$(hostnamectl --static)" || retval=1
_command hostnamectl || retval=1 _command hostnamectl || retval=1
test "$static_host" = "$transient_host" || retval=1 test "$static_host" = "$transient_host" || retval=1
return $retval return $retval
@ -255,7 +258,8 @@ test_hostname()
check_system_auth() check_system_auth()
{ {
local auth=$(/usr/sbin/control system-auth) local auth=
auth=$(/usr/sbin/control system-auth)
_command /usr/sbin/control system-auth _command /usr/sbin/control system-auth
_command readlink -f /etc/pam.d/system-auth _command readlink -f /etc/pam.d/system-auth
_command -x cat /etc/pam.d/system-auth _command -x cat /etc/pam.d/system-auth
@ -277,7 +281,8 @@ is_system_auth_local()
check_system_policy() check_system_policy()
{ {
local policy=$(/usr/sbin/control system-policy) local policy=
policy=$(/usr/sbin/control system-policy)
_command /usr/sbin/control system-policy _command /usr/sbin/control system-policy
_command readlink -f /etc/pam.d/system-policy _command readlink -f /etc/pam.d/system-policy
_command -x cat /etc/pam.d/system-policy _command -x cat /etc/pam.d/system-policy
@ -306,14 +311,16 @@ check_krb5_conf_exists()
check_krb5_conf_ccache() check_krb5_conf_ccache()
{ {
local ccache=$(/usr/sbin/control krb5-conf-ccache) local ccache=
ccache=$(/usr/sbin/control krb5-conf-ccache)
_command /usr/sbin/control krb5-conf-ccache _command /usr/sbin/control krb5-conf-ccache
test -n "$ccache" -a "$ccache" != "unknown" test -n "$ccache" -a "$ccache" != "unknown"
} }
test_keyring_krb5_conf_ccache() test_keyring_krb5_conf_ccache()
{ {
local ccache=$(/usr/sbin/control krb5-conf-ccache) local ccache=
ccache=$(/usr/sbin/control krb5-conf-ccache)
_command /usr/sbin/control krb5-conf-ccache _command /usr/sbin/control krb5-conf-ccache
_command test -n "$ccache" -a "$ccache" == "keyring" || return 2 _command test -n "$ccache" -a "$ccache" == "keyring" || return 2
} }
@ -372,8 +379,10 @@ compare_resolv_conf_with_default_realm()
echo "SEARCH_DOMAIN = '$SEARCH_DOMAIN'" echo "SEARCH_DOMAIN = '$SEARCH_DOMAIN'"
echo "KRB5_DEFAULT_REALM = '$KRB5_DEFAULT_REALM'" echo "KRB5_DEFAULT_REALM = '$KRB5_DEFAULT_REALM'"
echo echo
local domain=$(echo "$SEARCH_DOMAIN" | tr '[:upper:]' '[:lower:]') local domain=
local realm=$(echo "$KRB5_DEFAULT_REALM" | tr '[:upper:]' '[:lower:]') local realm=
domain=$(echo "$SEARCH_DOMAIN" | tr '[:upper:]' '[:lower:]')
realm=$(echo "$KRB5_DEFAULT_REALM" | tr '[:upper:]' '[:lower:]')
if test -z "$realm"; then if test -z "$realm"; then
return 2 return 2
@ -426,16 +435,18 @@ test_smb_realm()
test_domainname() test_domainname()
{ {
HOSTNAME_DOMAIN=`hostname -d` HOSTNAME_DOMAIN=$(hostname -d)
if [ "$HOSTNAME_DOMAIN" = "$HOSTNAME_SHORT" -o "$HOSTNAME_DOMAIN" = '(none)' -o -z "$HOSTNAME_DOMAIN" ]; then if test "$HOSTNAME_DOMAIN" = "$HOSTNAME_SHORT" ||
test "$HOSTNAME_DOMAIN" = '(none)' ||
test -z "$HOSTNAME_DOMAIN"; then
HOSTNAME_DOMAIN= HOSTNAME_DOMAIN=
echo "HOSTNAME_DOMAIN = '$HOSTNAME_DOMAIN'" echo "HOSTNAME_DOMAIN = '$HOSTNAME_DOMAIN'"
echo echo
return 2 return 2
fi fi
if [ -z "$DOMAIN_DOMAIN" ]; then if test -z "$DOMAIN_DOMAIN"; then
DOMAIN_DOMAIN="$HOSTNAME_DOMAIN" DOMAIN_DOMAIN="$HOSTNAME_DOMAIN"
test -n "$DOMAIN_REALM" || test -n "$DOMAIN_REALM" ||
DOMAIN_REALM="$(echo "$DOMAIN_DOMAIN" | tr '[:lower:]' '[:upper:]')" DOMAIN_REALM="$(echo "$DOMAIN_DOMAIN" | tr '[:lower:]' '[:upper:]')"
@ -461,9 +472,9 @@ check_time_synchronization()
test_time_synchronization() test_time_synchronization()
{ {
local retval=0 local retval=0
local func='test $(timedatectl show -p NTPSynchronized --value) == "yes"' local func="test \$(timedatectl show -p NTPSynchronized --value) == \"yes\""
__command_msg $func __command_msg "$func"
_command -q $func || retval=2 _command -q "$func" || retval=2
return $retval return $retval
} }
@ -506,14 +517,15 @@ _ldap_get_computer()
local dc="$1" local dc="$1"
local computer="$2" local computer="$2"
local filter="" local filter=""
local domain_dn=
if test -n "${3+x}"; then if test -n "${3+x}"; then
filter="$3" filter="$3"
fi fi
local domain_dn=$(echo $DOMAIN_DOMAIN | sed 's/\./,dc=/g' | sed 's/^/dc=/') domain_dn=$(echo $DOMAIN_DOMAIN | sed 's/\./,dc=/g' | sed 's/^/dc=/')
local searchcmd="ldapsearch -Y GSSAPI -N -h $dc -b $domain_dn \ local searchcmd="ldapsearch -Y GSSAPI -N -h $dc -b $domain_dn"
\"(&(ObjectClass=computer)(objectCategory=Computer)(name=$computer))\"" searchcmd="$searchcmd \"(&(ObjectClass=computer)(objectCategory=Computer)(name=$computer))\""
__command_msg $searchcmd $filter __command_msg "$searchcmd $filter"
_command -q $searchcmd $filter || retval=2 _command -q "$searchcmd" "$filter" || retval=2
return $retval return $retval
} }
@ -521,8 +533,10 @@ _check_domain_controller()
{ {
local retval=0 local retval=0
local dc="$1" local dc="$1"
local computer=$(echo $1 | sed 's/\..*$//') local computer=
local ldap_computer= local ldap_computer=
local computer=
computer="$(echo $1 | sed 's/\..*$//')"
_ldap_get_computer "$dc" "$computer" "| grep 'operating\|name:' | cut -d ' ' -f 2 | tr '\n' ' '" || retval=2 _ldap_get_computer "$dc" "$computer" "| grep 'operating\|name:' | cut -d ' ' -f 2 | tr '\n' ' '" || retval=2
return $retval return $retval
} }
@ -532,13 +546,14 @@ check_domain_controllers()
local retval=2 local retval=2
local hostcmd="host -t srv _ldap._tcp.$DOMAIN_DOMAIN | cut -d ' ' -f 8" local hostcmd="host -t srv _ldap._tcp.$DOMAIN_DOMAIN | cut -d ' ' -f 8"
local resolv_msg= local resolv_msg=
__command_msg $hostcmd local controllers_names=
local controllers_names=$(_command -q $hostcmd || retval=2) __command_msg "$hostcmd"
controllers_names=$(_command -q "$hostcmd" || retval=2)
echo $controllers_names | sed 's/ /\n/g' echo $controllers_names | sed 's/ /\n/g'
echo echo
for controller_name in $controllers_names; do for controller_name in $controllers_names; do
resolv_msg="host $controller_name | sed 's/^.* //g'" resolv_msg="host $controller_name | sed 's/^.* //g'"
_command $resolv_msg _command "$resolv_msg"
done done
for controller_name in $controllers_names; do for controller_name in $controllers_names; do
# TODO: Add controller check by ip # TODO: Add controller check by ip
@ -558,8 +573,10 @@ check_kerberos_and_ldap_srv_records()
compare_netbios_name() compare_netbios_name()
{ {
local netbios=$(echo "$SMB_NETBIOS_NAME" | tr '[:upper:]' '[:lower:]') local netbios=
local host=$(echo "$HOSTNAME_SHORT" | tr '[:upper:]' '[:lower:]') local host=
netbios=$(echo "$SMB_NETBIOS_NAME" | tr '[:upper:]' '[:lower:]')
host=$(echo "$HOSTNAME_SHORT" | tr '[:upper:]' '[:lower:]')
echo "SMB_NETBIOS_NAME = '$SMB_NETBIOS_NAME'" echo "SMB_NETBIOS_NAME = '$SMB_NETBIOS_NAME'"
echo "HOSTNAME_SHORT = '$HOSTNAME_SHORT'" echo "HOSTNAME_SHORT = '$HOSTNAME_SHORT'"
@ -617,7 +634,7 @@ init_log()
{ {
local log_index local log_index
if test -e "$logfile" && test "$logfile" != "/dev/null" && test -z "$force"; then if test -e "$logfile" && test "$logfile" != "/dev/null" && test -z "$force"; then
log_index=$(ls $logfile.* 2>/dev/null | sort -V | tail -1 | sed -E 's/^.*\.([^.]*)$/\1/' || true) log_index=$(find . -maxdepth 1 -name "$logfile.*" 2>/dev/null | sort -V | tail -1 | sed -E 's/^.*\.([^.]*)$/\1/' || true)
logfile="$logfile".$(($log_index + 1)) logfile="$logfile".$(($log_index + 1))
fi fi
if test "$logfile" != "/dev/null"; then if test "$logfile" != "/dev/null"; then
@ -627,11 +644,12 @@ init_log()
init_vars() init_vars()
{ {
local host=`hostname` local host=
host=$(hostname)
local domain realm local domain realm
HOSTNAME_COMMON="$host" HOSTNAME_COMMON="$host"
HOSTNAME_SHORT=`hostname -s` HOSTNAME_SHORT=$(hostname -s)
HOSTNAME_FQDN=`hostname -f` HOSTNAME_FQDN=$(hostname -f)
NAMESERVER1=$(grep "^nameserver\s\+" /etc/resolv.conf | sed -e 's/^nameserver\s\+//' -e 's/\s/\n/' | head -1) NAMESERVER1=$(grep "^nameserver\s\+" /etc/resolv.conf | sed -e 's/^nameserver\s\+//' -e 's/\s/\n/' | head -1)
NAMESERVER2=$(grep "^nameserver\s\+" /etc/resolv.conf | sed -e 's/^nameserver\s\+//' -e 's/\s/\n/' | head -2 | tail -1) NAMESERVER2=$(grep "^nameserver\s\+" /etc/resolv.conf | sed -e 's/^nameserver\s\+//' -e 's/\s/\n/' | head -2 | tail -1)