Created
February 20, 2014 11:03
-
-
Save nacho4d/9111261 to your computer and use it in GitHub Desktop.
Edit AndroidManifest.xml using xmlstarlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e; | |
[ -z "$1" ] && { echo "ERROR: No AndroidManifest.xml provided"; exit 1; } | |
command -v xmlstarlet >/dev/null 2>&1 || { echo >&2 "ERROR: xmlstarlet command not available"; exit 1; } | |
MANIFEST_FILE=$1 | |
function addUsesPermission () | |
{ | |
[ -z "$1" ] && { echo "ERROR: No attribute value"; exit 1; } | |
ATTR_VALUE=$1 | |
if [ -n "$(xmlstarlet sel -T -t -v "/manifest/uses-permission[@android:name=\"${ATTR_VALUE}\"]/@android:name" $MANIFEST_FILE)" ] | |
then | |
echo Found ${ATTR_VALUE}. Skipping | |
else | |
echo Adding ${ATTR_VALUE} | |
TMP_FILE=`mktemp -q /tmp/$(basename ${MANIFEST_FILE}).tmp` | |
xmlstarlet ed -S \ | |
-s /manifest -t elem -n uses-permission-temp -v "" \ | |
-i //uses-permission-temp -t attr -n android:name -v ${ATTR_VALUE} \ | |
-r //uses-permission-temp -v uses-permission ${MANIFEST_FILE} > ${TMP_FILE} | |
mv ${TMP_FILE} ${MANIFEST_FILE} | |
fi | |
} | |
# Add <uses-permission android:name="android.permission.INTERNET" /> | |
addUsesPermission 'com.android.vending.BILLING' | |
# Add <uses-permission android:name="com.android.vending.BILLING" /> | |
addUsesPermission 'android.permission.INTERNET' | |
echo "Done!" | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment