#!/bin/sh -ex # install xctool : brew install xctool # must be shared scheme # must be inhouse app inhouseserver="http://inhouse.xxx.com/upload" export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer projectpath=$1 scheme=$2 projectname=$(basename "${projectpath}") cd "${projectpath}" projectpath=$(pwd) # archive xctool -project "${projectname}".xcodeproj -scheme "${scheme}" clean archive -sdk iphoneos # find certname and mobileprovision filepath plist=/tmp/"${scheme}".plist rm -f "${plist}" plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj schemefile="${projectpath}"/"${projectname}".xcodeproj/xcshareddata/xcschemes/"${scheme}".xcscheme targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2) buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}") buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}") profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}") profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision teamname=$(egrep -a -A 1 TeamName "${profile}" | grep string | cut -d '>' -f2 | cut -d '<' -f1) cert=iPhone\ Distribution:\ "${teamname}" # package ipa archive=$(ls -dt ~/Library/Developer/Xcode/Archives/*/"${scheme}"*.xcarchive|head -1) app=$(ls -dt "${archive}"/Products/Applications/*.app|head -1) ipa=/tmp/"${scheme}".ipa rm -f "${ipa}" /usr/bin/xcrun -sdk iphoneos PackageApplication \ -o "${ipa}" \ -v "${app}" \ -s "${cert}" \ --embed "${profile}" # upload ipa to inhouse webserver #curl -F "ipa=@"${ipa}"" "${inhouseserver}"