Skip to content
Snippets Groups Projects
Commit f7f878f6 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

shell fixes in dbdetect functions

parent 0e96a36c
No related branches found
No related tags found
1 merge request!129Db Profiles
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
# before using these functions. # before using these functions.
# #
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# ah - Axel Hahn <axel.hahn@unibe.ch>
#
# 2024-03-15 ah v1.0 first public version
# ====================================================================== # ======================================================================
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -20,7 +23,7 @@ ...@@ -20,7 +23,7 @@
DBD_BASEDIR=plugins/localdump/profiles DBD_BASEDIR=plugins/localdump/profiles
declare -A DBD_PARAMS declare -A DBD_PARAMS
DBD_INI= DBD_INIFILE=
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -37,19 +40,19 @@ function dbdetect._wd(){ ...@@ -37,19 +40,19 @@ function dbdetect._wd(){
# param string regex to find in ps -ef output # param string regex to find in ps -ef output
# param bool flag to skip; default: none = abort on miss # param bool flag to skip; default: none = abort on miss
function dbdetect._requireProcess(){ function dbdetect._requireProcess(){
# echo "CHECK process $1" # echo "CHECK process $1"
# ps -ef | grep -v grep | grep -E "$1" >/dev/null # ps -ef | grep -v grep | grep -E "$1" >/dev/null
pgrep -l "$1" >/dev/null pgrep -l "$1" >/dev/null
rcself=$? rcself=$?
if [ $rcself -ne 0 ]; then if [ $rcself -ne 0 ]; then
rc=$rc+$rcself rc=$rc+$rcself
echo "INFO: missing process $1" echo "INFO: missing process $1"
if [ -z "$2" ]; then if [ -z "$2" ]; then
exit 4 exit 4
fi
return 1
fi fi
return 1 return 0
fi
return 0
} }
# get a list of all config files # get a list of all config files
...@@ -77,7 +80,7 @@ function dbdetect.validate(){ ...@@ -77,7 +80,7 @@ function dbdetect.validate(){
local _config="${1:-$DBD_INIFILE}" local _config="${1:-$DBD_INIFILE}"
# show errors in profile ini files # 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 # check if the requirements for a database match
...@@ -85,7 +88,7 @@ function dbdetect.validate(){ ...@@ -85,7 +88,7 @@ function dbdetect.validate(){
function dbdetect.exists(){ function dbdetect.exists(){
local _config="$1" local _config="$1"
DBD_PARAMS= DBD_PARAMS=()
local _found=0 local _found=0
...@@ -101,14 +104,14 @@ function dbdetect.exists(){ ...@@ -101,14 +104,14 @@ function dbdetect.exists(){
# --- check tcp # --- check tcp
local tcpport; tcpport=$( ini.value "tcp-port" ) local tcpport; tcpport=$( ini.value "tcp-port" )
if [ -n "$tcpport" ]; then if [ -n "$tcpport" ]; then
local tcptarget; tcptarget=$( ini.value "tcp-target" ) local tcptarget; tcptarget=$( ini.value "tcp-target" )
tcptarget=${tcptarget:-localhost} tcptarget=${tcptarget:-localhost}
if { ! >/dev/tcp/$tcptarget/$tcpport; } > /dev/null 2>&1; then if { ! >/dev/tcp/$tcptarget/$tcpport; } > /dev/null 2>&1; then
# echo "No port tcp $tcpport available" # echo "No port tcp $tcpport available"
dbdetect._wd "... No port tcp $tcpport available on $tcptarget" dbdetect._wd "... No port tcp $tcpport available on $tcptarget"
return 1 return 1
fi fi
dbdetect._wd "... Found tcp $tcpport on $tcptarget." dbdetect._wd "... Found tcp $tcpport on $tcptarget."
fi fi
# --- check tcp process # --- check tcp process
...@@ -140,7 +143,7 @@ function dbdetect.exists(){ ...@@ -140,7 +143,7 @@ function dbdetect.exists(){
local filetype; filetype=$( ini.value "type" ) local filetype; filetype=$( ini.value "type" )
if [ -n "${filetype}" ]; then if [ -n "${filetype}" ]; then
local myfiles; declare -a myfiles local myfiles
for myfile in $( ini.value "file[]" ) for myfile in $( ini.value "file[]" )
do do
if ! file -b "${myfile}" | grep -i "$filetype" >/dev/null; then if ! file -b "${myfile}" | grep -i "$filetype" >/dev/null; then
...@@ -173,8 +176,8 @@ function dbdetect.exists(){ ...@@ -173,8 +176,8 @@ function dbdetect.exists(){
ini.set "$_config" "set" ini.set "$_config" "set"
local value local value
local dbuser=$( ini.value "dbuser" ) local dbuser; dbuser=$( ini.value "dbuser" )
local dbpassword=$( ini.value "dbpassword" ) local dbpassword; dbpassword=$( ini.value "dbpassword" )
for mykey in env params for mykey in env params
do do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment