Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created May 10, 2013 20:35
Show Gist options
  • Select an option

  • Save Dimillian/5557188 to your computer and use it in GitHub Desktop.

Select an option

Save Dimillian/5557188 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# @(#) Increment the version number in the project plist. V1.2.
# Note: The project plist could be in directory
# "Resources" or the project root.
# Personally, I avoid clutter in the project root.
#
# Note: This script should be invoked from the project root!
#
# V1.2 Added checking for the INFOPLIST_FILE environment variable
#
# Enjoy! xaos@xm5design.com
#
PROJECTMAIN=$(pwd)
PROJECT_NAME=$(basename "${PROJECTMAIN}")
#
#
# Let's see if the environment variable is set
if [[ "${INFOPLIST_FILE}" != "" ]]
then
#
# This was passed from XCODE
buildPlist="${INFOPLIST_FILE}"
PROJECT_NAME=$(basename "${buildPlist}"| sed 's/^\(.*\)-Info.plist.*/\1/')
elif [[ -f "${PROJECTMAIN}/Resources/${PROJECT_NAME}-Info.plist" ]]
then
#
# This should handle the default behavior of the OSX file system
# which is case insensitive.
buildPlist="${PROJECTMAIN}/Resources/${PROJECT_NAME}-Info.plist"
elif [[ -f "${PROJECTMAIN}/resources/${PROJECT_NAME}-Info.plist" ]]
then
#
# Just in case the file system is case sensitive.
buildPlist="${PROJECTMAIN}/resources/${PROJECT_NAME}-Info.plist"
elif [[ -f "${PROJECTMAIN}/${PROJECT_NAME}-Info.plist" ]]
then
#
# In case the plist is in project root.
buildPlist="${PROJECTMAIN}/${PROJECT_NAME}-Info.plist"
else
echo -e "Can't find the plist: ${PROJECT_NAME}-Info.plist"
exit 1
fi
#
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${buildPlist}" 2>/dev/null)
if [[ "${buildVersion}" = "" ]]
then
echo -e "\"${buildPlist}\" does not contain key: \"CFBundleVersion\""
exit 1
fi
IFS='.'
set $buildVersion
#MAJOR_VERSION="${1}"
#MINOR_VERSION="${2}"
#BUILD_VERSION="${3}"
BUILD_VERSION="${1}"
#buildNumber=$(($MINOR_VERSION + 1))
#buildNewVersion="${MAJOR_VERSION}.${buildNumber}"
buildNumber=$BUILD_VERSION
buildNewVersion=$(($BUILD_VERSION + 1))
echo -e "${PROJECT_NAME}: Old version number: ${buildNumber} New Version Number: ${buildNewVersion}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNewVersion}" "${buildPlist}"
#/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${buildNewVersion}" "${buildPlist}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment