Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
Created August 26, 2018 18:49
Show Gist options
  • Save slmcmahon/afbc4cc3a823fbeb31c0eb91d3d5abf4 to your computer and use it in GitHub Desktop.
Save slmcmahon/afbc4cc3a823fbeb31c0eb91d3d5abf4 to your computer and use it in GitHub Desktop.
Appends to or overwrites version in info.plist file.
#!/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