Deleting expired provisioning profiles

放肆的年华 提交于 2019-12-10 00:25:46

问题


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?


回答1:


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 it to a format we can use to see if it is in the past (YYYYMMDD)
    read dow month day time timezone year <<< "${expirationDate}"
    ymd_expiration=`date -jf"%a %e %b %Y" "${dow} ${day} ${month} ${year}" +%Y%m%d`

    # compare it to today's date
    ymd_today=`date +%Y%m%d`

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

done

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) 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.



来源:https://stackoverflow.com/questions/37360201/deleting-expired-provisioning-profiles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!