-
Notifications
You must be signed in to change notification settings - Fork 399
/
ipa-publish-fir
executable file
·225 lines (187 loc) · 7.01 KB
/
ipa-publish-fir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
#--------------------------------------------
# 功能:上传ipa 到 fir.im,并可以发送邮件给相关人
# 注意:该脚本上传的ipa依赖于ipa-build脚本生成的目录结构和文件
# 作者:ccf & jiecao.fm
# E-mail:zhoujun@jiecao.fm
# 创建日期:2012/09/24
#--------------------------------------------
# 修改日期:2012/09/27
# 修改人:ccf
# 修改内容:去掉打包的部分脚本,只保留生成协议文件部分,以后此脚本依赖ipa-build脚本生成的内容
#--------------------------------------------
# 修改日期:2013/02/18
# 修改人:ccf
# 修改内容:添加通过sftp上传到服务器的功能
#--------------------------------------------
# 修改日期:2013/02/19
# 修改人:ccf
# 修改内容:添加上传服务器后邮件提醒功能
#--------------------------------------------
# 修改日期:2013/02/27
# 修改人:ccf
# 修改内容:添加更新服务器上工程索引文件功能
#--------------------------------------------
# 修改日期:2014/05/17
# 修改人:Shannon Chou
# 修改内容:在原ipa-publish 的基础上改为ipa-publish-fir,用于将app 发布到fir.im上测试
#--------------------------------------------
# 修改日期:2017/03/22
# 修改人:Shannon Chou
# 修改内容:修改配置部分, 该脚本已废弃,建议使用fir 官方cli 工具
#--------------------------------------------
#须配置内容 start
#以下是邮箱的相关设置
#收件人,多个收件人以空格分隔
email_reciver=""
#发送者邮箱
email_sender=
#邮箱用户名
email_username=
#邮箱密码
email_password=
#smtp服务器地址
email_smtphost=smtp.exmail.qq.com
#可配置内容 end
#fir 相关url
fir_domain="http://fir.im"
fir_lookup_url="$fir_domain/api/v2/app/info"
fir_finish_url="$fir_domain/api/finish"
fir_token="nu4s06BnAoHqugPRdEShv0lfRq7e9HahWL1kybwq"
#获取shell文件所在的绝对路径
current_path=$(pwd)
tmp_path=$(dirname $0)
cd $tmp_path
shell_path=$(pwd)
cd $current_path
#参数判断
should_email=n
git_log_limit=0
project_path=
change_msg=
while getopts el:d:m: opt
do
case "$opt" in
e) should_email=y;;
l) git_log_limit="$OPTARG";;
d) project_path="$OPTARG";;
m) change_msg="$OPTARG";;
\?) # unknown flag
echo >&2 \
"usage: $0 [-d directory>] [-e] [-l number] [-m message]"
exit 1;;
esac
done
shift `expr $OPTIND - 1`
#工程绝对路径
cd $project_path
project_path=$(pwd)
#判断所输入路径是否是xcode工程的根路径
ls | grep .xcodeproj > /dev/null
rtnValue=$?
if [ $rtnValue != 0 ];then
echo "Error!! The param must be the root path of a xcode project."
exit
fi
#判断是否执行过ipa-build脚本
ls ./build/ipa-build/*.ipa &>/dev/null
rtnValue=$?
if [ $rtnValue != 0 ];then
echo "Error!! No ipa files exists.Please run the \"ipa-build\" shell script first"
exit
fi
#build文件夹路径
build_path=${project_path}/build
echo "Fetching app infomation from the ipa file..."
#切换到tmp文件夹
cd /tmp
#创建临时文件夹
tmpfoldername=ipa_tmp
if [ -d ./${tmpfoldername} ];then
rm -rf ${tmpfoldername}
fi
mkdir ${tmpfoldername}
cd ${tmpfoldername}
#拷贝ipa到临时文件夹中
cp ${build_path}/ipa-build/*.ipa ./tmp.zip
#将ipa解压
unzip tmp.zip &>/dev/null
#app文件中Info.plist文件路径
app_infoplist_path=$(pwd)/Payload/*.app/Info.plist
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${app_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path})
#取bundleIdentifier
bundleIdentifier=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" ${app_infoplist_path})
#取CFBundleName
target_name=$(/usr/libexec/PlistBuddy -c "print CFBundleName" ${app_infoplist_path})
#取CFBundleDisplayName
display_name=$(/usr/libexec/PlistBuddy -c "print CFBundleDisplayName" ${app_infoplist_path})
echo "App $display_name版本号为: $bundleShortVersion, 构建号为: $bundleVersion."
#删除临时文件夹
cd ..
rm -rf ${tmpfoldername}
#进入到工程build路径下
cd $build_path
#显示名称
ipa_name="${display_name}"
if [ -d ./$target_name ];then
rm -rf $target_name
fi
mkdir $target_name
#拷贝ipa
cp ./ipa-build/*.ipa ./$target_name/${target_name}.ipa
cd $target_name
#处理用户输入的消息
change_msg=`echo $change_msg | tr -d " " | awk '{printf "%s<br/>",$1}'`
#获取git的提交日志
git_log=
if [ $git_log_limit != 0 ];then
echo "Fetching the git log..."
git_log=`git log --pretty=format:"%s" -$git_log_limit | tr -d " " | awk '{printf "%s<br/>",$1}'`
fi
echo "===== bundleIdentifier is $bundleIdentifier ======"
#到fir api 查询具体的包上传地址
echo "Fetching upload url from fir..."
echo "do fetch $fir_lookup_url/$bundleIdentifier?token=$fir_token"
response=`curl "$fir_lookup_url/$bundleIdentifier?token=$fir_token"`
echo $response
#网络请求结果判断
rtnValue=$?
if [ $rtnValue != 0 ];then
exit 1
fi
fir_publish_url=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['bundle']['pkg']['url']"`
echo $fir_publish_url
fir_publish_key=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['bundle']['pkg']['key']"`
fir_publish_token=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['bundle']['pkg']['token']"`
realShort=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['short']"`
#第一次请求得到的 Appid, 用来最后更新 App 的信息.
fir_app_id=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['id']"`
#上传ipa包,并获取最终的url short name
echo "Uploading the ipa file..."
curl -F file=@${target_name}.ipa -F "key=$fir_publish_key" -F "token=$fir_publish_token" $fir_publish_url
rtnValue=$?
if [ $rtnValue != 0 ];then
exit 1
fi
echo "Finishing uploading and filling in the app information..."
echo "Updateing app info."
response=`curl -X PUT -H "Content-Length: 0" -L "http://fir.im/api/v2/app/$fir_app_id?token=$fir_token&version=$bundleVersion&versionShort=$bundleShortVersion" -v`
realShort=`ruby -e "require 'json'; iJson = JSON.parse '${response}'; puts iJson['short']"`
#拼接完整的下载url,并在浏览器中打开
pulish_url=$fir_domain/$realShort
echo $pulish_url
# open $pulish_url
build_time=`date`
#发送邮件
#将之前html的换行方式改为\n
git_log=`echo ${git_log//<br\/>/\\\n}`
change_msg=`echo ${change_msg//<br\/>/\\\n}`
if [ $should_email = y ];then
echo "Sending email..."
email_title="${ipa_name}V${bundleShortVersion}-iOS客户端更新"
email_content="hi,\n\nThe app is updated recently. Use the safari browser on iOS device to download the app. Here is the URL: ${pulish_url} \n\nBuild time:${build_time}\nChange log:\n$change_msg \n$git_log \n\n\nThis email is sent by the automantic shell which is created by ccf & jiecao.fm, so do not reply this email.\n\nThanks!"
${shell_path}/sendEmail -f ${email_sender} -t ${email_reciver} -s ${email_smtphost} -u ${email_title} -xu ${email_username} -xp ${email_password} -m ${email_content}
fi