forked from jkroepke/helm-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
123 lines (105 loc) · 2.48 KB
/
common.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env sh
set -euf
is_help() {
case "$1" in
-h | --help | help)
true
;;
*)
false
;;
esac
}
log() {
if [ $# -le 1 ]; then
printf '[helm-secrets] %s\n' "${1:-}" >&2
else
format="${1}"
shift
# shellcheck disable=SC2059
printf "[helm-secrets] $format\n" "$@" >&2
fi
}
error() {
log "$@"
}
fatal() {
error "$@"
exit 1
}
load_secret_backend() {
backend="${1}"
if [ -f "${SCRIPT_DIR}/backends/${backend}.sh" ]; then
# shellcheck source=scripts/backends/sops.sh
. "${SCRIPT_DIR}/backends/${backend}.sh"
else
# Allow to load out of tree backends.
if [ ! -f "${backend}" ]; then
fatal "Can't find secret backend: %s" "${backend}"
fi
# shellcheck disable=SC2034
HELM_SECRETS_SCRIPT_DIR="${SCRIPT_DIR}"
# shellcheck source=tests/assets/custom-backend.sh
. "${backend}"
fi
}
_regex_escape() {
# This is a function because dealing with quotes is a pain.
# http://stackoverflow.com/a/2705678/120999
sed -e 's/[]\/()$*.^|[]/\\&/g'
}
_trap() {
if command -v _trap_hook >/dev/null; then
_trap_hook
fi
if command -v _trap_kill_gpg_agent >/dev/null; then
_trap_kill_gpg_agent
fi
rm -rf "${TMPDIR}"
}
# MacOS syntax and behavior is different for mktemp
# https://unix.stackexchange.com/a/555214
_mktemp() {
mktemp "$@" "${TMPDIR}/XXXXXX"
}
on_wsl() { false; }
on_cygwin() { false; }
_sed_i() { sed -i "$@"; }
_winpath() { printf '%s' "${1}"; }
_helm_winpath() { printf '%s' "${1}"; }
case "$(uname -s)" in
CYGWIN*)
on_cygwin() { true; }
_winpath() {
if [ "${2:-0}" = "1" ]; then
printf '%s' "${1}" | cygpath -w -l -f - | sed -e 's!\\!\\\\!g'
else
printf '%s' "${1}" | cygpath -w -l -f -
fi
}
_helm_winpath() { _winpath "$@"; }
;;
Darwin)
case $(sed --help 2>&1) in
*BusyBox* | *GNU*) ;;
*) _sed_i() { sed -i '' "$@"; } ;;
esac
;;
*)
# Check of WSL
if [ -f /proc/version ] && grep -qi microsoft /proc/version; then
on_wsl() { true; }
_winpath() {
touch "${1}"
if [ "${2:-0}" = "1" ]; then
wslpath -w "${1}" | sed -e 's!\\!\\\\!g'
else
wslpath -w "${1}"
fi
}
case "${HELM_BIN}" in
*.exe) _helm_winpath() { _winpath "$@"; } ;;
esac
fi
;;
esac