| 1 | #!/bin/bash |
| 2 | |
| 3 | KEY_CHAIN=build.keychain |
| 4 | CERTIFICATE_P12=certificate.p12 |
| 5 | |
| 6 | # Recreate the certificate from the secure environment variable |
| 7 | echo ${APPLE_CERT_P12} | base64 --decode > $CERTIFICATE_P12 |
| 8 | |
| 9 | # Create a keychain |
| 10 | security create-keychain -p main $KEY_CHAIN |
| 11 | |
| 12 | # Make the keychain the default so identities are found |
| 13 | security default-keychain -s $KEY_CHAIN |
| 14 | |
| 15 | # Unlock the keychain |
| 16 | security unlock-keychain -p main $KEY_CHAIN |
| 17 | |
| 18 | security import $CERTIFICATE_P12 -k $KEY_CHAIN -P ${APPLE_CERT_P12_PASS} -T /usr/bin/codesign; |
| 19 | |
| 20 | security set-key-partition-list -S apple-tool:,apple: -s -k main $KEY_CHAIN |
| 21 | |
| 22 | # Remove cert file |
| 23 | rm -fr *.p12 |