X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=service%2Fsystem%2Fconfig%2Flibrary%2Fsystem_manager_config%2Fxml%2Flaunch_xml2cfg.sh;fp=service%2Fsystem%2Fconfig%2Flibrary%2Fsystem_manager_config%2Fxml%2Flaunch_xml2cfg.sh;h=20fa0979ba17275b540d95334ca005dbcf8c0d3c;hb=17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d;hp=0000000000000000000000000000000000000000;hpb=9e86046cdb356913ae026f616e5bf17f6f238aa5;p=staging%2Fbasesystem.git diff --git a/service/system/config/library/system_manager_config/xml/launch_xml2cfg.sh b/service/system/config/library/system_manager_config/xml/launch_xml2cfg.sh new file mode 100755 index 0000000..20fa097 --- /dev/null +++ b/service/system/config/library/system_manager_config/xml/launch_xml2cfg.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# +# Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#xpath is slow, so use sed as much as possible + +infile=$1 + +main_file=system_launcher_main.xml +body_file=system_launcher_body.xml + + +#check xmllint is exist +if ! which xmllint > /dev/null ; then + echo "It need xmllint. Please install it." + exit 1; +fi + +#check xpath is exist +if ! which xpath > /dev/null ; then + echo "It need xpath Please install it." + exit 1; +fi + +#arg check +if ! [[ "$infile" =~ .+\.xml ]] ;then + echo "$infile is not *.xml" + exit 1 +elif ! [ -e $infile ];then + echo "$infile not found" + exit 1 +fi + +cp -f $infile $body_file + +#check xml vaild +if ! xmllint --noout --valid $main_file ;then + echo "XML is Invalid. " + exit 1; +fi + +#Read into memory after shaping with xpath +xmem=`xpath -q -e /system_launcher $main_file` + +echo "# This file is created from $infile." +echo "# created date : `LANG=en date`" +echo "[ModulesLaunchConfig]" + +#GROUP LOOP +group_num=`echo $xmem | xpath -e /system_launcher/group 2>&1 | grep Found | cut -d ' ' -f2` + +l_idx=1 +cur_group=1 +until [ $cur_group -gt $group_num ]; +do + #LAUNCH LOOP + group_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]` #group full XML text + group_attr=`echo $group_text | sed 's/\(]\+>\)\(.*\)/\1/g'` + + g_name=`echo $group_attr | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'` + g_wait_time=`echo $group_attr | sed 's/\(.* wait_time="\)\([^"]*\)\(.*\)/\2/g'` + g_trigger=`echo $group_attr | sed 's/\(.* trigger="\)\([^"]*\)\(.*\)/\2/g'` + +# echo $g_name $g_wait_time $g_trigger + l_launch_num=`echo $xmem | xpath -e /system_launcher/group[$cur_group]/launch 2>&1 | grep Found | cut -d ' ' -f2` + + cur_launch=1; + until [ $cur_launch -gt $l_launch_num ]; do + launch_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]/launch[$cur_launch]` + + l_attr="Launch${l_idx}=$g_name|$cur_group|$g_wait_time|$g_trigger" + l_attr+="|"`echo $launch_text | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* path="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* priority="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* critical="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* retry_cnt="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* arguments="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* logging_mask="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* restart="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* is_start_required="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_critical="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* fast_shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'` + l_attr+="|"`echo $launch_text | sed 's/\(.* user_name="\)\([^"]*\)\(.*\)/\2/g'` + if echo "$launch_text" | grep -sq 'env_cond=' ; then + l_attr+="|"`echo $launch_text | sed 's/\(.* env_cond="\)\([^"]*\)\(.*\)/\2/g'` + else + l_attr+="|" + fi + + echo $l_attr + + cur_launch=$(($cur_launch+1)) + l_idx=$(($l_idx+1)) + done + + cur_group=$(($cur_group+1)) +done + + + +