Created
August 26, 2018 18:49
-
-
Save slmcmahon/afbc4cc3a823fbeb31c0eb91d3d5abf4 to your computer and use it in GitHub Desktop.
Appends to or overwrites version in info.plist file.
This file contains hidden or 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 | |
# the 'defaults' command wants the plist file path, but without the .plist extension | |
NOEXT=$(echo "$1" | cut -f 1 -d '.') | |
# extract the current CFBundleVersion value | |
VERSION=$(defaults read $NOEXT CFBundleVersion) | |
# get the number of '.' characters in the version | |
DOTCOUNT=$(echo $VERSION | awk -F"." '{print NF-1}') | |
if [ $DOTCOUNT -eq 3 ] | |
then | |
# if we have 3 '.' (e.g. 1.2.3.4), then we want to replace the | |
# last version value (e.g. .4) with the value passed at the | |
# command prompt | |
NEWVERSION="$(echo $VERSION | cut -f 1 -d '.') $2" | |
elif [ $DOTCOUNT -lt 3 ] | |
then | |
# otherwise, we just want to append the new value to whatever | |
# we currently have | |
NEWVERSION="$VERSION.$2" | |
fi | |
# if we have a 3rd argument, then we use it as a DEBUG flag and | |
# only show the new version rather than actually executing it. | |
if [ -n "$3" ] | |
then | |
echo $NEWVERSION | |
else | |
/usr/bin/plutil -replace CFBundleVersion -string $NEWVERSION $1 | |
/usr/bin/plutil -replace CFBundleShortVersionString -string $NEWVERSION $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment