#!/bin/bash
# 获取当前目录下的所有 .ipa 文件
ipas=($(find . -name "*.ipa" -path "./APP/*"))
# 初始化一个变量以保存最早的过期日期
earliest_expiration_date=""
earliest_left_days=0
calculate_remaining_days() {
# 参数1: 描述文件的过期日期(示例,格式为"Mon DD, YYYY at HH:MM:SS GMT+TZ",您需要替换为实际日期)
expiration_date=$1
# 移除末尾的Z并将T替换为空格
expiration_date="${expiration_date%Z}"
expiration_date="${expiration_date//T/ }"
# 将描述文件的过期日期转换为时间戳
expiration_timestamp=$(date -u -j -f "%Y-%m-%d %H:%M:%S" "$expiration_date" +%s)
# 获取当前日期的时间戳
current_timestamp=$(date +%s)
# 计算剩余秒数
remaining_seconds=$((expiration_timestamp - current_timestamp))
# 计算剩余天数
remaining_days=$((remaining_seconds / 86400))
# 返回剩余天数
echo $remaining_days
}
# 遍历每个 .ipa 文件
for ipa_file in "${ipas[@]}"; do
# 删除已存在的 Payload 文件夹
rm -rf Payload
# 解压 .ipa 文件
unzip -q "$ipa_file"
# 获取 .app 文件夹的名称
app_folder=$(find Payload -type d -name "*.app" -print)
if [ -n "$app_folder" ]; then
# 提取 app 名称
app_name=$(basename -s .app "$app_folder")
else
app_name="N/A"
fi
# 初始化描述文件过期时间
expired_time="N/A"
html_content=""
# 获取描述文件路径
mobileprovision_files=$(find "$app_folder" -name "embedded.mobileprovision" -print)
for mobileprovision_file in $mobileprovision_files; do
if [ -e "$mobileprovision_file" ]; then
# echo $(security cms -D -i "$mobileprovision_file")
# 提取描述文件中的过期时间
expired_time=$(security cms -D -i "$mobileprovision_file" | grep -A1 ExpirationDate | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 App ID Name
app_id_name=$(security cms -D -i "$mobileprovision_file" | grep -A1 "Name" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 App ID
app_id=$(security cms -D -i "$mobileprovision_file" | grep -A1 "application-identifier" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 Group ID
application_groups=$(/usr/libexec/PlistBuddy -c "Print :Entitlements:com.apple.security.application-groups:0" /dev/stdin <<< $(security cms -D -i "$mobileprovision_file"))
# 提取 Team
team=$(security cms -D -i "$mobileprovision_file" | grep -A1 "TeamName" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 Platform
platform=$(security cms -D -i "$mobileprovision_file" | grep -A1 "Platform" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 UUID
uuid=$(security cms -D -i "$mobileprovision_file" | grep -A1 "UUID" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 Creation Date
creation_date=$(security cms -D -i "$mobileprovision_file" | grep -A1 "CreationDate" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取 Expiration Date
expiration_date=$(security cms -D -i "$mobileprovision_file" | grep -A1 "ExpirationDate" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 提取环境
aps_environment=$(security cms -D -i "$mobileprovision_file" | grep -A1 "aps-environment" | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
# 剩余天数
left_days=$(calculate_remaining_days $expiration_date)
# 检查left_days是否小于30,如果是,将css_style设置为设置红色文本颜色的CSS样式
if [ $left_days -lt 30 ]; then
css_style="color: red; text-align: center;"
else
css_style="text-align: left;"
fi
# 检查是否是第一个描述文件或者过期时间更早
if [ -z "$earliest_expiration_date" ] || [[ "$expiration_date" < "$earliest_expiration_date" ]]; then
earliest_expiration_date="$expiration_date"
fi
# 计算多个描述文件中最快过期的那一个
earliest_left_days=$(calculate_remaining_days $earliest_expiration_date)
echo $application_groups
group_id=',' read -ra group_array <<< "$application_groups"
html_content+="
<tr>
<td style=\"$css_style\">$app_id</td>
<td style=\"$css_style\">$application_groups</td>
<td style=\"$css_style\">$aps_environment</td>
<td style=\"$css_style\">$team</td>
<td style=\"$css_style\">$creation_date</td>
<td style=\"$css_style\">$expiration_date</td>
<td style=\"$css_style\"><span style=\"$css_style\">$left_days</span></td>
</tr>
"
fi
done
# 删除解压的文件
rm -r Payload
done
# 头部HTML
html_header="
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>iOS App描述文件信息</title>
</head>
<body>
<div id='container'>
<center>
<h1>$app_name 描述文件信息</h1>
</center>
<div id='content'>
<table border='1' cellpadding='2' style='border-collapse:collapse;margin-top:10px'>
<tr>
<th>App ID</th>
<th>Group ID</th>
<th>Environment</th>
<th>Team</th>
<th>创建时间</th>
<th>过期时间</th>
<th>剩余天数</th>
</tr>
"
# 尾部HTML
html_footer="
</table>
</div>
</div>
</body>
</html>
"
# 添加HTML头部和尾部
html_output="${html_header}${html_content}${html_footer}"
echo $html_output
# 将HTML输出到文件或打印
echo "$html_output" >"./APP/info.html"
# 完成后显示输出文件
# cat "$output_file"
# 清理输出文件
# rm "$output_file"
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