diff --git a/includes/dbdetect.class.sh b/includes/dbdetect.class.sh index 2a366c2474d17814434a4b0123d4bf6211ad0d41..03a67e920c81c8a201fca731ae952de89498d2f8 100644 --- a/includes/dbdetect.class.sh +++ b/includes/dbdetect.class.sh @@ -11,6 +11,9 @@ # before using these functions. # # ---------------------------------------------------------------------- +# ah - Axel Hahn <axel.hahn@unibe.ch> +# +# 2024-03-15 ah v1.0 first public version # ====================================================================== # ---------------------------------------------------------------------- @@ -20,7 +23,7 @@ DBD_BASEDIR=plugins/localdump/profiles declare -A DBD_PARAMS -DBD_INI= +DBD_INIFILE= # ---------------------------------------------------------------------- @@ -37,19 +40,19 @@ function dbdetect._wd(){ # param string regex to find in ps -ef output # param bool flag to skip; default: none = abort on miss function dbdetect._requireProcess(){ - # echo "CHECK process $1" - # ps -ef | grep -v grep | grep -E "$1" >/dev/null - pgrep -l "$1" >/dev/null - rcself=$? - if [ $rcself -ne 0 ]; then - rc=$rc+$rcself - echo "INFO: missing process $1" - if [ -z "$2" ]; then - exit 4 + # echo "CHECK process $1" + # ps -ef | grep -v grep | grep -E "$1" >/dev/null + pgrep -l "$1" >/dev/null + rcself=$? + if [ $rcself -ne 0 ]; then + rc=$rc+$rcself + echo "INFO: missing process $1" + if [ -z "$2" ]; then + exit 4 + fi + return 1 fi - return 1 - fi - return 0 + return 0 } # get a list of all config files @@ -77,7 +80,7 @@ function dbdetect.validate(){ local _config="${1:-$DBD_INIFILE}" # show errors in profile ini files - ini.validate "$_config" "$( dirname $0)/includes/dbdetect_validate_profile_ini.sh" 0 && dbdetect._wd "OK: Validation of '$_config' successful" + ini.validate "$_config" "$( dirname "$0")/includes/dbdetect_validate_profile_ini.sh" 0 && dbdetect._wd "OK: Validation of '$_config' successful" } # check if the requirements for a database match @@ -85,7 +88,7 @@ function dbdetect.validate(){ function dbdetect.exists(){ local _config="$1" - DBD_PARAMS= + DBD_PARAMS=() local _found=0 @@ -101,14 +104,14 @@ function dbdetect.exists(){ # --- check tcp local tcpport; tcpport=$( ini.value "tcp-port" ) if [ -n "$tcpport" ]; then - local tcptarget; tcptarget=$( ini.value "tcp-target" ) - tcptarget=${tcptarget:-localhost} - if { ! >/dev/tcp/$tcptarget/$tcpport; } > /dev/null 2>&1; then - # echo "No port tcp $tcpport available" - dbdetect._wd "... No port tcp $tcpport available on $tcptarget" - return 1 - fi - dbdetect._wd "... Found tcp $tcpport on $tcptarget." + local tcptarget; tcptarget=$( ini.value "tcp-target" ) + tcptarget=${tcptarget:-localhost} + if { ! >/dev/tcp/$tcptarget/$tcpport; } > /dev/null 2>&1; then + # echo "No port tcp $tcpport available" + dbdetect._wd "... No port tcp $tcpport available on $tcptarget" + return 1 + fi + dbdetect._wd "... Found tcp $tcpport on $tcptarget." fi # --- check tcp process @@ -140,7 +143,7 @@ function dbdetect.exists(){ local filetype; filetype=$( ini.value "type" ) if [ -n "${filetype}" ]; then - local myfiles; declare -a myfiles + local myfiles for myfile in $( ini.value "file[]" ) do if ! file -b "${myfile}" | grep -i "$filetype" >/dev/null; then @@ -173,8 +176,8 @@ function dbdetect.exists(){ ini.set "$_config" "set" local value - local dbuser=$( ini.value "dbuser" ) - local dbpassword=$( ini.value "dbpassword" ) + local dbuser; dbuser=$( ini.value "dbuser" ) + local dbpassword; dbpassword=$( ini.value "dbpassword" ) for mykey in env params do