diff --git a/plugins/localdump/mysql.sh b/plugins/localdump/mysql.sh index e5a9d2d39e9dacf2fc0931142709ef1995eace91..9d907b06f7e5281ae5ed747b77fcbea670de85e9 100755 --- a/plugins/localdump/mysql.sh +++ b/plugins/localdump/mysql.sh @@ -48,8 +48,8 @@ SOURCE_DIR=/var/lib/mysql # it sets mysql_FOUND as flag function mysql._check(){ - # j_requireBinary "mysql" 1 - # j_requireBinary "mysqldump" 1 + j_requireBinary "mysql" 1 + j_requireBinary "mysqldump" 1 # j_requireProcess "mysqld|mariadb" 1 # if [ ! -d $SOURCE_DIR ]; then diff --git a/plugins/localdump/profiles/couchdb2.ini b/plugins/localdump/profiles/couchdb2.ini new file mode 100644 index 0000000000000000000000000000000000000000..72d42d68b22a8e4f5ae3326e46baf26dfc7a89bc --- /dev/null +++ b/plugins/localdump/profiles/couchdb2.ini @@ -0,0 +1,23 @@ +# ====================================================================== +# +# LOCAL COUCHDB SERVER +# +# ====================================================================== + +[detect] + +tcp = 5984 +tcp-target = localhost +tcp-process = 'beam.smp' + + +[set] + +su = '' +dbuser = 'admin' +dbpassword = 'HereIsMyAdminPassword' + +params = '' +env = 'export COUCH_URL=http://{{dbuser}}:{{dbpassword}}@{{tcp-target}}:{{tcp-port}}/' + +# ---------------------------------------------------------------------- diff --git a/plugins/localdump/profiles/mysql.ini b/plugins/localdump/profiles/mysql.ini index 058f461ea27a324301c3ad2ac584f7c4369f1f39..654df4d2199275fa4ebc4df26c3850915390303a 100644 --- a/plugins/localdump/profiles/mysql.ini +++ b/plugins/localdump/profiles/mysql.ini @@ -1,34 +1,24 @@ -# ---------------------------------------------------------------------- -# what to detect -# ---------------------------------------------------------------------- +# ====================================================================== +# +# LOCAL MYSQL INSTANCE +# +# ====================================================================== [detect] -# binaries that must befound, comma seperated -binary = 'mysql,mysqldump' -# a running process that must be found process = 'mysqld|mariadb' - -# a port that must be open on a given host tcp = 3306 tcp-target = localhost - -# process that opens a port (see netstat -tulpen) - works for local services only -# "slirp4netns" is docker network stack -# "rootlesskit" is docker too tcp-process = 'mysqld|mariadbd' -# ---------------------------------------------------------------------- -# data to apply if it was found -# ---------------------------------------------------------------------- [set] su = '' -dbuser = 'root' -dbpassword = '12345678' +dbuser = '' +dbpassword = '' -# unschön - das ist in der Prozessliste -params = '--port={{tcp}} --password={{dbpassword}} --user={{dbuser}} --host={{tcp-target}}' +params = '' +env = '' # ---------------------------------------------------------------------- diff --git a/plugins/localdump/profiles/sqlite.ini b/plugins/localdump/profiles/sqlite.ini new file mode 100644 index 0000000000000000000000000000000000000000..1b7133a1a6c8ade871a9689bce5b0f116e9997f7 --- /dev/null +++ b/plugins/localdump/profiles/sqlite.ini @@ -0,0 +1,25 @@ +# ====================================================================== +# +# LOCAL SQLITE DATABASES +# +# ====================================================================== + +[detect] +# ---------------------------------------------------------------------- +# what to detect +# ---------------------------------------------------------------------- + +# file[] = "/var/www/database/logs.db" +type = "sqlite" + + +[set] + +su = '' +dbuser = '' +dbpassword = '' + +params = '' +env = '' + +# ---------------------------------------------------------------------- diff --git a/vendor/ini.class.sh b/vendor/ini.class.sh index 0392d80547e66c19456fe25c38c7954c12182a9d..1bd38e13345435b7effb4b3971b5577d619a43c9 100644 --- a/vendor/ini.class.sh +++ b/vendor/ini.class.sh @@ -4,11 +4,18 @@ # READ INI FILE with Bash # https://axel-hahn.de/blog/2018/06/08/bash-ini-dateien-parsen-lesen/ # +# Author: Axel hahn +# License: GNU GPL 3.0 +# Source: https://github.com/axelhahn/bash_iniparser +# Docs: https://www.axel-hahn.de/docs/bash_iniparser/ +# # ---------------------------------------------------------------------- # 2024-02-04 v0.1 Initial version # 2024-02-08 v0.2 add ini.varexport; improve replacements of quotes # 2024-02-10 v0.3 handle spaces and tabs around vars and values # 2024-02-12 v0.4 rename local varables +# 2024-02-20 v0.5 handle special chars in keys; add ini.dump + ini.help +# 2024-02-21 v0.6 harden ini.value for keys with special chars; fix fetching last value # ====================================================================== INI_FILE= @@ -25,7 +32,7 @@ function ini.set(){ INI_FILE= INI_SECTION= if [ ! -f "$1" ]; then - echo "ERROR: file does not exists: $1" + echo "ERROR: file does not exist: $1" exit 1 fi INI_FILE="$1" @@ -101,12 +108,16 @@ function ini.value(){ local myinisection=$2 local myvarname=$3 local out + regex="${myvarname//[^a-zA-Z0-9:()]/.}" out=$(ini.section "${myinifile}" "${myinisection}" \ - | grep "^[\ \t]*${myvarname}[\ \t]*=.*" \ + | sed "s,^[\ \t]*,,g" \ + | sed "s,[\ \t]*=,=,g" \ + | grep -F "${myvarname}=" \ + | grep "^${regex}=" \ | cut -f 2- -d "=" \ | sed -e 's,^\ *,,' -e 's, *$,,' ) - grep "\[\]$" <<< "myvarname" >/dev/null && out="echo $out | tail -1" + grep "\[\]$" <<< "$myvarname" >/dev/null || out="$( echo "$out" | tail -1 )" # delete quote chars on start and end grep '^".*"$' <<< "$out" >/dev/null && out=$(echo "$out" | sed -e's,^"\(.*\)"$,\1,g') @@ -115,6 +126,99 @@ function ini.value(){ fi } +# dump the ini file for visuall check of the parsing functions +# param string filename +ini.dump() { + local myinifile=${1:-$INI_FILE} + echo -en "\e[1;33m" + echo "+----------------------------------------" + echo "|" + echo "| $myinifile" + echo "|" + echo -e "+----------------------------------------\e[0m" + echo -e "\e[34m" + cat "$myinifile" | sed "s,^, ,g" + echo -e "\e[0m" + + echo " Parsed data:" + echo + ini.sections "$myinifile" | while read -r myinisection; do + echo -e " --+-- section \e[35m[$myinisection]\e[0m" + echo " |" + ini.keys "$myinifile" "$myinisection" | while read -r mykey; do + value="$(ini.value "$myinifile" "$myinisection" "$mykey")" + # printf " %-15s => %s\n" "$mykey" "$value" + printf " \`---- %-20s => " "$mykey" + echo -e "\e[1;36m$value\e[0m" + done + echo + done + echo +} + +function ini.help(){ + cat <<EOH + + INI.CLASS.SH + + A bash implementation to read ini files. + + Author: Axel hahn + License: GNU GPL 3.0 + Source: https://github.com/axelhahn/bash_iniparser + Docs: https://www.axel-hahn.de/docs/bash_iniparser/ + + Usage: + + (1) + source the file ini.class.sh + + (2) + ini.help + to show this help with all available functions. + + + BASIC ACCESS: + + ini.value <FILE> <SECTION> <KEY> + Get a avlue of a variable in a given section. + + Tho shorten ini.value with 3 parameters: + + ini.set <FILE> [<SECTION>] + + or + + ini.set <FILE> + ini.setsection <SECTION> + + This sets the ini file and/ or section as default. + Afterwards you can use: + + ini.value <KEY> + and + ini.value <SECTION> <KEY> + + OTHER GETTERS: + + ini.sections <FILE> + Get all sections in the ini file. + The <FILE> is not needed if ini.set <FILE> was used before. + + ini.keys <FILE> <SECTION> + Get all keys in the given section. + The <FILE> is not needed if ini.set <FILE> was used before. + The <SECTION> is not needed if ini.setsection <SECTION> was used + before. + + ini.dump <FILE> + Get a nice overview of the ini file. + You get a colored view of the content and a parsed view of the + sections and keys + values. + +EOH +} + # Create bash code to export all variables as hash. # Example: eval "$( ini.varexport "cfg_" "$inifile" )" #