Deleting expired provisioning profiles

This is a slightly modified version of the excellent answer from wottle.

Things I changed:

  • Added a force flag -f to really remove expired provisioning profiles. 
  • Improved std output just a bit. 

Hope it is useful.

#!/bin/bash

REMOVE_FLAG=$1

echo "Will check files: ${USER}/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision"
for provisioning_profile in ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision;
do
    filename=$(basename "${provisioning_profile}")
    printf "Checking %s ..." "${filename}"

    # pull the expiration date from the plist
    provisingInfo=$(security cms -D -i "${provisioning_profile}")
    expirationDate=$(/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' /dev/stdin <<< "$provisingInfo")

    printf "ExpirationDate: \"%s\" " "${expirationDate}"
    # 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
        printf "🚨 EXPIRED\n"
        if [ "$REMOVE_FLAG" = "-f" ];
        then
            rm -f "$provisioning_profile"
        fi
    else
        printf "✅ Usable\n"
    fi

done

Output:


0 comments :

This work is licensed under BSD Zero Clause License | nacho4d ®