Created
October 15, 2015 11:08
-
-
Save jmoody/30f3e071d85419320320 to your computer and use it in GitHub Desktop.
Bash script for extracting CFBundleIdentifier from .app or .ipa (MacOS only)
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
#!/usr/bin/env bash | |
function error { | |
echo "$(tput setaf 1)ERROR: $1$(tput sgr0)" | |
} | |
function usage { | |
echo "Usage: bundle-id.sh /path/to/App.{ipa | app}" | |
} | |
function ditto_or_exit { | |
ditto "${1}" "${2}" | |
if [ "$?" != 0 ]; then | |
error "Could not copy:" | |
error " source: ${1}" | |
error " target: ${2}" | |
if [ ! -e "${1}" ]; then | |
error "The source file does not exist" | |
fi | |
error "Exiting 1" | |
exit 1 | |
fi | |
} | |
if [ -z "${1}" ]; then | |
usage | |
exit 1 | |
fi | |
FILE="${1}" | |
if [ ! -e "${FILE}" ]; then | |
error "File ${FILE} does not exist" | |
fi | |
ORIGINAL_DIR="${PWD}" | |
EXT=`echo "${FILE##*.}" | tr -d '\n'` | |
if [ "${EXT}" = "app" ]; then | |
PLIST="${FILE}/Info.plist" | |
elif [ "${EXT}" = "ipa" ]; then | |
TMP_DIR=$(mktemp -d -t 'bundle-id-tmpdir') | |
ditto_or_exit "${FILE}" "${TMP_DIR}" | |
cd "${TMP_DIR}" | |
IPA=`basename ${FILE} | tr -d '\n'` | |
unzip -q "${IPA}" | |
PLIST=`find ./Payload -maxdepth 2 -type f -name Info.plist -print0` | |
else | |
error "Expected a .app or .ipa extention; found ${EXT}" | |
fi | |
/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "${PLIST}" | |
EXIT=$? | |
if [ -e "${TMP_DIR}" ]; then | |
rm -rf "${TMP_DIR}" | |
fi | |
exit $EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment