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