summaryrefslogtreecommitdiff
path: root/secrets/has.sh
blob: 6748754116e3b7581dd7ae94cf8015710f6f9432 (plain)
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
#!/bin/bash

set -euo pipefail

if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then
    cat <<EOF
has: Check, quietly, whether this machine can read a secret

Succeeds if <name> exists and this machine is one of its bucket's readers (in
the old store: if the old key is here). Decrypts nothing and prints nothing.

Usage:
  has <name>
  has <bucket>/<name>
  has -h|--help
EOF
    exit 0
fi

this_dir="$(cd "$(dirname "$0")" && pwd)"
szecret_quiet=1
source "${this_dir}/common.sh"

[[ "$#" -ge 1 ]] || exit 1

file="$(find_secret "$1" 2>/dev/null)" || exit 1

if [[ -n "${store}" && "$(dirname "${file}")" == "${store}" ]]; then
    [[ -n "${private_key}" && -r "${private_key}" ]]
else
    is_reader "$(dirname "${file}")"
fi