-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmExpiredProfiles.sh
78 lines (69 loc) · 3.14 KB
/
rmExpiredProfiles.sh
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
#!/bin/bash
# File name : rmExpiredProfiles.sh
# Author: Eric Wu
#
echo current bash version is :$BASH_VERSION
if ((BASH_VERSINFO < 4)); then echo "Sorry, you need at least bash-4.0 to run this script." ; exit 1; fi
# http://yeshaoting.cn/article/mac/%E5%8D%87%E7%BA%A7mac%20bash%E5%88%B04.3%E7%89%88%E6%9C%AC/
declare -A dict
list=(~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision)
echo "清理过期mobileprovision,保留最新"
echo ""
echo ""
echo "共有 :${#list[@]} 个mobileprovision文件"
for provisioning_profile in ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision;
do
# printf "Checking ${provisioning_profile}... "
# pull the expiration date from the plist
expirationDate=`/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' /dev/stdin <<< $(security cms -D -i "${provisioning_profile}")`
name=`/usr/libexec/PlistBuddy -c 'Print :Name' /dev/stdin <<< $(security cms -D -i "${provisioning_profile}")`
teamName=`/usr/libexec/PlistBuddy -c 'Print :TeamName' /dev/stdin <<< $(security cms -D -i "${provisioning_profile}")`
# convert it to a format we can use to see if it is in the past (YYYYMMDD)
read dow month day time timezone year <<< "${expirationDate}"
# echo $year,$month,$day,$dow,
# Failed conversion of ``Sun 06 Jan 2019'' using format ``%a %e %b %Y''
export LANG="en_US.UTF-8"
#https://www.cnblogs.com/meitian/p/7768376.html
ymd_expiration=`date -jf "%a %d %b %Y" "${dow} ${day} ${month} ${year}" +%Y%m%d`
echo "$name $teamName :$ymd_expiration"
# # compare it to today's date
ymd_today=`date +%Y%m%d`
# echo $ymd_expiration,$ymd_today
if [ ${ymd_today} -ge ${ymd_expiration} ];
then
echo "EXPIRED"
echo "删除${name} :${ymd_expiration}"
rm -f "${provisioning_profile}"
else
# echo "not expired"
trimName=`echo "$name" | tr -d ' '`
# echo "未过期 trimName :$trimName"
originName=${dict[${trimName}]}
if [ -z $originName ]
then
dict[$trimName]=$trimName
dict["${trimName}Exp"]=$ymd_expiration
dict["${trimName}Path"]="$provisioning_profile"
else
echo "已添加到字典,执行比较判断"
originExp=${dict["${trimName}Exp"]}
originPath=${dict["${trimName}Path"]}
if [ ${ymd_expiration} -ge ${originExp} ]; then
path=${dict["${trimName}Path"]}
rm -f "$path"
dict["${trimName}Exp"]=$ymd_expiration
dict["${trimName}Path"]="$provisioning_profile"
echo "删除${originName} :${originExp} 保留 :${ymd_expiration}"
else
echo "删除${originName} :${ymd_expiration} 保留:${originExp}"
rm -f "${provisioning_profile}"
fi
fi
# for key in $(echo ${!dict[*]})
# do
# echo "循环 :$key : ${dict[$key]}"
# done
fi
done
list=(~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision)
echo "清理后还有 :${#list[@]} 个mobileprovision文件"