Organized dependencies of xpath
[staging/basesystem.git] / agl-basefiles / bin / launch_xml2cfg.sh
1 #!/bin/bash
2 #
3 # @copyright Copyright (c) 2019 TOYOTA MOTOR CORPORATION.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 #Since xpath is slow, use sed as much as possible.
19
20 infile=$1
21 main_file=system_launcher_main.xml
22 body_file=system_launcher_body.xml
23
24
25 #check xmllint is exist
26 if ! which xmllint > /dev/null ; then
27   echo "It need xmllint. Please install it."
28   exit 1;
29 fi
30
31 #check xpath is exist
32 if ! which xpath > /dev/null ; then
33   echo "It need xpath Please install it."
34   exit 1;
35 fi
36
37 #arg check
38 if ! [[ "$infile" =~ .+\.xml ]] ;then
39   echo "$infile is not *.xml"
40   exit 1
41 elif ! [ -e $infile ];then
42   echo "$infile not found"
43   exit 1
44 fi
45
46 cp -f $infile $body_file
47
48 #check xml vaild
49 if ! xmllint --noout --valid $main_file ;then
50   echo "XML is Invalid. "
51   exit 1;
52 fi
53
54 #Format into xpath and read into memory
55 xmem=`xpath -q -e /system_launcher $main_file`
56
57 echo "#  This file is created from $infile."
58 echo "#  created date : `LANG=en date`"
59 echo "[ModulesLaunchConfig]"
60
61 #GROUP LOOP
62 group_num=`echo $xmem | xpath -e /system_launcher/group 2>&1 | grep Found | cut -d ' ' -f2`
63
64 l_idx=1
65 cur_group=1
66 until [ $cur_group -gt $group_num ];
67 do
68   #LAUNCH LOOP
69   group_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]`  #ALL XML text for group
70   group_attr=`echo $group_text | sed 's/\(<group[^>]\+>\)\(.*\)/\1/g'`
71
72   g_name=`echo $group_attr | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'`
73   g_wait_time=`echo $group_attr | sed 's/\(.* wait_time="\)\([^"]*\)\(.*\)/\2/g'`
74   g_trigger=`echo $group_attr | sed 's/\(.* trigger="\)\([^"]*\)\(.*\)/\2/g'`
75
76 #  echo $g_name $g_wait_time $g_trigger
77   l_launch_num=`echo $xmem | xpath -e /system_launcher/group[$cur_group]/launch  2>&1 | grep Found | cut -d ' ' -f2`
78
79   cur_launch=1;
80   until [ $cur_launch -gt $l_launch_num ];  do
81     launch_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]/launch[$cur_launch]`
82
83     l_attr="Launch${l_idx}=$g_name|$cur_group|$g_wait_time|$g_trigger"
84     l_attr+="|"`echo $launch_text | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'`
85     l_attr+="|"`echo $launch_text | sed 's/\(.* path="\)\([^"]*\)\(.*\)/\2/g'`
86     l_attr+="|"`echo $launch_text | sed 's/\(.* priority="\)\([^"]*\)\(.*\)/\2/g'`
87     l_attr+="|"`echo $launch_text | sed 's/\(.* critical="\)\([^"]*\)\(.*\)/\2/g'`
88     l_attr+="|"`echo $launch_text | sed 's/\(.* retry_cnt="\)\([^"]*\)\(.*\)/\2/g'`
89     l_attr+="|"`echo $launch_text | sed 's/\(.* arguments="\)\([^"]*\)\(.*\)/\2/g'`
90     l_attr+="|"`echo $launch_text | sed 's/\(.* logging_mask="\)\([^"]*\)\(.*\)/\2/g'`
91     l_attr+="|"`echo $launch_text | sed 's/\(.* restart="\)\([^"]*\)\(.*\)/\2/g'`
92     l_attr+="|"`echo $launch_text | sed 's/\(.* is_start_required="\)\([^"]*\)\(.*\)/\2/g'`
93     l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_critical="\)\([^"]*\)\(.*\)/\2/g'`
94     l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'`
95     l_attr+="|"`echo $launch_text | sed 's/\(.* fast_shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'`
96     l_attr+="|"`echo $launch_text | sed 's/\(.* user_name="\)\([^"]*\)\(.*\)/\2/g'`
97     if echo "$launch_text" | grep -sq 'is_agl_unit=' ; then
98       l_attr+="|"`echo $launch_text | sed 's/\(.* is_agl_unit="\)\([^"]*\)\(.*\)/\2/g'`
99     else
100       l_attr+="|"
101     fi
102     if echo "$launch_text" | grep -sq 'disable_agl_resethistory=' ; then
103       l_attr+="|"`echo $launch_text | sed 's/\(.* disable_agl_resethistory="\)\([^"]*\)\(.*\)/\2/g'`
104     else
105       l_attr+="|"
106     fi
107     if echo "$launch_text" | grep -sq 'disable_nonagl_resethistory=' ; then
108       l_attr+="|"`echo $launch_text | sed 's/\(.* disable_nonagl_resethistory="\)\([^"]*\)\(.*\)/\2/g'`
109     else
110       l_attr+="|"
111     fi
112     if echo "$launch_text" | grep -sq 'env_cond=' ; then
113       l_attr+="|"`echo $launch_text | sed 's/\(.* env_cond="\)\([^"]*\)\(.*\)/\2/g'`
114     else
115       l_attr+="|"
116     fi
117
118     if echo "$launch_text" | grep -sq 'cpu_assign=' ; then
119       l_attr+="|"`echo $launch_text | sed 's/\(.* cpu_assign="\)\([^"]*\)\(.*\)/\2/g'`
120     else
121       l_attr+="|0x0"
122     fi
123
124     echo $l_attr
125
126     cur_launch=$(($cur_launch+1))
127     l_idx=$(($l_idx+1))
128   done
129
130   cur_group=$(($cur_group+1))
131 done
132
133
134 rm $body_file