-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_xcode_version.sh
executable file
·44 lines (43 loc) · 1.19 KB
/
get_xcode_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
set -o pipefail
set -e
ROOT_PATH=`dirname "${0}"`/..
XCODE_APPS_FINDER=$(mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'")
XCODE_APPS_FALLBACK=$(find /Applications -iname 'Xcode*.app' -maxdepth 1)
XCODE_APPS=$(echo -e "$XCODE_APPS_FINDER\n$XCODE_APPS_FALLBACK" | sort | uniq)
PLIST_BUDDY="/usr/libexec/PlistBuddy"
function get_plist_value() {
"$PLIST_BUDDY" -c "Print :$2" "$1/Contents/Info.plist"
}
function get_build_version() {
"$PLIST_BUDDY" -c "Print :ProductBuildVersion" "$1/Contents/version.plist"
}
function get_version() {
APP_NAME=$(get_plist_value "$1" "CFBundleName")
if [[ "$APP_NAME" == "Xcode" ]]; then
echo $(get_plist_value "$1" "CFBundleShortVersionString")
else
echo ""
fi
}
function get_build() {
APP_NAME=$(get_plist_value "$1" "CFBundleName")
if [[ "$APP_NAME" == "Xcode" ]]; then
echo $(get_build_version "$1")
else
echo ""
fi
}
for APP in $XCODE_APPS; do
APP_VERSION=$(get_version $APP)
if [ $1 = $APP_VERSION ]; then
echo $(get_build $APP)
exit 0
fi
done
echo "Failed to find version $1. Available versions: " 1>&2
for APP in $XCODE_APPS; do
APP_VERSION=$(get_version $APP)
echo "$APP $APP_VERSION" 1>&2
done
exit 1