fnc_mc_file.inc.sh
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/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
}