github.com/StackExchange/blackbox/v2@v2.0.1-0.20220331193400-d84e904973ab/bin/blackbox_addadmin (about) 1 #!/usr/bin/env bash 2 3 # 4 # blackbox_addadmin -- Add an admin to the system 5 # 6 7 # Example: 8 # blackbox_addadmin tal@example.com 9 # 10 11 set -e 12 source "${0%/*}/_blackbox_common.sh" 13 14 fail_if_not_in_repo 15 16 KEYNAME="$1" 17 : "${KEYNAME:?ERROR: First argument must be a keyname (email address)}" ; 18 19 # Add the email address to the BB_ADMINS file. Remove any duplicates. 20 # The file must exist for sort to act as we expect. 21 touch "$BB_ADMINS" 22 echo "$1" >> "$BB_ADMINS" 23 sort -fdu -o "$BB_ADMINS" "$BB_ADMINS" 24 25 26 # Add the user's key to the keychain. 27 28 # Extract it: 29 make_self_deleting_tempfile pubkeyfile 30 31 # The second argument, if present, is the directory to find the GPG keys to be imported. 32 if [[ -z $2 ]]; then 33 $GPG --export -a "$KEYNAME" >"$pubkeyfile" 34 else 35 # TODO(tlim): This could probably be done with GNUPGHOME 36 # but that affects all commands; we just want it to affect the key export. 37 $GPG --homedir="$2" --export -a "$KEYNAME" >"$pubkeyfile" 38 fi 39 40 if [[ $(wc -l < "$pubkeyfile") = 0 ]]; then 41 fail_out "GPG key '$KEYNAME' not found. Please create it with: $GPG --gen-key" 42 exit 1 43 fi 44 45 # Import it: 46 $GPG --no-permission-warning --homedir="$KEYRINGDIR" --import "$pubkeyfile" 47 pubring_path=$(get_pubring_path) 48 vcs_add "$pubring_path" "$KEYRINGDIR/trustdb.gpg" "$BB_ADMINS" 49 50 # Make a suggestion: 51 echo 52 echo 53 echo 'NEXT STEP: You need to manually check these in:' 54 echo ' ' $VCS_TYPE commit -m\'NEW ADMIN: $KEYNAME\' "$BLACKBOXDATA/$(basename ${pubring_path})" "$BLACKBOXDATA/trustdb.gpg" "$BLACKBOXDATA/$BB_ADMINS_FILE"