|
#!/bin/sh
# autoarchive.sh
# EMobile_CIB_iPhone
#
# Created by Nory Chao on 2017/3/20.
# Copyright © 2017 CSII. All rights reserved.
# Purpose:
# Auto to build Xcode project and achive,install ipa to iOS device if you connect one.
# (Actually, this is a concise shell script,just slack to archive)
#
# Notes:
# 1) To use this,you must set your project CA certificate and mobileprovision exactly.
# 2) Check scheme name is correct.
# 3) Update variable.
#
# Usage: ./autoarchive.sh -t Enterprise
projectName="SuperMenu"
# four types
enterprise="Enterprise"
#Enterprise CA certificate name and mobileprovision uuid
enterpriseCodeSignIdentity="iPhone Distribution: Hunan AsiaInfo Software Co., Ltd."
#uuid
enterpriseProvisioningProfile="789e146a-71cf-4a5c-83d1-249ce60d3b64"
if [ $# -lt 1 ];then
echo "Error! Should enter the archive type (Enterprise)."
echo ""
exit 2
fi
while getopts 't:' optname
do
case "$optname" in
t)
if [ ${OPTARG} != $enterprise ];then
echo "Usage: -t [Enterprise]"
echo ""
exit 1
fi
type=${OPTARG}
;;
*)
echo "Error! Unknown error while processing options"
echo ""
exit 2
;;
esac
done
#current dir
basepath=$(cd `dirname $0`; pwd)
myFile="autobuild"
#use -f to check whether $myFile exist
#PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#export PATH
#if [ ! -f "$myFile" ]; then
# /bin/mkdir -p "$myFile"
#else
# echo "dir exist"
#fi
#log path
log_path="autobuild/log.txt"
#build mode
configuration="Release"
#project name
workspaceName="${projectName}.xcodeproj"
#scheme name(maybe )
scheme=$projectName
#build path
configurationBuildDir="autobuild/build"
#value for CA certificate type
scheme="${projectName}_${type}"
if [ $type == $enterprise ]; then
codeSignIdentity=$enterpriseCodeSignIdentity
provisioningProfile=$enterpriseProvisioningProfile
fi
#archive name and path
archivePath="autobuild/archive/${projectName}.xcarchive"
#ipa path
qs_date=`date +%Y_%m_%d_%H_%M_%S`
#ipa name and export path
exportPath="${basepath}/autobuild/ipa/${projectName}_$qs_date"
#export options
exportOptionsPlist="autobuild/${type}ExportOptions.plist"
#validate ipa
ipaPath="${exportPath}/${scheme}.ipa"
#clean project
function clean(){
echo "\033[31mStart clean!\033[0m"
rm -f $log_path
xcodebuild clean -configuration "$configuration" >> $log_path || exit
echo "\033[31mClean success!\033[0m"
}
function archive () {
echo "\033[31mStart archive!\033[0m"
xcodebuild archive -project "$workspaceName" -scheme "$scheme" -configuration "$configuration" -archivePath "$archivePath" CONFIGURATION_BUILD_DIR="$configurationBuildDir" CODE_SIGN_IDENTITY="$codeSignIdentity" PROVISIONING_PROFILE="$provisioningProfile" >> $log_path || exit
echo "\033[31mArchive success!\033[0m"
}
function exportArchive(){
echo "\033[31mStart export ipa!\033[0m"
xcodebuild -exportArchive -archivePath "${archivePath}" -exportOptionsPlist "${exportOptionsPlist}" -exportPath "${exportPath}" >> $log_path || exit
echo "\033[31mExport ipa success,ipa exportPath is:\n ${exportPath}\033[0m"
open ${exportPath}
}
clean
archive
exportArchive
|