#!/bin/bash -l
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
pod install --verbose --no-repo-update
#clean
#获取脚本执行目录
#scrip_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
scrip_path="/Users/admin/Desktop/Work/build_ipa_shell"
#工程绝对路径
#project_path=$(dirname "$scrip_path")
project_path="/Users/admin/Desktop/Work/xxx"
echo 'scrip_path :()'${scrip_path}
echo 'project_path :()'${project_path}
#工程名 将XXX替换成自己的工程名
project_name="Deyiche-xiakuan"
#scheme名 将XXX替换成自己的sheme名
scheme_name="Deyiche-xiakuan"
#project_type 项目如果是用cocoapod,就改为 xcworkspace,否则用 xcodeproj
project_type=xcworkspace
#打包模式 Debug/Release
development_mode=Release
#build文件夹路径
build_path=${project_path}/build
#plist文件所在路径
exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-dev.plist
#echo "Place enter the number you want to export ? [ 0:测试 1:线上 2:auto-test] "
#
#read number
##0测试 1线上 2auto-test
#while([[ $number != 0 ]] && [[ $number != 1 ]] && [[ $number != 2 ]])
#do
#echo "Error! Should enter 1 or 2 or 0"
#echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc 3:dev] "
#read number
#done
number=1
if [ $number == 0 ];then
# development_mode=Release Debug
development_mode=Debug
envirument="0"
# exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-appstore.plist
elif [ $number == 1 ];then
development_mode=Debug
envirument="1"
# exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-adhoc.plist
else
development_mode=Debug
envirument="2"
# exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-dev.plist
fi
info_plist="/Users/admin/Desktop/Work/XiaKuan/Deyiche-xiakuan"/Info.plist
#exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-adhoc.plist
#exportOptionsPlistPath=${project_path}/build_ipa_shell/ExportOptions-Appstore.plist
#exportOptionsPlistPath是你先archive,export之后ipa包同目录下的同名文件,包含了证书与配置文件信息,这个也可以手写plist,但是手写麻烦,直接用打包好现成的
exportOptionsPlistPath=${scrip_path}/ExportOptions.plist
/usr/libexec/PlistBuddy -c "Set :RunEnvirment ${envirument}" ${info_plist}
#导出.ipa文件所在路径
exportIpaPath=${project_path}/ipa_files/${development_mode}
# 生成保存ipa文件的目录
if [ ! -d ${project_path}/ipa_files ];
then
mkdir -p ${project_path}/ipa_files;
fi
# 打包类型
if [ $project_type == "xcodeproj" ];
then
project_build=project
else
project_build=workspace
fi
# 进入项目目录,方便后面的操作
cd ${project_path}
echo '///-----------'
echo '/// 正在清理工程'
echo '///-----------'
#xcodebuild \
#clean -configuration ${development_mode} -quiet || exit
echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''
echo '///-----------'
echo '/// 正在编译工程:'${development_mode}
echo '///-----------'
xcodebuild \
archive -${project_build} ${project_path}/${project_name}.${project_type} \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${build_path}/${project_name}.xcarchive -quiet || exit
echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''
echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit
if [ -e $exportIpaPath/$scheme_name.ipa ]; then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成 '
echo '///-----------='
echo ''
# 打开生成ipa的目录
open ${exportIpaPath}
# echo '///-------------'
# echo '/// 开始发布ipa包 '
# echo '///-------------'
# if [ $number == 1 ];then
# #验证并上传到App Store
# # 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
# altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
# "$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u XXX -p XXX -t ios --output-format xml
# "$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u XXX -p XXX -t ios --output-format xml
# else
# #上传到Fir
# # 将XXX替换成自己的Fir平台的token
# fir login -T XXX
# fir publish $exportIpaPath/$scheme_name.ipa
# fi
#蒲公英上的User Key
uKey="5261cf40a3408a4d237d154df398075d"
#蒲公英上的API Key
apiKey="acea93e9056b474f8c5b9f0bbec25ef2"
#要上传的ipa文件路径
IPA_PATH="/Users/admin/Desktop/Work/XiaKuan/ipa_files/Debug/下款.ipa"
#执行上传至蒲公英的命令,这句不需要修改
curl -F "file=@${IPA_PATH}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" https://www.pgyer.com/apiv2/app/upload
exit 0