-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
common.sh
143 lines (123 loc) · 3.11 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/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
}
_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 [ -n "${_GNUPGHOME+x}" ]; then
if [ -f "${_GNUPGHOME}/.helm-secrets" ]; then
# On CentOS 7, there is no kill option
case $(gpgconf --help 2>&1) in
*--kill*)
gpgconf --kill gpg-agent
;;
esac
fi
fi
rm -rf "${TMPDIR}"
}
# MacOS syntax and behavior is different for mktemp
# https://unix.stackexchange.com/a/555214
_mktemp() {
# ksh/posh - @: parameter not set
# https://stackoverflow.com/a/35242773
if [ $# -eq 0 ]; then
mktemp "${TMPDIR}/XXXXXX"
else
mktemp "$@" "${TMPDIR}/XXXXXX"
fi
}
_gpg_load_keys() {
_GNUPGHOME=$(_mktemp -d)
touch "${_GNUPGHOME}/.helm-secrets"
export GNUPGHOME="${_GNUPGHOME}"
for key in ${LOAD_GPG_KEYS}; do
if [ -d "${key}" ]; then
set +f
for file in "${key%%/}/"*; do
gpg --batch --no-permission-warning --quiet --import "${file}"
done
set -f
else
gpg --batch --no-permission-warning --quiet --import "${key}"
fi
done
}
on_wsl() { false; }
on_cygwin() { false; }
_sed_i() { sed -i "$@"; }
_winpath() { printf '%s' "${1}"; }
_helm_winpath() { printf '%s' "${1}"; }
case "$(uname -s)" in
CYGWIN* | MINGW64_NT*)
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 "$@"; }
_sed_i 's! - command: .*! - command: "scripts/wrapper/run.cmd downloader"!' "${HELM_PLUGIN_DIR}/plugin.yaml"
;;
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
}
# We are on a Linux VM, but helm.exe (Win32) is called
case "${HELM_BIN}" in
*.exe)
_helm_winpath() { _winpath "$@"; }
_sed_i 's! - command: .*! - command: "scripts/wrapper/run.cmd downloader"!' "${HELM_PLUGIN_DIR}/plugin.yaml"
;;
esac
fi
;;
esac