Skip to content

Instantly share code, notes, and snippets.

@linyize
Last active December 31, 2015 19:38
Show Gist options
  • Save linyize/8034386 to your computer and use it in GitHub Desktop.
Save linyize/8034386 to your computer and use it in GitHub Desktop.
Bash shell to package inhouse/development/adhoc/appstore ios app (then upload to inhouse webserver) Usage: ./xctool_archive.sh PathToProject Scheme
#!/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}"
@linyize
Copy link
Author

linyize commented Dec 23, 2013

TODO:
1、加强错误检验
2、找到一个快速检验证书+私钥是否有效的途径,目前的方式比较慢
3、如果工程中指定了CodeSigning,使用指定的CodeSigning来签名打包

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment