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

localdump - extend by env

parent bd07c244
No related branches found
No related tags found
1 merge request!129Db Profiles
...@@ -32,8 +32,9 @@ ...@@ -32,8 +32,9 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
. `dirname $0`/jobhelper.sh . $(dirname $0)/jobhelper.sh
. `dirname $0`/inc_bash.sh . $(dirname $0)/inc_bash.sh
. $(dirname $0)/vendor/ini.class.sh
# if [ -r ~/.backup.conf ]; then # if [ -r ~/.backup.conf ]; then
# . ~/.backup.conf # . ~/.backup.conf
# fi # fi
...@@ -50,18 +51,147 @@ ...@@ -50,18 +51,147 @@
BACKUP_BASEDIR= BACKUP_BASEDIR=
BACKUP_PLUGINDIR= BACKUP_PLUGINDIR=
DBD_BASEDIR=plugins/localdump/profiles
declare -A DBD_PARAMS
DBD_DEBUG=0
# Cleanup local dumps older N days # Cleanup local dumps older N days
typeset -i BACKUP_KEEP_DAYS=0 typeset -i BACKUP_KEEP_DAYS=0
BACKUP_DATE= BACKUP_DATE=
# --------------------------------------------------------------------
#
# --------------------------------------------------------------------
# ---------- GETTER
function dbdetect._wd(){
test "$DBD_DEBUG" -eq "1" && echo "DEBUG: $*" >&2
}
function dbdetect.getConfigs(){
find ${DBD_BASEDIR} -type f -name "*.ini"
}
function dbdetect.getType(){
basename "$1" | cut -d "_" -f 1 | sed "s,\.ini$,,"
}
function dbdetect.getProfile(){
basename "$1" | cut -d "_" -f 1- | sed "s,\.ini$,,"
}
function dbdetect.exists(){
local _config="$1"
DBD_PARAMS=
local _found=0
# set file and inisection we read values from
ini.set "$_config" "detect"
# --- check tcp
local tcpport; tcpport=$( ini.value "tcp" )
local tcptarget; tcptarget=$( ini.value "tcp-target" )
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."
# --- check tcp process
local tcpprocess; tcpprocess=$( ini.value "tcp-process" )
if [ -n "$tcpprocess" ]; then
if ! netstat -tulpen 2>/dev/null | grep "^tcp.*:${tcpport} .*/${tcpprocess}" >/dev/null; then
# echo "No port tcp $tcpport available"
dbdetect._wd "... $tcpprocess not found for tcp ${tcpport}"
return 1
fi
dbdetect._wd "... tcp $tcpport is used by $tcpprocess."
fi
# --- check binaries
local binary; binary=$( ini.value "binary" )
if [ -n "${binary}" ]; then
for mybinary in $( echo "${binary}" | tr "," " " ); do
if ! j_requireBinary "$mybinary" 1 >/dev/null 2>&1; then
dbdetect._wd "... Missing binary: ${mybinary}"
return 1
fi
dbdetect._wd "... Binary: ${mybinary} was found"
done
fi
# --- check process
local process; process=$( ini.value "process" )
if [ -n "${process}" ]; then
if ! j_requireProcess "${process}" 1 >/dev/null; then
dbdetect._wd "... Missing process: ${process}"
return 1
fi
# if ! ps -eo command | grep -E "${process}" >/dev/null 2>&1; then
# dbdetect._wd "... Process ${process} was not found"
# return 1
# fi
dbdetect._wd "... Process ${process} was found"
fi
ini.set "$_config" "set"
local value
local dbuser=$( ini.value "dbuser" )
local dbpassword=$( ini.value "dbpassword" )
for mykey in $( ini.keys )
do
# params = '--port={{tcp}} --password={{dbpassword}} --user={{dbuser}} --host={{tcp-target}}'
value="$( ini.value "$mykey" )"
value="${value//\{\{tcp\}\}/$tcpport}"
value="${value//\{\{tcp-target\}\}/$tcptarget}"
value="${value//\{\{dbuser\}\}/$dbuser}"
value="${value//\{\{dbpassword\}\}/$dbpassword}"
DBD_PARAMS[$mykey]="$value"
done
return 0
}
# set a profile name
function dbdetect.setProfile(){
dbdetect.exists "${DBD_BASEDIR}/${PROFILENAME}.ini"
}
function dbdetect.getParams(){
echo "${DBD_PARAMS['params']}"
}
# set variables in [set] -> env = ...
# USAGE:
# eval $( dbdetect.setenv )
function dbdetect.setenv(){
echo "${DBD_PARAMS['env']}"
}
# unset variables from [set] -> env = ...
# USAGE:
# eval $( dbdetect.unsetenv )
function dbdetect.unssetenv(){
echo "${DBD_PARAMS['env']}" | grep -o '[a-z0-9]*=' | tr -d '=' | sed "s,^,unset ,"
}
function dbdetect.runas(){
echo "${DBD_PARAMS['su']}"
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS 4 DB-WRAPPER # FUNCTIONS 4 DB-WRAPPER
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
function db.init(){ function db.init(){
BACKUP_BASEDIR=`_j_getvar ${JOBFILE} "dir-localdumps"` BACKUP_BASEDIR=$(_j_getvar ${JOBFILE} "dir-localdumps")
# check # check
if [ -z "$BACKUP_BASEDIR" ]; then if [ -z "$BACKUP_BASEDIR" ]; then
...@@ -71,8 +201,8 @@ ...@@ -71,8 +201,8 @@
color reset color reset
exit 1 exit 1
fi fi
BACKUP_PLUGINDIR=`dirname $0`/plugins/localdump BACKUP_PLUGINDIR=$(dirname $0)/plugins/localdump
BACKUP_KEEP_DAYS=`_j_getvar ${JOBFILE} "keep-days"` BACKUP_KEEP_DAYS=$(_j_getvar ${JOBFILE} "keep-days")
if [ $BACKUP_KEEP_DAYS -eq 0 ]; then if [ $BACKUP_KEEP_DAYS -eq 0 ]; then
BACKUP_KEEP_DAYS=7 BACKUP_KEEP_DAYS=7
...@@ -88,8 +218,8 @@ ...@@ -88,8 +218,8 @@
# $myrc is last returncode - set in fetchrc # $myrc is last returncode - set in fetchrc
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
echo -n "gzip $1 ... " echo -n "gzip $_outfile ... "
gzip -9 -f "${1}" gzip -9 -f "${_outfile}"
fetchrc fetchrc
else else
cecho error "ERROR occured while dumping - no gzip of $_outfile" cecho error "ERROR occured while dumping - no gzip of $_outfile"
...@@ -115,7 +245,7 @@ ...@@ -115,7 +245,7 @@
find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print
color reset color reset
if [ `find "${BACKUP_TARGETDIR}" -type f | wc -l` -eq 0 ]; then if [ $(find "${BACKUP_TARGETDIR}" -type f | wc -l) -eq 0 ]; then
echo "INFO: the directory is empty - deleting it" echo "INFO: the directory is empty - deleting it"
rm -rf "${BACKUP_TARGETDIR}" rm -rf "${BACKUP_TARGETDIR}"
fi fi
...@@ -160,14 +290,23 @@ ...@@ -160,14 +290,23 @@
# param string name of a service # param string name of a service
function get_service_script(){ function get_service_script(){
local _service=$1 local _service=$1
ls -1 ${BACKUP_PLUGINDIR}/${_service}.sh 2>/dev/null local _type; _type=$( dbdetect.getType "$_service" )
ls -1 ${BACKUP_PLUGINDIR}/${_type}.sh 2>/dev/null
} }
# ------------------------------------------------------------ # ------------------------------------------------------------
# get a list of existing dumper scripts # get a list of existing dumper scripts
function get_services(){ function get_services(){
#ls -1 `dirname $0`/localdump_* | sed "s#`dirname $0`/localdump_##" | sed "s#\.sh##"
ls -1 ${BACKUP_PLUGINDIR}/*.sh | sed "s#${BACKUP_PLUGINDIR}/##" | sed "s#\.sh##" | sort #
# ls -1 ${BACKUP_PLUGINDIR}/*.sh | sed "s#${BACKUP_PLUGINDIR}/##" | sed "s#\.sh##" | sort
for config in $(dbdetect.getConfigs); do
if dbdetect.exists $config; then
echo "$( dbdetect.getProfile $config )"
fi
done
} }
# ------------------------------------------------------------ # ------------------------------------------------------------
...@@ -239,8 +378,8 @@ ...@@ -239,8 +378,8 @@
if [ -f $metafile ]; then if [ -f $metafile ]; then
cat $metafile cat $metafile
else else
sBasename=`basename $1` sBasename=$(basename $1)
sDb=`echo ${sBasename} | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g"` sDb=$(echo ${sBasename} | sed "s#__[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9].*##g")
if [ -z $sDb ]; then if [ -z $sDb ]; then
color error color error
echo ERROR: db name was not detected from file $1 echo ERROR: db name was not detected from file $1
...@@ -259,7 +398,7 @@ ...@@ -259,7 +398,7 @@
local _self local _self
_self=$( basename "$0" ) _self=$( basename "$0" )
echo "SYNTAX: " echo "SYNTAX: "
echo "$_self [[operation]] [Name_of_ervice] [[more services]]" echo "$_self [[operation]] [Name_of_service] [[more services]]"
echo echo
echo "$_self backup [Name_of_service]" echo "$_self backup [Name_of_service]"
echo "$_self restore [Name_of_service] [[file-to-restore]]" echo "$_self restore [Name_of_service] [[file-to-restore]]"
...@@ -287,7 +426,7 @@ ...@@ -287,7 +426,7 @@
# . /usr/local/bin/inc_cronfunctions.sh # . /usr/local/bin/inc_cronfunctions.sh
j_requireUser "root" j_requireUser "root"
h1 `date` IML BACKUP :: LOCALDUMP :: $* h1 $(date) IML BACKUP :: LOCALDUMP :: $*
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
color error color error
...@@ -321,6 +460,7 @@ ...@@ -321,6 +460,7 @@
# ------------------------------------------------------------ # ------------------------------------------------------------
backup) backup)
if [ "$SERVICENAME" = "ALL" ]; then if [ "$SERVICENAME" = "ALL" ]; then
services=$(get_services) services=$(get_services)
echo AUTO: calling local backup scripts for all known services echo AUTO: calling local backup scripts for all known services
echo $services echo $services
...@@ -345,24 +485,49 @@ ...@@ -345,24 +485,49 @@
fi fi
done done
# ----- GO # ----- GO
for SERVICENAME in $services # PROFILENAME mysql_localhost_13306
# SERVICENAME mysql
#
for PROFILENAME in $services
do do
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${SERVICENAME} if dbdetect.setProfile "${PROFILENAME}"; then
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
SERVICENAME=$( dbdetect.getType "$PROFILENAME" )
BACKUP_PARAMS=$( dbdetect.getParams )
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${PROFILENAME}
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
# ----- start service specific script
h2 "START SCRIPT FOR [${PROFILENAME}] -> ${SERVICENAME}"
# ------ set env
# dbdetect.setenv
eval $( dbdetect.setenv )
# echo "BACKUP_PARAMS = $BACKUP_PARAMS"
# ----- start service specific script _j_runHooks "200-before-db-service"
h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT" . $BACKUP_SCRIPT $mode
_j_runHooks "200-before-db-service"
. $BACKUP_SCRIPT $mode
test $rc -gt 0 && j_notify "db ${SERVICENAME}" "$BACKUP_SCRIPT $mode was finished with rc=$rc" $rc
_j_runHooks "230-after-db-service" "$rc"
# ----- post jobs: cleanup test $rc -gt 0 && j_notify "db ${SERVICENAME}" "$BACKUP_SCRIPT $mode was finished with rc=$rc" $rc
cleanup_backup_target _j_runHooks "230-after-db-service" "$rc"
show_info_backup_target
# ----- post jobs: cleanup
cleanup_backup_target
show_info_backup_target
# ------ unset env
eval $( dbdetect.unssetenv )
else
echo "SKIP: $PROFILENAME"
fi
done done
;; ;;
...@@ -392,12 +557,12 @@ ...@@ -392,12 +557,12 @@
echo echo
color input color input
sTargetDb=`guessDB ${dbfile}` sTargetDb=$(guessDB ${dbfile})
echo -n "new database name [$sTargetDb] >" echo -n "new database name [$sTargetDb] >"
color reset color reset
read sTargetDb read sTargetDb
if [ -z $sTargetDb ]; then if [ -z $sTargetDb ]; then
sTargetDb=`guessDB ${dbfile}` sTargetDb=$(guessDB ${dbfile})
fi fi
echo echo
...@@ -417,16 +582,36 @@ ...@@ -417,16 +582,36 @@
rc=$rc+1 rc=$rc+1
else else
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}" PROFILENAME="${sDumpfile//${BACKUP_BASEDIR}/}"
if [ $? -ne 0 -o $rc -ne 0 ]; then PROFILENAME="$( echo $PROFILENAME | sed "s,^/*,," | cut -f 1 -d '/')"
color error
echo ERROR: $mode failed. See ouput above. :-/ if dbdetect.setProfile "${PROFILENAME}"; then
color reset
else SERVICENAME=$( dbdetect.getType "$PROFILENAME" )
color ok
echo OK, $mode was successful. BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${PROFILENAME}
color reset BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
fi
BACKUP_PARAMS=$( dbdetect.getParams )
# ------ set env
eval $( dbdetect.setenv )
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
if [ $? -ne 0 -o $rc -ne 0 ]; then
color error
echo ERROR: $mode failed. See ouput above. :-/
color reset
else
color ok
echo OK, $mode was successful.
color reset
fi
# ------ unset env
eval $( dbdetect.unssetenv )
fi
fi fi
;; ;;
......
...@@ -48,14 +48,14 @@ SOURCE_DIR=/var/lib/mysql ...@@ -48,14 +48,14 @@ SOURCE_DIR=/var/lib/mysql
# it sets mysql_FOUND as flag # it sets mysql_FOUND as flag
function mysql._check(){ function mysql._check(){
j_requireBinary "mysql" 1 # j_requireBinary "mysql" 1
j_requireBinary "mysqldump" 1 # j_requireBinary "mysqldump" 1
j_requireProcess "mysqld|mariadb" 1 # j_requireProcess "mysqld|mariadb" 1
if [ ! -d $SOURCE_DIR ]; then # if [ ! -d $SOURCE_DIR ]; then
echo "INFO: directory $SOURCE_DIR doees not exist." # echo "INFO: directory $SOURCE_DIR doees not exist."
rc=$rc+1 # rc=$rc+1
fi # fi
# set flag and reset return code # set flag and reset return code
test $rc -eq 0 && mysql_FOUND=1 test $rc -eq 0 && mysql_FOUND=1
...@@ -71,7 +71,7 @@ function mysql._check(){ ...@@ -71,7 +71,7 @@ function mysql._check(){
# param string name of the dabase scheme # param string name of the dabase scheme
function mysql.db.create(){ function mysql.db.create(){
local _dbname=$1 local _dbname=$1
echo "CREATE DATABASE IF NOT EXISTS \`${_dbname}\`;" | mysql echo "CREATE DATABASE IF NOT EXISTS \`${_dbname}\`;" | mysql ${BACKUP_PARAMS}
fetchrc >/dev/null fetchrc >/dev/null
test $myrc -eq 0 && mysql_COUNT_CREATE+=1 test $myrc -eq 0 && mysql_COUNT_CREATE+=1
test $myrc -eq 0 || mysql_COUNT_ERRORS+=1 test $myrc -eq 0 || mysql_COUNT_ERRORS+=1
...@@ -89,14 +89,14 @@ function mysql.db.dump(){ ...@@ -89,14 +89,14 @@ function mysql.db.dump(){
local _dbname=$1 local _dbname=$1
local _dumpfile=$2 local _dumpfile=$2
mysqldump $LD_MYSQL_DUMP_PARAMS --result-file="$_dumpfile" "$_dbname" 2>&1 mysqldump ${BACKUP_PARAMS} $LD_MYSQL_DUMP_PARAMS --result-file="$_dumpfile" "$_dbname" 2>&1
fetchrc >/dev/null fetchrc >/dev/null
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
if ! zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null if ! zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null
then then
typeset -i local _iTables typeset -i local _iTables
_iTables=$( mysql --skip-column-names --batch -e "use $_dbname; show tables ;" | wc -l ) _iTables=$( mysql ${BACKUP_PARAMS} --skip-column-names --batch -e "use $_dbname; show tables ;" | wc -l )
if [ $_iTables -eq 0 ]; if [ $_iTables -eq 0 ];
then then
echo -n "EMPTY DATABASE ... " echo -n "EMPTY DATABASE ... "
...@@ -120,7 +120,7 @@ function mysql.db.dump(){ ...@@ -120,7 +120,7 @@ function mysql.db.dump(){
function mysql.db.import(){ function mysql.db.import(){
local _dumpfile=$1 local _dumpfile=$1
local _dbname=$2 local _dbname=$2
zcat "$_dumpfile" | mysql "${_dbname}" zcat "$_dumpfile" | mysql $BACKUP_PARAMS "${_dbname}"
fetchrc >/dev/null fetchrc >/dev/null
test $myrc -eq 0 && mysql_COUNT_IMPORT+=1 test $myrc -eq 0 && mysql_COUNT_IMPORT+=1
test $myrc -eq 0 || mysql_COUNT_ERRORS+=1 test $myrc -eq 0 || mysql_COUNT_ERRORS+=1
...@@ -129,7 +129,7 @@ function mysql.db.import(){ ...@@ -129,7 +129,7 @@ function mysql.db.import(){
# show a list of existing databases # show a list of existing databases
function mysql.db.list(){ function mysql.db.list(){
# mysql -Ee "show databases ;" | grep "^Database:" | awk '{ print $2 }' # mysql -Ee "show databases ;" | grep "^Database:" | awk '{ print $2 }'
local _result=$( mysql -Ee "show databases ;" ) local _result=$( mysql ${BACKUP_PARAMS} -Ee "show databases ;" $BACKUP_PARAMS )
fetchrc >/dev/null fetchrc >/dev/null
test $myrc -eq 0 && mysql_COUNT_DB=$( echo "$_result" | grep -c "^Database:" ) test $myrc -eq 0 && mysql_COUNT_DB=$( echo "$_result" | grep -c "^Database:" )
test $myrc -eq 0 && echo "$_result" | grep "^Database:" | awk '{ print $2 }' test $myrc -eq 0 && echo "$_result" | grep "^Database:" | awk '{ print $2 }'
...@@ -144,7 +144,8 @@ function mysql.db.list(){ ...@@ -144,7 +144,8 @@ function mysql.db.list(){
# USAGE: to abort a function if not available: # USAGE: to abort a function if not available:
# mysql.available || return # mysql.available || return
function mysql.available(){ function mysql.available(){
typeset -i local _rc=(1-$mysql_FOUND) local _rc;
typeset -i _rc=(1-$mysql_FOUND)
return $_rc return $_rc
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 2024-02-04 v0.1 Initial version # 2024-02-04 v0.1 Initial version
# 2024-02-08 v0.2 add ini.varexport; improve replacements of quotes # 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
# ====================================================================== # ======================================================================
INI_FILE= INI_FILE=
...@@ -23,7 +25,7 @@ function ini.set(){ ...@@ -23,7 +25,7 @@ function ini.set(){
INI_FILE= INI_FILE=
INI_SECTION= INI_SECTION=
if [ ! -f "$1" ]; then if [ ! -f "$1" ]; then
echo "ERROR: file does not exist: $1" echo "ERROR: file does not exists: $1"
exit 1 exit 1
fi fi
INI_FILE="$1" INI_FILE="$1"
...@@ -56,29 +58,31 @@ function ini.setsection(){ ...@@ -56,29 +58,31 @@ function ini.setsection(){
# Get all sections # Get all sections
# param1 - name of the ini file # param1 - name of the ini file
function ini.sections(){ function ini.sections(){
local myfile=$1 local myinifile=${1:-$INI_FILE}
grep "^\[" "$myfile" | sed 's,^\[,,' | sed 's,\].*,,' grep "^\[" "$myinifile" | sed 's,^\[,,' | sed 's,\].*,,'
} }
# Get all content inside a section # Get all content inside a section
# param1 - name of the ini file # param1 - name of the ini file
# param2 - name of the section in ini file # param2 - name of the section in ini file
function ini.section(){ function ini.section(){
local myfile=$1 local myinifile=${1:-$INI_FILE}
local mysection=$2 local myinisection=${2:-$INI_SECTION}
sed -e "0,/^\[${mysection}\]/ d" -e '/^\[/,$ d' $myfile | grep -v "^[#;]" sed -e "0,/^\[${myinisection}\]/ d" -e '/^\[/,$ d' $myinifile \
| grep -v "^[#;]" \
| sed -e "s/^[ \t]*//g" -e "s/[ \t]*=[ \t]*/=/g"
} }
# Get all keys inside a section # Get all keys inside a section
# param1 - name of the ini file # param1 - name of the ini file
# param2 - name of the section in ini file # param2 - name of the section in ini file
function ini.keys(){ function ini.keys(){
local myfile=${1:-$INI_FILE} local myinifile=${1:-$INI_FILE}
local mysection=${2:-$INI_SECTION} local myinisection=${2:-$INI_SECTION}
ini.section "${myinifile}" "${myinisection}" \
ini.section "${myfile}" "${mysection}" \
| grep "^[\ \t]*[^=]" \ | grep "^[\ \t]*[^=]" \
| cut -f 1 -d "=" | cut -f 1 -d "=" \
| sort -u
} }
...@@ -93,17 +97,15 @@ function ini.value(){ ...@@ -93,17 +97,15 @@ function ini.value(){
elif [ -z "$2" ]; then elif [ -z "$2" ]; then
ini.value "$INI_FILE" "$INI_SECTION" "$1" ini.value "$INI_FILE" "$INI_SECTION" "$1"
else else
local myfile=$1 local myinifile=$1
local mysection=$2 local myinisection=$2
local myvarname=$3 local myvarname=$3
local out local out
out=$(ini.section "${myfile}" "${mysection}" \ out=$(ini.section "${myinifile}" "${myinisection}" \
| grep "^[\ \t]*${myvarname}[\ \t]*=.*" \ | grep "^[\ \t]*${myvarname}[\ \t]*=.*" \
| cut -f 2- -d "=" \ | cut -f 2- -d "=" \
| sed -e 's,^\ *,,' -e 's, *$,,' | sed -e 's,^\ *,,' -e 's, *$,,'
) )
# if value does not end with [] than the last found value wins
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 # delete quote chars on start and end
...@@ -120,16 +122,16 @@ function ini.value(){ ...@@ -120,16 +122,16 @@ function ini.value(){
# param string ini file to read # param string ini file to read
function ini.varexport(){ function ini.varexport(){
local myprefix="$1" local myprefix="$1"
local myfile="$2" local myinifile="$2"
local var= local var=
for mysection in $(ini.sections "$myfile"); do for myinisection in $(ini.sections "$myinifile"); do
var="${myprefix}${mysection}" var="${myprefix}${myinisection}"
echo "declare -A ${var}; " echo "declare -A ${var}; "
echo "export ${var}; " echo "export ${var}; "
for mykey in $(ini.keys "$myfile" "$mysection"); do for mykey in $(ini.keys "$myinifile" "$myinisection"); do
value="$(ini.value "$myfile" "$mysection" "$mykey")" value="$(ini.value "$myinifile" "$myinisection" "$mykey")"
echo ${var}[$mykey]="\"$value\"" echo ${var}[$mykey]="\"$value\""
done done
done done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment