dsh-ipa-build 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +19 -0
- package/README.md +44 -48
- package/SKILL.md +42 -72
- package/index.js +1 -1
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/scripts/bootstrap.ps1 +50 -13
- package/scripts/bootstrap.sh +41 -11
- package/scripts/ipa +239 -89
- package/scripts/ipa.ps1 +195 -38
- package/scripts/templates/Info.plist +4 -0
- package/scripts/templates/entitlements.plist +6 -1
package/scripts/ipa
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# ipa-build 入口。Linux / macOS 用这个,Windows 用同目录的 ipa.ps1。
|
|
3
|
-
|
|
4
3
|
set -e
|
|
5
4
|
|
|
6
5
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
@@ -11,6 +10,7 @@ ldid="${IPA_LDID:-$tc/bin/ldid}"
|
|
|
11
10
|
|
|
12
11
|
die() { echo "$*" >&2; exit 1; }
|
|
13
12
|
need_ldid() { [ -x "$ldid" ] || die "没找到 ldid,先跑 scripts/bootstrap.sh"; }
|
|
13
|
+
need_py() { command -v python3 >/dev/null || die "缺 python3,改 plist 要用它(bootstrap 不装系统包,请自行 apt/dnf/pacman 装)"; }
|
|
14
14
|
|
|
15
15
|
zsign_bin() {
|
|
16
16
|
if [ -n "${IPA_ZSIGN:-}" ]; then echo "$IPA_ZSIGN"; return; fi
|
|
@@ -18,7 +18,17 @@ zsign_bin() {
|
|
|
18
18
|
command -v zsign 2>/dev/null || true
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
#
|
|
21
|
+
# 密码优先走环境变量,命令行参数只做兼容
|
|
22
|
+
cert_pass() {
|
|
23
|
+
local cli="$1"
|
|
24
|
+
if [ -n "$cli" ]; then
|
|
25
|
+
echo "提示:--password 会进 shell 历史和进程列表,建议改用 IPA_CERT_PASSWORD" >&2
|
|
26
|
+
printf '%s' "$cli"; return
|
|
27
|
+
fi
|
|
28
|
+
printf '%s' "${IPA_CERT_PASSWORD:-}"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# 有 p12 就走 zsign 真签名,没 p12 的地方还是走 ldid 伪签
|
|
22
32
|
sign_with_cert() {
|
|
23
33
|
local in="$1" out="$2"
|
|
24
34
|
local z; z="$(zsign_bin)"
|
|
@@ -33,19 +43,18 @@ sign_with_cert() {
|
|
|
33
43
|
|
|
34
44
|
plist_get() {
|
|
35
45
|
local dir="$1" key="$2"
|
|
36
|
-
python3 - "$dir/Info.plist" "$key" 2>/dev/null
|
|
46
|
+
python3 - "$dir/Info.plist" "$key" <<'PY' 2>/dev/null || true
|
|
37
47
|
import plistlib, sys
|
|
38
48
|
try:
|
|
39
49
|
with open(sys.argv[1], 'rb') as f:
|
|
40
50
|
d = plistlib.load(f)
|
|
41
|
-
|
|
42
|
-
if v is not None:
|
|
43
|
-
print(v)
|
|
51
|
+
print(d.get(sys.argv[2], '') or '')
|
|
44
52
|
except Exception:
|
|
45
53
|
pass
|
|
46
54
|
PY
|
|
47
55
|
}
|
|
48
56
|
|
|
57
|
+
# 只改/加字符串键;数字也按字符串写,CFBundleVersion 在规范里是字符串
|
|
49
58
|
plist_set() {
|
|
50
59
|
local dir="$1"; shift
|
|
51
60
|
python3 - "$dir/Info.plist" "$@" <<'PY'
|
|
@@ -55,21 +64,86 @@ with open(path, 'rb') as f:
|
|
|
55
64
|
d = plistlib.load(f)
|
|
56
65
|
for p in pairs:
|
|
57
66
|
k, _, v = p.partition('=')
|
|
58
|
-
if k == 'CFBundleVersion' and v.isdigit():
|
|
59
|
-
v = int(v)
|
|
60
67
|
d[k] = v
|
|
61
68
|
with open(path, 'wb') as f:
|
|
62
69
|
plistlib.dump(d, f)
|
|
63
70
|
PY
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
# 架构 + 签名状态,一次读完。不再用 file / 字符串搜索判断
|
|
74
|
+
macho_report() {
|
|
75
|
+
python3 - "$1" <<'PY'
|
|
76
|
+
import struct, sys
|
|
77
|
+
|
|
78
|
+
CPU = {16777228: 'arm64', 16777223: 'x86_64', 12: 'armv7', 7: 'i386', 16777222: 'arm64_32'}
|
|
79
|
+
|
|
80
|
+
path = sys.argv[1]
|
|
81
|
+
try:
|
|
82
|
+
data = open(path, 'rb').read()
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print('读不了|%s' % e)
|
|
85
|
+
sys.exit()
|
|
86
|
+
|
|
87
|
+
def u32(b, o):
|
|
88
|
+
return struct.unpack('<I', b[o:o + 4])[0]
|
|
89
|
+
|
|
90
|
+
def sig_state(off):
|
|
91
|
+
magic = u32(data, off)
|
|
92
|
+
if magic == 0xfeedfacf:
|
|
93
|
+
hsz = 32
|
|
94
|
+
elif magic == 0xfeedface:
|
|
95
|
+
hsz = 28
|
|
96
|
+
else:
|
|
97
|
+
return None
|
|
98
|
+
ncmds = u32(data, off + 16)
|
|
99
|
+
sizeofcmds = u32(data, off + 20)
|
|
100
|
+
pos, end = off + hsz, off + hsz + sizeofcmds
|
|
101
|
+
sigoff = None
|
|
102
|
+
while pos + 8 <= end and pos + 8 <= len(data):
|
|
103
|
+
cmd, size = u32(data, pos), u32(data, pos + 4)
|
|
104
|
+
if size < 8:
|
|
105
|
+
break
|
|
106
|
+
if cmd == 0x1d and pos + 16 <= len(data):
|
|
107
|
+
sigoff = u32(data, pos + 8)
|
|
108
|
+
pos += size
|
|
109
|
+
if sigoff is None or sigoff + 12 > len(data):
|
|
110
|
+
return None
|
|
111
|
+
if u32(data, sigoff) != 0xfade0cc0:
|
|
112
|
+
return None
|
|
113
|
+
count = u32(data, sigoff + 4)
|
|
114
|
+
types = []
|
|
115
|
+
for i in range(min(count, 20)):
|
|
116
|
+
types.append(u32(data, sigoff + 8 + i * 8))
|
|
117
|
+
if 0x10000 in types:
|
|
118
|
+
return 'cms'
|
|
119
|
+
if 0 in types:
|
|
120
|
+
return 'adhoc'
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
magic = u32(data, 0)
|
|
124
|
+
archs = []
|
|
125
|
+
sig = None
|
|
126
|
+
if magic in (0xfeedface, 0xfeedfacf):
|
|
127
|
+
archs = [CPU.get(u32(data, 4), '?')]
|
|
128
|
+
sig = sig_state(0)
|
|
129
|
+
elif magic in (0xcafebabe, 0xcafebabf):
|
|
130
|
+
nfat = u32(data, 4)
|
|
131
|
+
if nfat <= 20:
|
|
132
|
+
for i in range(nfat):
|
|
133
|
+
e = 8 + i * (32 if magic == 0xcafebabf else 20)
|
|
134
|
+
if e + 8 > len(data):
|
|
135
|
+
break
|
|
136
|
+
archs.append(CPU.get(u32(data, e), '?'))
|
|
137
|
+
if sig is None:
|
|
138
|
+
off = struct.unpack('<Q' if magic == 0xcafebabf else '<I', data[e + 8:e + 16 if magic == 0xcafebabf else e + 12])[0]
|
|
139
|
+
if off < len(data):
|
|
140
|
+
sig = sig_state(off)
|
|
141
|
+
else:
|
|
142
|
+
archs = ['不是 Mach-O']
|
|
143
|
+
|
|
144
|
+
label = {'cms': '真证书签名(有 CMS)', 'adhoc': 'ad-hoc 伪签名(只有 CodeDirectory)', None: '没签'}[sig]
|
|
145
|
+
print('|'.join(['+'.join(archs) or '?', label]))
|
|
146
|
+
PY
|
|
73
147
|
}
|
|
74
148
|
|
|
75
149
|
# Info.plist 里的 CFBundleExecutable 和实际文件名对不上时(手改过、重打包过),
|
|
@@ -78,27 +152,52 @@ find_exe() {
|
|
|
78
152
|
local app="$1" e
|
|
79
153
|
e="$(plist_get "$app" CFBundleExecutable)"
|
|
80
154
|
if [ -n "$e" ] && [ -f "$app/$e" ]; then echo "$e"; return; fi
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
155
|
+
python3 - "$app" <<'PY' 2>/dev/null || true
|
|
156
|
+
import os, struct, sys
|
|
157
|
+
app = sys.argv[1]
|
|
158
|
+
MAG = (0xfeedface, 0xfeedfacf, 0xcafebabe, 0xcafebabf) # 32/64 位 Mach-O 和 fat
|
|
159
|
+
for name in sorted(os.listdir(app)):
|
|
160
|
+
p = os.path.join(app, name)
|
|
161
|
+
if not os.path.isfile(p):
|
|
162
|
+
continue
|
|
163
|
+
try:
|
|
164
|
+
head = open(p, 'rb').read(4)
|
|
165
|
+
m = struct.unpack('<I', head)[0]
|
|
166
|
+
if m == 0xcafebabe and len(head) == 4:
|
|
167
|
+
# 0xcafebabe 也可能是 Java 类,看 nfat 是否像一个正常值
|
|
168
|
+
nfat = struct.unpack('<I', open(p, 'rb').read(8)[4:8])[0]
|
|
169
|
+
if nfat > 20:
|
|
170
|
+
continue
|
|
171
|
+
except Exception:
|
|
172
|
+
continue
|
|
173
|
+
if m in MAG:
|
|
174
|
+
print(name)
|
|
175
|
+
break
|
|
176
|
+
PY
|
|
90
177
|
}
|
|
91
178
|
|
|
92
179
|
find_app() {
|
|
93
|
-
find "$1" -maxdepth 3 -name '*.app' -type d | head -1
|
|
180
|
+
find "$1" -maxdepth 3 -name '*.app' -type d 2>/dev/null | awk '{ print length($0), $0 }' | sort -n | head -1 | cut -d' ' -f2-
|
|
94
181
|
}
|
|
95
182
|
|
|
96
183
|
cmd_doctor() {
|
|
97
|
-
|
|
98
|
-
|
|
184
|
+
local v
|
|
185
|
+
v="$(command -v clang >/dev/null 2>&1 && clang --version 2>/dev/null | head -1 | sed 's/.*version //' || echo 缺)"
|
|
186
|
+
printf '%-9s %s\n' clang "$v"
|
|
187
|
+
printf '%-9s %s\n' ld64.lld "$(command -v ld64.lld >/dev/null 2>&1 && echo ok || echo 缺)"
|
|
99
188
|
printf '%-9s %s\n' sdk "$([ -d "$sdk" ] && echo "$sdk" || echo 缺)"
|
|
100
189
|
printf '%-9s %s\n' ldid "$([ -x "$ldid" ] && echo "$ldid" || echo 缺)"
|
|
190
|
+
printf '%-9s %s\n' python3 "$(command -v python3 >/dev/null 2>&1 && echo ok || echo 缺)"
|
|
191
|
+
printf '%-9s %s\n' zip "$(command -v zip >/dev/null 2>&1 && echo ok || echo 缺)"
|
|
192
|
+
printf '%-9s %s\n' unzip "$(command -v unzip >/dev/null 2>&1 && echo ok || echo 缺)"
|
|
101
193
|
printf '%-9s %s\n' 系统 "$(uname -s)"
|
|
194
|
+
case "$(uname -s)" in
|
|
195
|
+
Linux)
|
|
196
|
+
if command -v apt-get >/dev/null 2>&1; then echo "包管理 apt(clang lld python3 zip unzip)"
|
|
197
|
+
elif command -v dnf >/dev/null 2>&1; then echo "包管理 dnf(clang lld python3 zip unzip)"
|
|
198
|
+
elif command -v pacman >/dev/null 2>&1; then echo "包管理 pacman(clang lld python zip unzip)"
|
|
199
|
+
else echo "包管理 认不出,bootstrap 只支持 apt/dnf/pacman"; fi;;
|
|
200
|
+
esac
|
|
102
201
|
}
|
|
103
202
|
|
|
104
203
|
cmd_info() {
|
|
@@ -112,19 +211,25 @@ cmd_info() {
|
|
|
112
211
|
local exe; exe="$(find_exe "$t")"
|
|
113
212
|
[ -n "$exe" ] || exe="$(basename "$t" .app)"
|
|
114
213
|
|
|
214
|
+
local bid ver build minos
|
|
215
|
+
bid="$(plist_get "$t" CFBundleIdentifier)"
|
|
216
|
+
ver="$(plist_get "$t" CFBundleShortVersionString)"
|
|
217
|
+
build="$(plist_get "$t" CFBundleVersion)"
|
|
218
|
+
minos="$(plist_get "$t" MinimumOSVersion)"
|
|
219
|
+
|
|
115
220
|
echo "位置 $orig"
|
|
116
221
|
echo "可执行 $exe"
|
|
117
|
-
echo "标识符 $
|
|
118
|
-
echo "版本 $
|
|
119
|
-
echo "最低系统 $
|
|
222
|
+
echo "标识符 $bid"
|
|
223
|
+
echo "版本 $ver build $build"
|
|
224
|
+
echo "最低系统 $minos"
|
|
225
|
+
if [ -z "$bid$ver$minos" ]; then
|
|
226
|
+
echo "plist 读不出字段,多半是二进制格式(bplist)——Xcode 产出的包都是这种,换 pack 或 resign 处理前先 plutil -convert xml1"
|
|
227
|
+
fi
|
|
120
228
|
if [ -f "$t/$exe" ]; then
|
|
121
|
-
|
|
229
|
+
local rep; rep="$(macho_report "$t/$exe")"
|
|
230
|
+
echo "架构 ${rep%%|*}"
|
|
231
|
+
echo "签名 ${rep#*|}"
|
|
122
232
|
echo "大小 $(du -h "$t/$exe" | cut -f1)"
|
|
123
|
-
if "$ldid" -h "$t/$exe" 2>/dev/null | grep -q CodeDirectory; then
|
|
124
|
-
echo "签名 有 CodeDirectory,是伪签名"
|
|
125
|
-
else
|
|
126
|
-
echo "签名 没签"
|
|
127
|
-
fi
|
|
128
233
|
fi
|
|
129
234
|
[ -n "$tmp" ] && rm -rf "$tmp"
|
|
130
235
|
true
|
|
@@ -139,7 +244,7 @@ cmd_build() {
|
|
|
139
244
|
[ -d "$sdk" ] || die "没有 SDK,先跑 scripts/bootstrap.sh"
|
|
140
245
|
|
|
141
246
|
local name="" bid="com.example.app" minios="14.0" ent="" icon="" out="" fw=()
|
|
142
|
-
local p12="" prov=""
|
|
247
|
+
local p12="" prov="" pwd_cli=""
|
|
143
248
|
while [ $# -gt 0 ]; do
|
|
144
249
|
case "$1" in
|
|
145
250
|
--name) name="$2"; shift 2;;
|
|
@@ -150,11 +255,12 @@ cmd_build() {
|
|
|
150
255
|
--framework) fw+=(-framework "$2"); shift 2;;
|
|
151
256
|
--p12) p12="$2"; shift 2;;
|
|
152
257
|
--prov) prov="$2"; shift 2;;
|
|
153
|
-
--password|--pass)
|
|
258
|
+
--password|--pass) pwd_cli="$2"; shift 2;;
|
|
154
259
|
-o) out="$2"; shift 2;;
|
|
155
260
|
*) die "不认识的参数: $1";;
|
|
156
261
|
esac
|
|
157
262
|
done
|
|
263
|
+
pwd_="$(cert_pass "$pwd_cli")"
|
|
158
264
|
[ -n "$name" ] || name="$(basename "$src")"
|
|
159
265
|
[ -n "$out" ] || out="$PWD/dist/$name.ipa"
|
|
160
266
|
|
|
@@ -162,11 +268,11 @@ cmd_build() {
|
|
|
162
268
|
local app="$work/Payload/$name.app"
|
|
163
269
|
rm -rf "$work"; mkdir -p "$app"
|
|
164
270
|
|
|
271
|
+
# 源码不限层级,跟 Windows 版保持一致
|
|
165
272
|
local files=() f
|
|
166
|
-
while IFS= read -r f; do files+=("$f"); done < <(find "$src" -
|
|
273
|
+
while IFS= read -r f; do files+=("$f"); done < <(find "$src" -type f \( -name '*.m' -o -name '*.mm' -o -name '*.c' -o -name '*.cpp' \) ! -path '*/.build/*')
|
|
167
274
|
[ ${#files[@]} -gt 0 ] || die "$src 里没有 .m/.mm/.c/.cpp"
|
|
168
275
|
|
|
169
|
-
# 碰了 UIKit 才链 UIKit,不然白拉一堆依赖
|
|
170
276
|
if [ ${#fw[@]} -eq 0 ]; then
|
|
171
277
|
if grep -rq "UIKit/" "$src" 2>/dev/null; then
|
|
172
278
|
fw=(-framework UIKit -framework Foundation)
|
|
@@ -181,44 +287,52 @@ cmd_build() {
|
|
|
181
287
|
done
|
|
182
288
|
|
|
183
289
|
echo "编译 ${#files[@]} 个文件,arm64 ios$minios"
|
|
184
|
-
clang -target "arm64-apple-ios$minios" -isysroot "$sdk"
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
290
|
+
clang -target "arm64-apple-ios$minios" -isysroot "$sdk" -F "$sdk/System/Library/Frameworks" -fuse-ld=lld -O2 -fPIC "${arc[@]}" "${fw[@]}" -o "$app/$name" "${files[@]}"
|
|
291
|
+
|
|
292
|
+
# 模板填充走 python,名字里带 & < | 也不会把 plist 弄坏
|
|
293
|
+
need_py
|
|
294
|
+
python3 - "$here/templates/Info.plist" "$app/Info.plist" "$name" "$bid" "$minios" <<'PY'
|
|
295
|
+
import sys
|
|
296
|
+
from xml.sax.saxutils import escape
|
|
297
|
+
tpl, out, name, bid, minios = sys.argv[1:6]
|
|
298
|
+
s = open(tpl, encoding='utf-8').read()
|
|
299
|
+
for k, v in (('@NAME@', name), ('@BUNDLEID@', bid), ('@MINIOS@', minios)):
|
|
300
|
+
s = s.replace(k, escape(v))
|
|
301
|
+
open(out, 'w', encoding='utf-8').write(s)
|
|
302
|
+
PY
|
|
192
303
|
[ -n "$icon" ] && [ -f "$icon" ] && cp "$icon" "$app/AppIcon60x60@2x.png"
|
|
193
|
-
|
|
194
304
|
chmod +x "$app/$name"
|
|
305
|
+
|
|
195
306
|
if [ -z "$p12" ]; then
|
|
196
307
|
need_ldid
|
|
197
|
-
if [ -n "$ent" ] && [ -f "$ent" ]; then
|
|
198
|
-
|
|
199
|
-
else
|
|
200
|
-
"$ldid" -S "$app/$name" || die "ldid 签名失败"
|
|
201
|
-
fi
|
|
308
|
+
if [ -n "$ent" ] && [ -f "$ent" ]; then "$ldid" -S"$ent" "$app/$name" || die "ldid 签名失败"
|
|
309
|
+
else "$ldid" -S "$app/$name" || die "ldid 签名失败"; fi
|
|
202
310
|
fi
|
|
203
311
|
|
|
204
312
|
local tmpipa="$out.tmp.ipa"
|
|
205
313
|
zip_payload "$tmpipa" "$work"
|
|
206
|
-
if [ -n "$p12" ]; then
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
else
|
|
210
|
-
mv -f "$tmpipa" "$out"
|
|
211
|
-
fi
|
|
314
|
+
if [ -n "$p12" ]; then sign_with_cert "$tmpipa" "$out"; rm -f "$tmpipa"
|
|
315
|
+
else mv -f "$tmpipa" "$out"; fi
|
|
316
|
+
rm -rf "$PWD/.build"
|
|
212
317
|
echo "产物 $out"
|
|
213
318
|
}
|
|
214
319
|
|
|
320
|
+
zip_payload() {
|
|
321
|
+
local out="$1" root="$2"
|
|
322
|
+
case "$out" in /*) ;; *) out="$PWD/$out";; esac
|
|
323
|
+
mkdir -p "$(dirname "$out")"
|
|
324
|
+
rm -f "$out"
|
|
325
|
+
# -y 保留符号链接,别把 .framework 里的链接展开成重复文件
|
|
326
|
+
( cd "$root" && zip -qry "$out" Payload )
|
|
327
|
+
}
|
|
328
|
+
|
|
215
329
|
cmd_pack() {
|
|
216
330
|
shift
|
|
217
331
|
local src="${1:-}"; [ -n "$src" ] || die "用法: ipa pack 某.app 或 含 Payload 的目录 [-o 输出.ipa]"
|
|
218
332
|
shift
|
|
219
333
|
[ -e "$src" ] || die "没有这个路径: $src"
|
|
220
334
|
|
|
221
|
-
local out="" bid="" name="" version="" icon="" p12="" prov=""
|
|
335
|
+
local out="" bid="" name="" version="" icon="" p12="" prov="" pwd_cli=""
|
|
222
336
|
while [ $# -gt 0 ]; do
|
|
223
337
|
case "$1" in
|
|
224
338
|
-o) out="$2"; shift 2;;
|
|
@@ -228,10 +342,11 @@ cmd_pack() {
|
|
|
228
342
|
--icon) icon="$2"; shift 2;;
|
|
229
343
|
--p12) p12="$2"; shift 2;;
|
|
230
344
|
--prov) prov="$2"; shift 2;;
|
|
231
|
-
--password|--pass)
|
|
345
|
+
--password|--pass) pwd_cli="$2"; shift 2;;
|
|
232
346
|
*) die "不认识的参数: $1";;
|
|
233
347
|
esac
|
|
234
348
|
done
|
|
349
|
+
pwd_="$(cert_pass "$pwd_cli")"
|
|
235
350
|
|
|
236
351
|
local work; work="$(mktemp -d)"; mkdir -p "$work/Payload"
|
|
237
352
|
if [ -d "$src" ] && [ "$(basename "$src")" = "Payload" ]; then
|
|
@@ -241,13 +356,21 @@ cmd_pack() {
|
|
|
241
356
|
fi
|
|
242
357
|
|
|
243
358
|
local app; app="$(find "$work/Payload" -maxdepth 1 -name '*.app' -type d | head -1)"
|
|
244
|
-
[ -
|
|
359
|
+
if [ -z "$app" ]; then
|
|
360
|
+
app="$(find "$work" -name '*.app' -type d | awk '{ print length($0), $0 }' | sort -n | head -1 | cut -d' ' -f2-)"
|
|
361
|
+
[ -n "$app" ] || die "这棵树里没找到 .app。可以直接把 .app 本身当参数传进来"
|
|
362
|
+
echo "给的目录里没有顶层 .app,改用找到的这个:$app"
|
|
363
|
+
fi
|
|
245
364
|
|
|
365
|
+
need_py
|
|
246
366
|
local pairs=()
|
|
247
367
|
[ -n "$bid" ] && pairs+=("CFBundleIdentifier=$bid")
|
|
248
368
|
[ -n "$name" ] && pairs+=("CFBundleDisplayName=$name" "CFBundleExecutable=$name")
|
|
249
369
|
[ -n "$version" ] && pairs+=("CFBundleShortVersionString=$version")
|
|
250
|
-
[ ${#pairs[@]} -gt 0 ]
|
|
370
|
+
if [ ${#pairs[@]} -gt 0 ]; then
|
|
371
|
+
[ -f "$app/Info.plist" ] || die "$app 里没有 Info.plist"
|
|
372
|
+
plist_set "$app" "${pairs[@]}"
|
|
373
|
+
fi
|
|
251
374
|
[ -n "$icon" ] && [ -f "$icon" ] && cp "$icon" "$app/AppIcon60x60@2x.png"
|
|
252
375
|
|
|
253
376
|
local exe; exe="$(find_exe "$app")"
|
|
@@ -256,7 +379,7 @@ cmd_pack() {
|
|
|
256
379
|
mv "$app/$exe" "$app/$name"
|
|
257
380
|
exe="$name"
|
|
258
381
|
fi
|
|
259
|
-
[ -z "$out" ] && out="$PWD/dist/$(basename "$app" .app).ipa"
|
|
382
|
+
[ -z "$out" ] && out="$PWD/dist/${name:-$(basename "$app" .app)}.ipa"
|
|
260
383
|
|
|
261
384
|
if [ -z "$p12" ] && [ -f "$app/$exe" ] && [ -x "$ldid" ]; then
|
|
262
385
|
rm -rf "$app/_CodeSignature"
|
|
@@ -265,23 +388,52 @@ cmd_pack() {
|
|
|
265
388
|
|
|
266
389
|
local tmpipa="$out.tmp.ipa"
|
|
267
390
|
zip_payload "$tmpipa" "$work"
|
|
268
|
-
if [ -n "$p12" ]; then
|
|
269
|
-
|
|
270
|
-
rm -f "$tmpipa"
|
|
271
|
-
else
|
|
272
|
-
mv -f "$tmpipa" "$out"
|
|
273
|
-
fi
|
|
391
|
+
if [ -n "$p12" ]; then sign_with_cert "$tmpipa" "$out"; rm -f "$tmpipa"
|
|
392
|
+
else mv -f "$tmpipa" "$out"; fi
|
|
274
393
|
rm -rf "$work"
|
|
275
394
|
echo "产物 $out"
|
|
276
395
|
}
|
|
277
396
|
|
|
397
|
+
# 内嵌的 framework / appex / dylib 都得签,只签主程序启动就崩
|
|
398
|
+
sign_nested() {
|
|
399
|
+
local app="$1" ent="$2" d
|
|
400
|
+
if [ -d "$app/PlugIns" ]; then
|
|
401
|
+
while IFS= read -r x; do
|
|
402
|
+
local xe; xe="$(plist_get "$x" CFBundleExecutable)"
|
|
403
|
+
[ -n "$xe" ] || xe="$(basename "$x" .appex)"
|
|
404
|
+
if [ -n "$ent" ] && [ -f "$ent" ]; then "$ldid" -S"$ent" "$x/$xe" || die "签 $x 失败"
|
|
405
|
+
else "$ldid" -S "$x/$xe" || die "签 $x 失败"; fi
|
|
406
|
+
find "$x" -name '*.dylib' -type f | while read -r d; do "$ldid" -S "$d" || true; done
|
|
407
|
+
done < <(find "$app/PlugIns" -maxdepth 2 -name '*.appex' -type d 2>/dev/null)
|
|
408
|
+
fi
|
|
409
|
+
if [ -d "$app/Frameworks" ]; then
|
|
410
|
+
while IFS= read -r fwdir; do
|
|
411
|
+
local bin="$fwdir/$(basename "$fwdir" .framework)"
|
|
412
|
+
[ -f "$bin" ] && { "$ldid" -S "$bin" || die "签 $bin 失败"; }
|
|
413
|
+
find "$fwdir" -name '*.dylib' -type f | while read -r d; do "$ldid" -S "$d" || true; done
|
|
414
|
+
done < <(find "$app/Frameworks" -maxdepth 1 -name '*.framework' -type d 2>/dev/null)
|
|
415
|
+
find "$app/Frameworks" -maxdepth 1 -name '*.dylib' -type f | while read -r d; do "$ldid" -S "$d" || true; done
|
|
416
|
+
fi
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
# 换主 id 时扩展的 id 要跟着换,真签要求 appex id 以主 app id 开头
|
|
420
|
+
retag_appex() {
|
|
421
|
+
local app="$1" bid="$2" x eid base
|
|
422
|
+
while IFS= read -r x; do
|
|
423
|
+
eid="$(plist_get "$x" CFBundleIdentifier)"
|
|
424
|
+
[ -n "$eid" ] || continue
|
|
425
|
+
base="${eid##*.}"
|
|
426
|
+
plist_set "$x" "CFBundleIdentifier=$bid.$base"
|
|
427
|
+
done < <(find "$app/PlugIns" -maxdepth 2 -name '*.appex' -type d 2>/dev/null)
|
|
428
|
+
}
|
|
429
|
+
|
|
278
430
|
cmd_resign() {
|
|
279
431
|
shift
|
|
280
432
|
local src="${1:-}"; [ -n "$src" ] || die "用法: ipa resign 某.ipa 或 某.app [-o 输出.ipa]"
|
|
281
433
|
shift
|
|
282
434
|
[ -e "$src" ] || die "没有这个路径: $src"
|
|
283
435
|
|
|
284
|
-
local out="" ent="" bid="" p12="" prov=""
|
|
436
|
+
local out="" ent="" bid="" p12="" prov="" pwd_cli=""
|
|
285
437
|
while [ $# -gt 0 ]; do
|
|
286
438
|
case "$1" in
|
|
287
439
|
-o) out="$2"; shift 2;;
|
|
@@ -289,10 +441,11 @@ cmd_resign() {
|
|
|
289
441
|
--bundle-id) bid="$2"; shift 2;;
|
|
290
442
|
--p12) p12="$2"; shift 2;;
|
|
291
443
|
--prov) prov="$2"; shift 2;;
|
|
292
|
-
--password|--pass)
|
|
444
|
+
--password|--pass) pwd_cli="$2"; shift 2;;
|
|
293
445
|
*) die "不认识的参数: $1";;
|
|
294
446
|
esac
|
|
295
447
|
done
|
|
448
|
+
pwd_="$(cert_pass "$pwd_cli")"
|
|
296
449
|
|
|
297
450
|
local work; work="$(mktemp -d)"
|
|
298
451
|
case "$src" in
|
|
@@ -304,31 +457,28 @@ cmd_resign() {
|
|
|
304
457
|
local app; app="$(find "$work/Payload" -maxdepth 1 -name '*.app' -type d | head -1)"
|
|
305
458
|
[ -n "$app" ] || die "包里没有 .app"
|
|
306
459
|
|
|
307
|
-
[ -n "$bid" ]
|
|
460
|
+
if [ -n "$bid" ]; then
|
|
461
|
+
need_py
|
|
462
|
+
plist_set "$app" "CFBundleIdentifier=$bid"
|
|
463
|
+
retag_appex "$app" "$bid"
|
|
464
|
+
fi
|
|
308
465
|
rm -rf "$app/_CodeSignature"
|
|
309
466
|
|
|
310
467
|
local exe; exe="$(find_exe "$app")"
|
|
311
468
|
[ -z "$exe" ] && die "这个 app 里没找到可执行文件"
|
|
312
469
|
if [ -z "$p12" ]; then
|
|
313
470
|
need_ldid
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
else
|
|
317
|
-
"$ldid" -S "$app/$exe"
|
|
318
|
-
fi
|
|
319
|
-
# 包里带的 dylib 也得签,不然启动就崩
|
|
320
|
-
find "$app" -name '*.dylib' -type f 2>/dev/null | while read -r d; do "$ldid" -S "$d" 2>/dev/null || true; done
|
|
471
|
+
sign_nested "$app" "$ent"
|
|
472
|
+
if [ -n "$ent" ] && [ -f "$ent" ]; then "$ldid" -S"$ent" "$app/$exe" || die "ldid 签名失败"
|
|
473
|
+
else "$ldid" -S "$app/$exe" || die "ldid 签名失败"; fi
|
|
321
474
|
fi
|
|
322
475
|
|
|
323
|
-
|
|
476
|
+
local leaf; leaf="$(basename "$src")"; leaf="${leaf%.*}"
|
|
477
|
+
[ -z "$out" ] && out="$PWD/dist/${leaf}_resigned.ipa"
|
|
324
478
|
local tmpipa="$out.tmp.ipa"
|
|
325
479
|
zip_payload "$tmpipa" "$work"
|
|
326
|
-
if [ -n "$p12" ]; then
|
|
327
|
-
|
|
328
|
-
rm -f "$tmpipa"
|
|
329
|
-
else
|
|
330
|
-
mv -f "$tmpipa" "$out"
|
|
331
|
-
fi
|
|
480
|
+
if [ -n "$p12" ]; then sign_with_cert "$tmpipa" "$out"; rm -f "$tmpipa"
|
|
481
|
+
else mv -f "$tmpipa" "$out"; fi
|
|
332
482
|
rm -rf "$work"
|
|
333
483
|
echo "产物 $out"
|
|
334
484
|
}
|
|
@@ -343,5 +493,5 @@ case "${1:-}" in
|
|
|
343
493
|
echo " info 看 ipa/app 的标识、版本、架构、签没签"
|
|
344
494
|
echo " build .m/.c 编成 ipa,需要 clang 和 SDK"
|
|
345
495
|
echo " pack .app 打成 ipa,可改标识/显示名/版本/图标"
|
|
346
|
-
echo " resign 已有的 ipa 或 app
|
|
496
|
+
echo " resign 已有的 ipa 或 app 重签,可换标识";;
|
|
347
497
|
esac
|