1*dd0948b3SAndroid Build Coastguard Worker#!/bin/sh 2*dd0948b3SAndroid Build Coastguard Worker 3*dd0948b3SAndroid Build Coastguard Worker# Copyright (C) 2023 The Android Open Source Project 4*dd0948b3SAndroid Build Coastguard Worker# 5*dd0948b3SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*dd0948b3SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*dd0948b3SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*dd0948b3SAndroid Build Coastguard Worker# 9*dd0948b3SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*dd0948b3SAndroid Build Coastguard Worker# 11*dd0948b3SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*dd0948b3SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*dd0948b3SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*dd0948b3SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*dd0948b3SAndroid Build Coastguard Worker# limitations under the License. 16*dd0948b3SAndroid Build Coastguard Worker 17*dd0948b3SAndroid Build Coastguard Worker# Generates an AndroidManifest.xml file from a template by replacing the line 18*dd0948b3SAndroid Build Coastguard Worker# containing the substring, 'PERMISSIONS', with a list of permissions defined in 19*dd0948b3SAndroid Build Coastguard Worker# another text file. 20*dd0948b3SAndroid Build Coastguard Worker 21*dd0948b3SAndroid Build Coastguard Workerset -e 22*dd0948b3SAndroid Build Coastguard Worker 23*dd0948b3SAndroid Build Coastguard Workerif [ "$#" != 3 ]; 24*dd0948b3SAndroid Build Coastguard Workerthen 25*dd0948b3SAndroid Build Coastguard Worker echo "usage: gen-manifest.sh AndroidManifest.xml.template" \ 26*dd0948b3SAndroid Build Coastguard Worker "permissions.txt AndroidManifest.xml" 27*dd0948b3SAndroid Build Coastguard Worker exit 1 28*dd0948b3SAndroid Build Coastguard Workerfi 29*dd0948b3SAndroid Build Coastguard Worker 30*dd0948b3SAndroid Build Coastguard Workerreadonly template="$1" 31*dd0948b3SAndroid Build Coastguard Workerreadonly permissions="$2" 32*dd0948b3SAndroid Build Coastguard Workerreadonly output="$3" 33*dd0948b3SAndroid Build Coastguard Worker 34*dd0948b3SAndroid Build Coastguard Workerecho "template = $1" 35*dd0948b3SAndroid Build Coastguard Worker 36*dd0948b3SAndroid Build Coastguard Worker# Print the XML template file before the line containing PERMISSIONS. 37*dd0948b3SAndroid Build Coastguard Workersed -e '/PERMISSIONS/,$d' "$template" > "$output" 38*dd0948b3SAndroid Build Coastguard Worker 39*dd0948b3SAndroid Build Coastguard Worker# Print the permissions formatted as XML. 40*dd0948b3SAndroid Build Coastguard Workersed -r 's!(.*)! <uses-permission android:name="\1"/>!g' "$permissions" >> "$output" 41*dd0948b3SAndroid Build Coastguard Worker 42*dd0948b3SAndroid Build Coastguard Worker# Print the XML template file after the line containing PERMISSIONS. 43*dd0948b3SAndroid Build Coastguard Workersed -e '1,/PERMISSIONS/d' "$template" >> "$output" 44