Create a gist now

Instantly share code, notes, and snippets.

Import keys
#!/bin/sh
# Usage: import.sh "directory/project/distribution/files" "G8DZVTHQJC"
ROOT_PATH="$1"
CER_FILENAME="$2".cer
P12_FILENAME="$2".p12
CERT_SHA1=`openssl x509 -inform DER -in $ROOT_PATH/$CER_FILENAME -noout -fingerprint | sed 's/\://g' | sed 's/.*=//g'`
if security find-identity -v -p codesigning | grep $CERT_SHA1 > /dev/null; then
echo "Found valid certificate in keychain"
else
echo "Importing $CER_FILENAME"
security -q import $ROOT_PATH/$CER_FILENAME -A -k ~/Library/Keychains/login.keychain -T /usr/bin/codesign -T /usr/bin/security 2>/dev/null
echo "Importing $P12_FILENAME"
security -q import $ROOT_PATH/$P12_FILENAME -A -k ~/Library/Keychains/login.keychain -T /usr/bin/codesign -T /usr/bin/security 2>/dev/null
fi
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment