1#!/usr/bin/env bash
2
3
4function killperson {
5  OPTIND=1
6
7  while getopts 'h' opt; do
8    case "$opt" in
9      h) _show_manual_for 'killperson';;
10
11      *) _invalid_option_for 'killperson';;
12    esac
13  done
14
15  shift $((OPTIND-1))
16  [ "$1" = "--" ] && shift
17
18  _user_required
19
20  # Command logic:
21
22  local emails=( "$@" )
23
24  if [[ ${#emails[@]} -eq 0 ]]; then
25    _abort "at least one email is required for killperson."
26  fi
27  # Getting the local git-secret `gpg` key directory:
28  local secrets_dir_keys
29  secrets_dir_keys=$(_get_secrets_dir_keys)
30
31  _assert_keychain_contains_emails "$secrets_dir_keys" "${emails[@]}"
32
33  for email in "${emails[@]}"; do
34    $SECRETS_GPG_COMMAND --homedir "$secrets_dir_keys" --no-permission-warning --batch --yes --delete-key "$email"
35    local exit_code=$?
36    if [[ "$exit_code" -ne 0 ]]; then
37      _abort "problem deleting key for '$email' with gpg: exit code $exit_code"
38    fi
39  done
40
41  echo 'removed keys.'
42  echo "now [$*] do not have an access to the repository."
43  echo 'make sure to hide the existing secrets again.'
44}
45