Skip to content

Instantly share code, notes, and snippets.

@anivaros
Last active August 29, 2015 14:01
Show Gist options
  • Save anivaros/f3ab6cb3cbe499908c29 to your computer and use it in GitHub Desktop.
Save anivaros/f3ab6cb3cbe499908c29 to your computer and use it in GitHub Desktop.
Script for automatic updating version counter in Info.plist and settings files
#!/bin/bash
#
INFOPLIST_FILE=${2};
OIFS=$IFS;
IFS=".";
#считали версию
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildArray=($buildNumber)
IFS=$OIFS;
newBuild=${1}
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildArray[0]}.${buildArray[1]}.${newBuild}" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${buildArray[0]}.${buildArray[1]}" "$INFOPLIST_FILE"
buildShortVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $INFOPLIST_FILE)
buildNumber1=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $INFOPLIST_FILE)
INFOPLIST_FILE=${3}
build="Номер сборки: $buildShortVersion ($buildNumber1)";
fdate=$(date +"%d.%m.%Y %R");
builddate="Дата сборки: $fdate";
cnt=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:" ${INFOPLIST_FILE} | grep "Dict"|wc -l`
typeset -i cnt
#echo "the count is: $cnt."
cnt=`expr ${cnt} '-' '1'`
#echo "the count is: $cnt."
#foreach idx `seq 0 ${cnt}`
for idx in $(seq 0 $cnt); do
# echo "the index is: $idx."
val=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:Key" ${INFOPLIST_FILE}`
#echo "the value of PreferenceSpecifiers:${idx}:Title: is ${val}."
if [ "$val" == "versionDate" ] ; then
echo "the index of the entry whose 'Title' is 'Version' is $idx."
# now set it
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${idx}:DefaultValue $builddate" ${INFOPLIST_FILE}
# just to be sure that it worked
ver=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:DefaultValue" ${INFOPLIST_FILE}`
echo 'PreferenceSpecifiers:$idx:DefaultValue set to: ' $ver
fi
if [ "$val" == "FullVersionNumber" ] ; then
echo "the index of the entry whose 'Title' is 'Version' is $idx."
# now set it
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${idx}:DefaultValue $build" ${INFOPLIST_FILE}
# just to be sure that it worked
ver=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:DefaultValue" ${INFOPLIST_FILE}`
echo 'PreferenceSpecifiers:$idx:DefaultValue set to: ' $ver
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment