删除过期的配置文件 [英] Deleting expired provisioning profiles

查看:119
本文介绍了删除过期的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅使用终端,如何识别和删除~/Library/MobileDevice/Provisioning Profiles

Using exclusively terminal, how can one identify and delete the expired provisioning profiles from ~/Library/MobileDevice/Provisioning Profiles

有没有一种方法可以仅在终端上完成?

Is there a way to do that just from terminal?

推荐答案

您可以编写一个shell脚本,该脚本将遍历文件,从mobileprovision文件中获取日期,然后将其与当前日期进行比较.

You can write a shell script that will loop through the files, grab the date from the mobileprovision file, and check it against the current date.

#!/bin/sh

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}")`

    # convert expirationDate and current date to epoch (Unix Timestamps) then compare both.
    timestamp_expiration=`date -jf"%a %b %d %T %Z %Y" "${expirationDate}" +%s`
    timestamp_now=`date +%s`

    if [ ${timestamp_now} -ge ${timestamp_expiration} ];
    then
        echo "EXPIRED"
        # rm -f "${provisioning_profile}"
    else
        echo "not expired"
    fi

done

您可以使用security命令和plist buddy从文件中提取ExpirationDate.然后,为简单起见,我只是将该日期转换为易于比较的格式( YYYMMDD Unix时间戳或自1970年以来的秒数),然后将其与相同格式的今天的日期进行比较.我打印出每个状态.注意:我不执行删除操作,因为我希望您在取消注释删除行之前先验证脚本结果.我在我的机器上运行它,并添加了旧的配置文件.它在我的测试中正确地标识了过期的配置文件.

You can use the security command and plist buddy to extract the ExpirationDate from the file. Then for simplicity I just convert that date to a easily comparable format (YYYMMDD unix time stamps or seconds since 1970) and compare it to today's date in the same format. I print out the status of each. Note: I do not do the delete, because I want you to verify the script results before you uncomment the removal line. I ran it on mine, and threw in an old profile. It correctly identified the expired profile in my tests.

这篇关于删除过期的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆