1 #!/bin/bash 2 3 # Copyright (c) 2011-2014, Intel Corporation 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without modification, 7 # are permitted provided that the following conditions are met: 8 # 9 # 1. Redistributions of source code must retain the above copyright notice, this 10 # list of conditions and the following disclaimer. 11 # 12 # 2. Redistributions in binary form must reproduce the above copyright notice, 13 # this list of conditions and the following disclaimer in the documentation and/or 14 # other materials provided with the distribution. 15 # 16 # 3. Neither the name of the copyright holder nor the names of its contributors 17 # may be used to endorse or promote products derived from this software without 18 # specific prior written permission. 19 # 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 32 # This script generate an xml from a .pfw in an easy and fast way 33 # It only works if you have an parameter running with criterion compatible 34 # with the .pfw 35 36 set -eu -o pipefail 37 38 adbShell="adb shell" 39 parameterCommandAccess="eval remote-process localhost 5000" 40 parameter="$adbShell $parameterCommandAccess" 41 42 tmpfile="/tmp/pfw_commands" 43 target_tmpfile="/data/pfw_commands" 44 45 46 adbShellForward () { 47 48 echo 'echo $?; exit' >> "$1" 49 50 # Send commands 51 adb push "$1" "$target_tmpfile" 52 $adbShell chmod 700 "$target_tmpfile" 53 54 $adbShell "$target_tmpfile" | 55 # keep only the -2 line, the output of "echo $?" 56 tee /dev/stderr | tail -2 | sed '1{s/\r//;q}' | 57 # stop if $? != 0 (as of set -e) 58 xargs test 0 -eq 2> /dev/null 59 60 } 61 62 function parameterExecute () 63 { 64 echo " \$ $parameter $@" 65 result="$($parameter $@ | sed 's/\r$//')" 66 67 if [[ "$result" != "Done"* ]]; then 68 echo "$result" 69 return 2 70 fi 71 return 0 72 } 73 74 function log () 75 { 76 echo "$@" >&2 77 } 78 79 # Clean tmp file 80 echo > "${tmpfile}" 81 82 ################# 83 # Configure PFW # 84 ################# 85 86 echo "setTuningMode on" >> "${tmpfile}" 87 echo "setAutoSync off" >> "${tmpfile}" 88 89 90 log "Delete routing domains" 91 for domain in $(parameterExecute listDomains |grep -io '^Routing.[^ ]*') 92 do 93 log "Will delete domain $domain" 94 echo "deleteDomain $domain" >> "${tmpfile}" 95 done 96 97 ######################### 98 # Generate PFW commands # 99 ######################### 100 101 log "Generate domain commands from file(s): $*" 102 m4 "$@" \ 103 | $(dirname $0)/PFWScriptGenerator.py --output-kind pfw >> "${tmpfile}" 104 105 106 echo "setAutoSync off" >> "${tmpfile}" 107 echo "setTuningMode off" >> "${tmpfile}" 108 109 sed -i -e':a 110 # look for line finishing with \ 111 /\\$/{ 112 # Delete the last char (\) 113 s/\\$//; 114 # Append the next line and delete the \n separator 115 N; 116 s/\n/ /; 117 # Jump back to the expression beginning 118 ta; 119 }; 120 # delete empty lines; 121 /^$/d 122 # delete leading space 123 s/^ *// 124 # delete multiple spaces 125 s/ */ /g; 126 # Prefix each line with "$parameterCommandAccess 127 '"s/^/$parameterCommandAccess /" \ 128 "${tmpfile}" 129 130 echo "set -xeu" > "${tmpfile}2" 131 cat "${tmpfile}" >> "${tmpfile}2" 132 133 log "Execute commands" 134 adbShellForward "${tmpfile}2" 135 136 137 ##################### 138 # Generate xml file # 139 ##################### 140 141 outputFilePath="domains.xml" 142 143 if test $# -ne 0 144 then 145 # Output file is the input file with the xml extension 146 outputFilePath="${1%.*}.xml" 147 if test "$outputFilePath" == "$1" 148 then 149 # There is a conflict 150 outputFilePath="${1}.xml" 151 fi 152 fi 153 154 log "Output file: $outputFilePath" 155 156 parameter_execute_if_exist () { 157 $parameter help | grep --quiet --word $1 || return $? 158 $parameter $1 | sed 's/\r//' 159 } 160 161 parameter_execute_if_exist getDomainsWithSettingsXML > "$outputFilePath" || 162 # Fall back on old command 163 parameter_execute_if_exist getDomainsXML > "$outputFilePath" 164 165 166 log "The media server PFW domains have been change, please restart it to restore old domains" 167