12/1/2013 - 6:55 AM

Automatic Distribution of In-House and upload .ipa to web server( )

Automatic Distribution of In-House and upload .ipa to web server( )

# Update: 2014-06-24
# Author: YoungShook

# compress application.
if [ "${CONFIGURATION}" = "Release" ]; then

# Local Display App Name And Default Icon@2x.png ------------ need developer custom

/bin/rm "/tmp/firim.log"
/bin/rm "/tmp/${PRODUCT_NAME}.ipa"


echo  "find Archives Distribution  ${PRODUCT_NAME}.app file ...1 " >> $LOG
DATE=$( /bin/date +"%Y-%m-%d" )
ARCHIVE=$( /bin/ls -t "${HOME}/Library/Developer/Xcode/Archives/${DATE}" | /usr/bin/grep xcarchive | /usr/bin/sed -n 1p )
echo  "Step Done ----------1" >> $LOG

echo  "Gets the configuration of ${TARGET_NAME} from Info.plist ...2 " >> $LOG
#SIGNING_IDENTITY="iPhone Distribution: <Your Name>>"
#PROVISIONING_PROFILE="${HOME}/Library/MobileDevice/Provisioning Profiles/<filename>>.mobileprovision"
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd "${SRCROOT}"
PATH_TO_ARTWORK=`find . -name ${ICON_NAME}`
/bin/cp ${PATH_TO_ARTWORK} /tmp/iTunesArtwork

#Get Version
VERSION_SHORT=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${APP}/Info.plist")
VERSION_BUILD=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${APP}/Info.plist")
APPID=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "${APP}/Info.plist")
echo  "Step Done ----------2" >> $LOG 

#Package ipa file 
echo  "Package .ipa for ${PRODUCT_NAME}...3 " >> $LOG
#if need set sign, add (--sign "${SIGNING_IDENTITY}" --embed "${PROVISIONING_PROFILE}")
xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "/tmp/${PRODUCT_NAME}.ipa"
echo  "Step Done ----------3" >> $LOG

#get last commit if have
gitcommit=`git --git-dir="${SRCDIR}/.git" log -1 --oneline --pretty=format:'%s'`

echo  "Uploading to  ....4 " >> $LOG

#Get App Info
Respones=`curl ""${APPID}"?token="${token}`
pkgkey=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['pkg']['key'];"`
pkgurl=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['pkg']['url'];"`
pkgtoken=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['pkg']['token'];"`
iconkey=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['icon']['key'];"`
iconurl=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['icon']['url'];"`
icontoken=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['bundle']['icon']['token'];"`
pkgid=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['id'];"`

#POST App To
upicon=`curl -F "key="${iconkey} -F "token="${icontoken} -F "file=@/tmp/iTunesArtwork" ${iconurl}`

upipa=`curl -F "key="${pkgkey} -F "token="${pkgtoken} -F "file=@/tmp/${PRODUCT_NAME}.ipa" ${pkgurl}`

editinfo=`curl -d "changelog="${gitcommit}"&version="${VERSION} -X PUT ""${pkgid}"?token="${token}`

short=`echo ${Respones}| ruby -e "require 'rubygems'; require 'json'; puts JSON[]['short'];"`

#Open Download Url
open "${short}"

echo  "finish load ----------OK" >> $LOG
echo  "To visit${short} download!" >> $LOG

exit 0