Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / scripts / select-identity.sh

select-identity.sh31 lines · 1.0 KiBRaw
1#!/bin/bash
2
3# we can't simply extract the portion in brackets because some times the Organizational Unit is different from that
4# so extract that info from the certificate
5function get_team {
6 security find-certificate -pc "$1" | openssl x509 -noout -subject | grep -o 'OU=[A-Z0-9]*' | cut -d= -f2
7}
8
9IFS=$'\n' names=($(security find-identity -vp codesigning | grep -E '(?:iPhone Developer|Apple Development):' | cut -d'"' -f2 | uniq))
10if [[ "${#names[@]}" -eq 1 ]]; then
11 identity="${names[0]}"
12else
13 echo "Select identity" >&2
14 for i in "${!names[@]}"; do
15 cur_identity="${names[$i]}"
16 cur_team="$(get_team "$cur_identity")"
17 printf "%s. %s '%s'\n" $((i + 1)) "$cur_team" "$cur_identity" >&2
18 done
19 # ask for choice until the user supplies a valid answer
20 function select_identity {
21 read -p "Choice (enter number): " identity_idx >&2
22 if [[ "$identity_idx" -lt 1 || "$identity_idx" -gt "${#names[@]}" ]]; then
23 select_identity
24 else
25 identity="${names[$((identity_idx - 1))]}"
26 fi
27 }
28 select_identity
29fi
30
31get_team "$identity"