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