forked from liaoque/ipasign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignIpa.rb
134 lines (106 loc) · 4.46 KB
/
signIpa.rb
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
require "spaceship"
require "mysql2"
require 'pathname'
require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/globalConfig'
require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/mysqlInstance'
# certificate_pem key_pem 所使用的的p12文件 必须和 mobileprovision的cer签名文件一致
# 否则重新签名后也无法使用
inFile = ARGV[0];
uid = ARGV[1];
uuid = ARGV[2];
gid = ARGV[3];
gameName = ARGV[4];
bundleId = ARGV[5];
#加入打包日志
cTime = Time.now
eTime = cTime + 31536000
# 更新mysql
begin
client = MysqlInstance.instance.getClient();
#寻找对应的开发者
results = client.query("SELECT apuid FROM apple_developer_uuid WHERE uuid='#{uuid}' limit 1")
if !results.any?
raise "设备号: #{uuid} 不存在"
end
apuid = results.first['apuid']
results = client.query("SELECT user FROM apple_developer WHERE apuid='#{apuid}' limit 1")
if !results.any?
raise "设备号: #{uuid} 不存在"
end
username = results.first['user']
#寻找对应的授权文件
# puts "SELECT mobileprovision,certificate_id FROM apple_developer_mobileprovision WHERE apuid= '#{apuid}' and status = 1"
results = client.query("SELECT mobileprovision,certificate_id FROM apple_developer_mobileprovision WHERE apuid= '#{apuid}' and build_id='#{bundleId}' and status = 1")
if !results.any?
raise "mobileprovision 不存在"
end
mobileProvision = results.first['mobileprovision']
certificateId = results.first['certificate_id']
# puts "SELECT certificate_pem,key_pem FROM apple_developer_cer WHERE certificate_id= '#{certificateId}'"
results = client.query("SELECT certificate_pem,key_pem FROM apple_developer_cer WHERE certificate_id= '#{certificateId}' and status = 1")
if !results.any?
raise "certificate_id: #{certificateId} 不存在"
end
certificatePem = results.first['certificate_pem']
keyPem = results.first['key_pem']
# isign -c /path/to/mycert.pem -k ~/mykey.pem -p path/to/my.mobileprovision -o my222.ipa lcfh_allDis.ipa
outFile = "/applesign/#{username}/#{certificateId}/#{gid}/#{uuid}_#{cTime.strftime("%Y%m%d%H%M%S")}.ipa"
_outFile = GlobalConfig::ROOT_KEY + outFile
keyPath = GlobalConfig::ROOT_KEY + "/applesign/#{username}/#{certificateId}/#{gid}"
system "mkdir -p #{keyPath}"
system "chmod 777 #{keyPath}"
certificatePem = GlobalConfig::ROOT_KEY + certificatePem
mobileProvision = GlobalConfig::ROOT_KEY + mobileProvision
keyPem = GlobalConfig::ROOT_KEY + keyPem
system "rm -rf #{_outFile}"
# puts "/usr/bin/isign -c #{certificatePem} -k #{keyPem} -p #{mobileProvision} -o #{_outFile} #{inFile}"
res = system "/usr/bin/isign -c #{certificatePem} -k #{keyPem} -p #{mobileProvision} -o #{_outFile} #{inFile}"
if !res
raise "/usr/bin/isign -c #{certificatePem} -k #{keyPem} -p #{mobileProvision} -o #{_outFile} #{inFile} 失败"
end
plist = "/applesign/#{username}/#{certificateId}/#{gid}/#{uuid}_#{cTime.strftime("%Y%m%d%H%M%S")}.plist"
url = GlobalConfig::ROOT_IMG_PATH + outFile
File.open(GlobalConfig::ROOT_KEY + plist, "w+") do |aFile|
aFile.puts <<EOF
<?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>#{url}</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>#{bundleId}</string>
<key>bundle-version</key>
<string>1.0</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>#{gameName}</string>
</dict>
</dict>
</array>
</dict>
</plist>
EOF
end
results = client.query("insert into apple_developer_ipa_log (uid, uuid, gid, apuid, certificate_id, certificate_pem, key_pem, mobileprovision, source_ipa, to_ipa, plist, build_id, c_time, e_time)values('#{uid}', '#{uuid}', '#{gid}', '#{apuid}', '#{certificateId}', '#{certificatePem}', '#{keyPem}', '#{mobileProvision}', '#{inFile}', '#{outFile}', '#{plist}', '#{bundleId}', '#{cTime.strftime("%Y-%m-%d %H:%M:%S")}', '#{eTime.strftime("%Y-%m-%d %H:%M:%S")}')")
rescue Exception => e
puts "Trace message: #{e}"
else
puts outFile
ensure
# 断开与服务器的连接
# MysqlInstance.instance.close()
end