Skip to content

Instantly share code, notes, and snippets.

@hjeffrey
Created July 20, 2015 14:09
Show Gist options
  • Save hjeffrey/25d9afc212ad41454cbd to your computer and use it in GitHub Desktop.
Save hjeffrey/25d9afc212ad41454cbd to your computer and use it in GitHub Desktop.
make ipa by command line tool.
#!/bin/sh
# build.sh
#
# Created by Jia Yuhui on 24/06/2015.
# Modified by Jia Yuhui on 17/07/2015. Fixed Uploading file tyep error and crasylytics error.
# Copyright 2015 Jia Yuhui. All rights reserved.
env=$1
sleepsecond=0
# 检查参数
if [[ -z "$env" ]]; then
echo "Default Release"
env="Release"
fi
# 配置参数
BUILD_SHELL_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${BUILD_SHELL_PATH}
cd ..
PROJDIR=~+
echo $PROJDIR
if [[ "$env" == "Release" ]]; then
PROJECT_BUILDDIR="Release-iphoneos"
DEVELOPPER_NAME="iPhone Developer: xxx (xxxxxxx)" # form keychain
#PROVISONNING_PROFILE="${PROJDIR}/Profiles/xxxx.mobileprovision"
elif [[ "$env" == "Debug" ]]; then
PROJECT_BUILDDIR="Debug-iphoneos"
DEVELOPPER_NAME="iPhone Developer: xxx (xxxxxxx)" # form keychain
#PROVISONNING_PROFILE="${PROJDIR}/Profiles/xxxxx.mobileprovision"
fi
PROJECT_NAME="TargetName"
TARGET_SDK="iphoneos8.4"
echo "Ctrl+C 可以停止脚本执行!!"
sleep $sleepsecond
echo "!!!此脚本编译的安装包,无法上传到Crashlytics做crash收集"
sleep $sleepsecond
# 开始编译
echo -------------Cleaning $PROJECT_NAME $env----------------
sleep $sleepsecond
xcodebuild clean -sdk "$TARGET_SDK" -configuration "$env"
echo -------------Building $env----------------
sleep $sleepsecond
xcodebuild -target "$PROJECT_NAME" -sdk "$TARGET_SDK" -configuration "$env" CODE_SIGN_IDENTITY="$DEVELOPPER_NAME"
if [ $? != 0 ]
then
echo Building $env error !!!
exit 1
fi
# 生产IPA
echo -------------Making IPA----------------
sleep $sleepsecond
# Set variables
BUILD_PATH="$PROJDIR/build"
APP_PATH="$BUILD_PATH/$PROJECT_BUILDDIR/$PROJECT_NAME.app"
APP_VERSION=`defaults read $APP_PATH/Info CFBundleShortVersionString`
APP_REVISION=`defaults read $APP_PATH/Info CFBundleVersion`
APP_NAME="iOS_V${APP_VERSION}_store_build${APP_REVISION}_$(date +%Y%m%d_%H%M)"
IPA_NAME="${APP_NAME}.ipa"
IPA_PATH="$PROJDIR/${IPA_NAME}"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP_PATH}" -o "$IPA_PATH" #--sign "$DEVELOPPER_NAME"
if [ $? != 0 ]
then
echo Making IPA error !!!
exit 1
fi
echo -------------Zip dSYM----------------
sleep $sleepsecond
cd "$BUILD_PATH/$PROJECT_BUILDDIR"
APP_dSYM_NAME="$PROJECT_NAME.app.dSYM"
WIDGET_dSYM_NAME="Widget.appex.dSYM"
dSYM_NAME="$IPA_NAME.dSYM.zip"
dSYM_PATH="$PROJDIR/$dSYM_NAME"
zip -r -q "$dSYM_PATH" "$APP_dSYM_NAME" #"$WIDGET_dSYM_NAME"
if [ $? != 0 ]
then
echo Zip dSYM error !!!
exit 1
fi
# 删除编译文件
echo -------------Cleaning temp files----------------
sleep $sleepsecond
cd "$PROJDIR"
find . -name "build" -exec rm -rf {} \;
# echo -------------Crashlytics configuration----------------
# sleep $sleepsecond
# $PROJDIR/Frameworks/Fabric.framework/run 638b5c0d98ee2c93f28822ae4041785771a804b6 729ee0bbc536abab5dffccb85efa6e5df399701c5e0bdf6763bdc34ea423618a
# if [ $? != 0 ]
# then
# echo Crashlytics error !!!
# exit 1
# fi
# 上传文件
echo -------------Uploading to ftp----------------
sleep $sleepsecond
HOST='192.168.1.1'
USER='name'
PASSWD='password'
REMOTEDIR='path'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
type binary
cd $REMOTEDIR
put $dSYM_NAME
put $IPA_NAME
quit
END_SCRIPT
echo -------------Send Email----------------
sleep $sleepsecond
CONTENTFILE="$PROJDIR/$(date +%Y%m%d_%H%M).log"
echo "名称编号" >> $CONTENTFILE
echo ${APP_NAME} >> $CONTENTFILE
echo "ftp://$HOST/$REMOTEDIR/$IPA_NAME" >> $CONTENTFILE
echo "ftp://$HOST/$REMOTEDIR/$dSYM_NAME" >> $CONTENTFILE
UPDATECONTENT="${PROJDIR}/history.txt"
cat $UPDATECONTENT | while read LINE
do
echo $LINE >> $CONTENTFILE
done
EMAIL_ADDRESS="[email protected]"
FROM_NAME="Author"
EMAIL_TITLE="[发包邮件]${PROJECT_NAME}_iOS_${APP_VERSION}"
mail -s $EMAIL_TITLE $EMAIL_ADDRESS -f $FROM_NAME < $CONTENTFILE
if [ $? != 0 ]
then
rm -r $CONTENTFILE
echo Mail error !!!
exit 1
fi
rm -r $CONTENTFILE
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment