Created
January 5, 2012 10:06
-
-
Save crsantos/1564538 to your computer and use it in GitHub Desktop.
iOS Build Script
This file contains 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 | |
# Bash script to generate a "Release" Build - Based on arrix.blogspot.com code | |
# - The file must lay on the same .xcodeproj folder | |
# - Project must be set up with "Debug" (with developer provisioning profiles) | |
# and "Release" (with distribution provisioning profiles) | |
# - Project build version will be upgraded with the current datetime and marketing version | |
# will be the same provided as the second parameter of the script: see USAGE. | |
# | |
# USAGE: sh build.sh AppName 0.1.1 | |
config='Release' | |
project_dir=$(pwd) | |
build_version=$(date -u +%Y%m%d%H%M) | |
usage(){ | |
echo "\n\t*****************************************************************" | |
echo "\t\tUSAGE: sh $0 AppName 0.1.1" | |
echo "\t\t You must provide the app name: (i.e.) MyApp" | |
echo "\t\tYou must provide a marketing-version: (i.e.) 1.0.0" | |
echo "\n\t\t\tString format must match!" | |
echo "\t*****************************************************************\n\n" | |
exit 1 | |
} | |
die() { | |
echo "$*" >&2 | |
exit 1 | |
} | |
doIt(){ | |
appname=$1 | |
version=$2 | |
echo "\n1/4 - Updating marketing version number and build to: $2 ($build_version)..." # agvtool bump -all | |
agvtool new-version -all "$build_version" > /dev/null | |
agvtool new-marketing-version "$version" > /dev/null | |
fullversion="$(agvtool mvers -terse1)($(agvtool vers -terse))" # gets current version | |
echo "\n\n2/4 - Building $appname using configuration $config..." | |
echo "\t\tBuilding version $fullversion\n\n" | |
xcodebuild -target "$appname" -configuration "$config" > /dev/null || die "\nBuild failed!\n" # Builds on xcode | |
clear # clear screen | |
echo "\n\n3/4 - Making ipa..." | |
# packaging | |
cd build/"$config"-iphoneos || die "no such directory" | |
rm -rf Payload | |
# rm -f "$appname".*.ipa | |
mkdir Payload # creates Payload dir | |
cp -Rp "$appname.app" Payload/ # move app to payload | |
if [ -f "$project_dir"/iTunesArtwork ] ; then # check if there is any iTunesArtwork | |
cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork | |
fi | |
ipaname="$appname.$fullversion.$build_version.ipa" # new name for the .ipa | |
zip -r $ipaname Payload # compress to ipa | |
md5checksum=$(md5 -s $ipaname) | |
echo "\t $md5checksum" # shows md5 checksum | |
mv $ipaname ~/Desktop # move to desktop | |
cd ../../ && rm -rf build # deletes build/ dirs | |
echo "\n\n4/4 - Moved ipa to ~/Desktop" | |
echo "\n\n\tFinished making $ipaname\n\n" | |
open ~/Desktop | |
exit 0 | |
} | |
[[ $# -lt 2 ]] && usage # check if param count < 2 and shows an error | |
count=`ls -1 | grep ".xcodeproj" | wc -l` | |
if [ $count != 0 ] | |
then | |
if [[ $1 =~ ^[A-z_-]+$ ]] && [[ $2 =~ ^[0-9]+(\.[0-9]+)+$ ]]; | |
then | |
doIt $1 $2; | |
else | |
usage; | |
fi | |
else | |
echo "\n\n\tWARNING: Not in a project's folder. This file must lay side by side with .xcodeproj\n\n" | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment