Last active
October 16, 2021 02:22
-
-
Save DanboDuan/720ed7f86cfe7621713ae711a6f0ac21 to your computer and use it in GitHub Desktop.
Keychain Script from https://stackoverflow.com/questions/10538942/add-a-keychain-to-search-list/44138621
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
uuid="$(uuidgen)" | |
echo "New Keychain name: $uuid" | |
keychains=$(security list-keychains -d user) | |
keychainNames=(); | |
for keychain in $keychains | |
do | |
basename=$(basename "$keychain") | |
keychainName=${basename::${#basename}-4} | |
keychainNames+=("$keychainName") | |
done | |
echo "User keychains on this machine: ${keychainNames[@]}"; | |
read -p "Enter to create keychain" | |
security -v create-keychain -p test123 $uuid | |
read -p "Enter to add keychain to searchlist" | |
security -v list-keychains -s "${keychainNames[@]}" $uuid | |
read -p "Enter to unlock keychain" | |
security -v unlock-keychain -p test123 $uuid | |
read -p "Enter to import certificate" | |
security -v import build-assets/certficate.p12 -k $uuid -P certificate_password | |
read -p "Enter to delete keychain" | |
security -v delete-keychain $uuid | |
### more | |
MY_KEYCHAIN="temp.keychain" | |
MY_KEYCHAIN_PASSWORD="secret" | |
CERT="certificate.p12" | |
CERT_PASSWORD="certificate secret" | |
security create-keychain -p "$MY_KEYCHAIN_PASSWORD" "$MY_KEYCHAIN" # Create temp keychain | |
security list-keychains -d user -s "$MY_KEYCHAIN" $(security list-keychains -d user | sed s/\"//g) # Append temp keychain to the user domain | |
security set-keychain-settings "$MY_KEYCHAIN" # Remove relock timeout | |
security unlock-keychain -p "$MY_KEYCHAIN_PASSWORD" "$MY_KEYCHAIN" # Unlock keychain | |
security import $CERT -k "$MY_KEYCHAIN" -P "$CERT_PASSWORD" -T "/usr/bin/codesign" # Add certificate to keychain | |
CERT_IDENTITY=$(security find-identity -v -p codesigning "$MY_KEYCHAIN" | head -1 | grep '"' | sed -e 's/[^"]*"//' -e 's/".*//') # Programmatically derive the identity | |
CERT_UUID=$(security find-identity -v -p codesigning "$MY_KEYCHAIN" | head -1 | grep '"' | awk '{print $2}') # Handy to have UUID (just in case) | |
security set-key-partition-list -S apple-tool:,apple: -s -k $MY_KEYCHAIN_PASSWORD -D "$CERT_IDENTITY" -t private $MY_KEYCHAIN # Enable codesigning from a non user interactive shell | |
### INSERT BUILD COMMANDS HERE ### | |
security delete-keychain "$MY_KEYCHAIN" # Delete temporary keychain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment