fnc_mc_file.inc.sh 2.39 KB
#!/bin/bash

#
#	function liest eine php config.php Datei ein und gibt sie für bash frei
#	@param string $1 - php Datei die eingelesen werden soll
#	@param bool $2 - optional $2=1 create Temp dir 
#
mc_readPhpConfig() {

	i=0
	content=''
	IFSoriginal=$IFS
	while read zeile; do
		content=$content''$zeile
		i=`expr $i + 1`
	done<$1

	content=$(sed -e '/\/\*/,/*\//d' -e '/\/\//d' -e '/^$/d' $1)
	content=$(echo $content | sed  's/<?php//g')
	content=$(echo $content | sed  's/<?//g')
	content=$(echo $content | sed  's/?>//g')

	IFS=";"
	orders=($content)
	IFS=""


 	if [ $# -gt 1 ]  ; then
 		if [ $2 -eq 1 ]  ; then
			mc_bashsu "mkdir $__PATH_to_Temp " 1
			mc_bashsu "chmod 777 $__PATH_to_Temp -R" 1
			mc_bashsu "ls -al $__PATH_to_Temp/../ " 1
 		fi
 	fi
	tempfile=$__PATH_to_Temp'/mc_readPhpConfig.tmp'
	echo '#!/bin/bash' > $tempfile

# if [ -f "$tempfile" ]  ;
# 	mc_e "$tempfile"
# 	then
# 	mc_dialogMessage "ERROR: $tempfile konnte nicht geschrieben werden!!!"
# 	mc_bashsu "ls -al $__PATH_to_Temp " 1
# 	mc_bashsu "ls -al $tempfile " 1
# 	mc_bashsu "more $tempfile " 1
# 	exit
# fi

	for((i=0;i<${#orders};i++)); do
		if [ ${orders[$i]}"" != "" ]; then

			vars[$i]=$(echo ${orders[$i]} | egrep -r -T  -E "^[[:blank:]]*[$]{1}[[:alpha:]_]{1}[_[:alnum:]]*[ ]*=.*$")
			vars[$i]=$(echo ${vars[$i]} | sed  's/\$//g')
			vars[$i]=$(echo ${vars[$i]} | sed  's/ //g')
			if [ ${vars[$i]}"" != "" ]; then
				IFS="="
				var=(${vars[$i]})
				IFS=""

				array_var=$(echo ${var[1]} | egrep -r -T -E "[[:blank:]]*array[[:blank:]]*\(.*\)" | sed -r 's/\(.*\)//g') 
				if [ $array_var"" != "array" ]; then
					array_var=${var[1]}
				fi
				echo ${var[0]}=$array_var >> $tempfile
			fi

			arrays[$i]=$(echo ${orders[$i]} | egrep -r -T -E "^[[:blank:]]*[$]{1}[[:alpha:]_]{1}[_[:alnum:]]*[\[][\"\'][_[:alnum:]]*[\"\']"[\]])
			arrays[$i]=$(echo ${arrays[$i]} | sed  's/\$//g')
			arrays[$i]=$(echo ${arrays[$i]} | sed  's/ //g')

			if [ ${arrays[$i]}"" != "" ]; then
				IFS="="
				array=(${arrays[$i]})
				IFS=""

				array_var=$(echo ${array[1]} | egrep -r -T -E "[[:blank:]]*array[[:blank:]]*\(.*\)" | sed -r 's/\(.*\)//g')
				if [ $array_var"" != "array" ]; then
					array_var=${array[1]}
				fi

				array_name=$(echo ${array[0]} | sed  -e 's/\[/_/g' -e 's/]//g' -e 's/"//g' -r -e "s/'//g" )
# 				echo $array_name=${array[1]} >> $tempfile
				echo $array_name=$array_var >> $tempfile
			fi

		fi
	done
	. $tempfile
	IFS=$IFSoriginal
}