-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·82 lines (67 loc) · 2.14 KB
/
gen.sh
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
#!/bin/bash
if [[ ! $(command -v dot) ]];then
lsb_os=$(grep -o '^ID=.*$' /etc/os-release | cut -d'=' -f2)
if [[ ${lsb_os} =~ "ubuntu" ]];then
sudo apt install graphviz libxml2 -y
elif [[ ${lsb_os} =~ "manjaro" ]] || [[ ${lsb_os} == "arch" ]];then
sudo pacman -Sy graphviz libxml2 --noconfirm
elif [[ ${lsb_os} =~ "fedora" ]];then
sudo yum install -y graphviz libxml2
elif [[ ${lsb_os} =~ "solus" ]];then
sudo eopkg it graphviz libxml2
fi
fi
str_to_arr(){
OLD_IFS="$IFS"
IFS="$2"
str_to_arr_result=($1)
IFS="$OLD_IFS"
}
write_txt(){
cat>${graphviz_name}.txt<<EOF
digraph regexp {
rankdir=RL;
node[shape=box,style=filled,color=lightblue,nodesep=4.0];
graph [ overlap=false ];
// Generated map body
${graphviz_lines_add}
}
EOF
}
handle_routes(){
# audio_policy_configuration.xml
adp_source=$1
graphviz_name=$2
lines_tmp=lines.txt
if [[ ! $1 ]];then echo "[ - ] No input audio_policy_configuration.xml" && exit;fi
if [[ $graphviz_name == "" ]];then graphviz_name='audio_graphviz';fi
# Gnerate lines.txt
cat>$lines_tmp<<LINESEOF
// body follows
LINESEOF
route_list_arg0="$(xmllint --xpath '//audioPolicyConfiguration/modules/module/routes/route[@type="mix"]/@sink' $adp_source | sed 's/"//g' | sed 's/ sink=//g' | sed ':a;N;$!ba;s/\n/!/g')"
str_to_arr "${route_list_arg0}" '!'
for route in "${str_to_arr_result[@]}"
do
cmd_get_route_source="xmllint --xpath 'string(//audioPolicyConfiguration/modules/module/routes/route[@sink=\"$route\"]/@sources)' $adp_source"
route_sources_str="$(eval $cmd_get_route_source)"
#echo "[$route]: ${route_sources_str}"
sed -i '$a\ \/\/ '"$route"'' $lines_tmp
str_to_arr "${route_sources_str}" ','
for route_source in "${str_to_arr_result[@]}"
do
#echo "$route_source -> $route"
graphviz_new_line="\"$route_source\" -> \"$route\";"
sed -i '$a '"$graphviz_new_line"'' $lines_tmp
#echo "$route <- $route_source"
done
sed -i '$a\ \n' $lines_tmp
#echo '-----------------'
done
graphviz_lines_add="$(cat $lines_tmp | uniq)"
write_txt
rm -f $lines_tmp
dot -Tpng ${graphviz_name}.txt -o ${graphviz_name}.png
echo "[ + ] Generated at ${graphviz_name}.png "
}
handle_routes $1 $2