-
Notifications
You must be signed in to change notification settings - Fork 399
/
ipa-publish
executable file
·265 lines (220 loc) · 7.25 KB
/
ipa-publish
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
#--------------------------------------------
# 功能:创建符合itms-services协议的发布文件
# 作者:ccf
# E-mail:[email protected]
# 创建日期:2012/09/24
#--------------------------------------------
# 修改日期:2012/09/27
# 修改人:ccf
# 修改内容:去掉打包的部分脚本,只保留生成协议文件部分,以后此脚本依赖ipa-build脚本生成的内容
#--------------------------------------------
# 修改日期:2013/02/18
# 修改人:ccf
# 修改内容:添加通过sftp上传到服务器的功能
#--------------------------------------------
# 修改日期:2013/02/19
# 修改人:ccf
# 修改内容:添加上传服务器后邮件提醒功能
#--------------------------------------------
# 修改日期:2013/02/27
# 修改人:ccf
# 修改内容:添加更新服务器上工程索引文件功能
#--------------------------------------------
#须配置内容 start
#sftp参数设置
sftp_server=192.168.xx.xx
sftp_username=xx
sftp_password=xx
sftp_workpath="/usr/share/xx/xx/xx"
#发布应用的url地址
pulish_url="http://xx.com/xx"
#以下是邮箱的相关设置
#收件人
#发送者邮箱
#邮箱用户名
email_username=xx
#邮箱密码
email_password=xx
#smtp服务器地址
email_smtphost=smtp.exmail.qq.com
#可配置内容 end
#获取shell文件所在的绝对路径
current_path=$(pwd)
tmp_path=$(dirname $0)
cd $tmp_path
shell_path=$(pwd)
cd $current_path
#参数判断
if [ $# != 2 ] && [ $# != 1 ];then
echo "Number of params error! Need one or two params!"
echo "1.root path of project(necessary) 2.should send email after upload?y/n(default is n)"
exit
elif [ ! -d $1 ];then
echo "The param must be a dictionary."
exit
fi
should_email=n
if [ $# = 2 ];then
should_email=$2
if [ $should_email != y ] && [ $should_email != n ];then
echo "Error! The Second Param must be y or n!"
exit
fi
fi
#工程绝对路径
cd $1
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
#切换到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
#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})
#删除临时文件夹
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
cp ../[email protected] ./$target_name/${target_name}_logo.png
cd $target_name
#ipa下载url
ipa_download_url=${pulish_url}/${target_name}/${target_name}.ipa
#itms-services协议串
ios_install_url="itms-services://?action=download-manifest&url=${pulish_url}/${target_name}/${target_name}.plist"
#生成install.html文件
cat << EOF > index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>安装此软件</title>
</head>
<body>
<br>
<br>
<br>
<br>
<p align=center>
<font size="8">
<a href="${ios_install_url}">点击这里安装</a>
</font>
</p>
</div>
</body>
</html>
EOF
#生成plist文件
cat << EOF > ${target_name}.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>${ipa_download_url}</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>${pulish_url}/${target_name}/${target_name}_logo.png</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>${pulish_url}/${target_name}/${target_name}_logo.png</string>
</dict>
</array><key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>${bundleIdentifier}</string>
<key>bundle-version</key>
<string>${bundleVersion}</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>${ipa_name}</string>
<key>title</key>
<string>${ipa_name}</string>
</dict>
</dict>
</array>
</dict>
</plist>
EOF
#调用upload脚本来将文件上传到服务器
${shell_path}/uploadItemsServicesFiles $target_name ${sftp_server} ${sftp_username} ${sftp_password} ${sftp_workpath} || exit
#切换到tmp目录下
serverIndexHtmlName=index.html
cd /tmp
rm ${serverIndexHtmlName}
#从服务器下载index.html
${shell_path}/sftpDownloadFile ${serverIndexHtmlName} ${sftp_server} ${sftp_username} ${sftp_password} ${sftp_workpath} || exit
#更新index.html
${shell_path}/updateLocalIndexHtml ${display_name} ${bundleShortVersion} ${ipa_download_url} ${ios_install_url} || exit
#上传index.html
${shell_path}/sftpUploadFile ${serverIndexHtmlName} ${sftp_server} ${sftp_username} ${sftp_password} ${sftp_workpath} || exit
#发送邮件
if [ $should_email = y ];then
email_title="${ipa_name}-IOS客户端更新"
email_content="hi,\n\n The app is updated recently.Use the safari browser on IOS device to download the app.Here is the URL: ${pulish_url}/${target_name} \n\n To see the list of all iOS projects, open this URL: ${pulish_url} \n\n\n This email is sent by the automantic shell which is created by ccf,so do not reply this email.\n\n\n\n\n Thanks!"
${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