[Xcode]Xcode自动打ipa包脚本

本文介绍了一个用于iOS应用自动化打包及上传至fir.im平台的Shell脚本。该脚本首先确保brew和xctool已安装,然后进行IPA文件打包,并通过调用API将IPA文件及其图标上传至fir.im。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打包脚本.sh文件

# !/bin/sh

if [ ! -d ~/genParentPackage ];then
	mkdir -p ~/genParentPackage
fi
ROOT_PATH=~/genParentPackage

#############安装brew和xctool#############
if which brew 2>/dev/null; then
  echo "-> brew已经安装"
else
  echo "-> 检测到brew未安装,开始安装brew···"
  curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1
  ##ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

if which xctool>/dev/null; then
  echo "-> xctool已经安装"
else
  echo "-> 检测到xctool未安装,开始安装xctool···"
  sudo brew update
  sudo brew install xctool 
fi


###########开始打包IPA########
APP_NAME="TXChatParent"
BUILD_DIR="$ROOT_PATH"        #build目录

buildDayTime=$(date +'%Y-%m-%d_%H%M%S')

ARCHIVE_PATH="$BUILD_DIR/${APP_NAME}_${buildDayTime}.xcarchive"
IPA_PATH_ADHOC="$BUILD_DIR/${APP_NAME}_adHoc_${buildDayTime}.ipa"
IPA_PATH_DIS="$BUILD_DIR/${APP_NAME}_dis_${buildDayTime}.ipa"

# ARCHIVE_PATH="$BUILD_DIR/$APP_NAME.xcarchive"
#IPA_PATH_ADHOC="$BUILD_DIR/TXChatParent_adHoc_2016-03-30_101124.ipa"

XCWORKSPACE="TXChatParent.xcworkspace"
SCHEME="TXChatParent"
CONF="Release"
# PROFILE="Provisioning Profile: com.tuxing.chs.parent_adhoc"
PROFILE_ADHOC="parentsClient_adhoc"
PROFILE_DIS="parentsClient_dis"

# # clean Release
xcodebuild clean \
-project ${APP_NAME}.xcodeproj \
-configuration ${CONF} \
-alltargets


#set version and bundleVesion add 1
InfoPlist="TXChat/info.plist"
BINARY_VERSION=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $InfoPlist`
BINARY_BUILD=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $InfoPlist`

BINARY_VERSION=`echo ${BINARY_VERSION%.*}`
BINARY_BUILD=$(($BINARY_BUILD+1))
BINARY_VERSION="$BINARY_VERSION.$BINARY_BUILD"

/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $BINARY_VERSION" $InfoPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BINARY_BUILD" $InfoPlist



# #archive
xctool \
-workspace $XCWORKSPACE \
-scheme $SCHEME \
-sdk iphoneos \
-configuration $CONF \
archive -archivePath  "$ARCHIVE_PATH"

#导成IPA(adhoc测试版本)
xcodebuild \
-exportArchive \
-exportFormat ipa -archivePath "$ARCHIVE_PATH" \
-exportPath 	"$IPA_PATH_ADHOC" \
-exportProvisioningProfile $PROFILE_ADHOC

#导成IPA(dis发布版本)
xcodebuild \
-exportArchive \
-exportFormat ipa -archivePath "$ARCHIVE_PATH" \
-exportPath 	"$IPA_PATH_DIS" \
-exportProvisioningProfile $PROFILE_DIS

#判断IPA导出成功没
if [ ! -f "$IPA_PATH_DIS" ];then
	echo "IPA_DIS文件的导出没有成功"
	exit 1
fi

#上传到fir
if [ ! -f "$IPA_PATH_ADHOC" ];then
	echo "找不到IPA文件的路径"
	exit 1
fi

####获取上传基本信息
#USER_TOKEN和APP_ID,在fir.im网站上注册一个账号,新建一个项目就,有这两个变量了
USER_TOKEN="ee71ba0f10dae25b74659e976c470e73"
APP_ID="56fb5b7c00fc746ce200000e"
APP_TYPE="ios"
ICON_FILE="$(pwd)/fir_icon.png"
# echo ${ICON_FILE}

####获取当前时间
date_Y_M_D_W_T()
{
    WEEKDAYS=(星期日 星期一 星期二 星期三 星期四 星期五 星期六)
    WEEKDAY=$(date +%w)
    DT="$(date +%Y年%m月%d日) ${WEEKDAYS[$WEEKDAY]} $(date "+%H:%M:%S")"
    echo "$DT 更新测试包"
}

#读取Info.plist内容
InfoPlist="TXChat/info.plist"
Bundle_ID=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $InfoPlist`
BINARY_VERSION=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $InfoPlist`
BINARY_NAME=`/usr/libexec/PlistBuddy -c "Print CFBundleDisplayName" $InfoPlist`
BINARY_BUILD=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $InfoPlist`
BINARY_CHANGELOG="$(date_Y_M_D_W_T)"

# echo "getting token"

#POST请求获取上传凭证
APP_INFO=`curl -d "type=${APP_TYPE}&bundle_id=${Bundle_ID}&api_token=${USER_TOKEN}" http://api.fir.im/apps/${APP_ID}/releases 2>/dev/null`
# echo ${APP_INFO}

#上传Icon
echo "uploading icon"
ICON_KEY=$(echo ${APP_INFO} | grep "key.*binary" -o | awk -F '"' '{print $3;}')
ICON_TOKEN=$(echo ${APP_INFO} | grep "token.*token" -o | awk -F '"' '{print $3;}')
# echo ${ICON_KEY}
# echo ${ICON_TOKEN}

ICON_INFO=`curl -# -F file=@${ICON_FILE} -F "key=${ICON_KEY}" -F "token=${ICON_TOKEN}" http://upload.qiniu.com`
echo ${ICON_INFO}
if [ $? != 0 ];then
  echo "上传Icon失败"
  exit 1
fi

#上传Binary
echo "uploading ipa"
BINARY_KEY=$(echo ${APP_INFO} | grep "binary.*token" -o | awk -F '"' '{print $5;}')
BINARY_TOKEN=$(echo ${APP_INFO} | grep "binary.*upload_url" -o | awk -F '"' '{print $9;}')
# echo ${BINARY_KEY}
# echo ${BINARY_TOKEN}

BINARY_INFO=`curl -# -F file=@${IPA_PATH_ADHOC} -F "key=${BINARY_KEY}" -F "token=${BINARY_TOKEN}" -F "x:name=${BINARY_NAME}" -F "x:version=${BINARY_VERSION}" -F "x:build=${BINARY_BUILD}" -F "x:changelog=${BINARY_CHANGELOG}" http://upload.qiniu.com`
echo ${BINARY_INFO}
if [ $? != 0 ];then
  echo "上传IPA失败"
  exit 1
fi

echo "成功上传到fir地址:http://fir.im/jyjparent"
脚本在红框内,它们的工程目录结构。如下图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值