Skip to content

Instantly share code, notes, and snippets.

@nervouna
Forked from linyize/xctool_archive.sh
Created December 19, 2013 04:22
Show Gist options
  • Save nervouna/8034391 to your computer and use it in GitHub Desktop.
Save nervouna/8034391 to your computer and use it in GitHub Desktop.
#!/bin/sh -ex
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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment