-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·107 lines (92 loc) · 2.8 KB
/
install.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
#!/bin/sh
set -e
set -o errexit
usage() {
this=$1
cat <<EOF
$this: download binaries for sopstool
Usage: $this [-b bindir] [-o OS] [-a ARCH] [-s SOPS_VERSION] [-t SOPSTOOL_VERSION] [-d] [bindir]
-b sets bindir or installation directory, Defaults to ./bin
-o target OS (windows, linux, darwin) - uses uname by default
-a target architecture (amd64, arm64) - uses uname by default
-s SOPS_VERSION tag to download
-t SOPSTOOL_VERSION tag to download
-f force download to the binary directory even if command exists
-d turns on debug logging
SOPS_VERSION overrides the sops version tag downloaded
SOPSTOOL_VERSION overrides the sopstool version tag downloaded
[bindir] arg sets the installation directory
Flags are passed to the installers (-a, -o, -d)
EOF
exit 2
}
parse_args() {
BINDIR="${BINDIR:-./bin}"
while getopts "b:o:a:s:t:dfxh?" arg; do
case "${arg}" in
x) TARGET_X=1 && set -x ;;
b) BINDIR="${OPTARG}" ;;
o) TARGET_OS="${OPTARG}" ;;
a) TARGET_ARCH="${OPTARG}" ;;
s) SOPS_VERSION="${OPTARG}" ;;
t) SOPSTOOL_VERSION="${OPTARG}" ;;
f) FORCE=1 ;;
d) TARGET_DEBUG=1 ;;
h | \? | *) usage "$0" ;;
esac
done
shift $((OPTIND - 1))
BINDIR=${1:-${BINDIR}}
}
execute() {
if [ -n "${TARGET_ARCH}" ]; then
set -- "$@" "-a" "${TARGET_ARCH}"
fi
if [ -n "${TARGET_OS}" ]; then
set -- "$@" "-o" "${TARGET_OS}"
fi
if [ -n "${TARGET_DEBUG}" ]; then
set -- "$@" "-d"
fi
if [ -n "${TARGET_X}" ]; then
set -- "$@" "-x"
fi
if [ -n "${FORCE}" ] || ! is_command sops; then
http_exec https://raw.githubusercontent.com/Ibotta/sopstool/main/sopsinstall.sh -b "${BINDIR}" "$@" "${SOPS_VERSION}"
fi
http_exec https://raw.githubusercontent.com/Ibotta/sopstool/main/sopstoolinstall.sh -b "${BINDIR}" "$@" "${SOPSTOOL_VERSION}"
echo "Both sops and sopstool installed"
}
http_exec() {
url="$1"
shift
if is_command curl; then
cmd='curl --fail -sSL'
elif is_command wget; then
cmd='wget -qO-'
else
echo "http_exec: unable to find wget or curl"
return 1
fi
$cmd "$url" | $SHELL -s -- "$@"
}
cat /dev/null <<EOF
------------------------------------------------------------------------
https://github.com/client9/shlib - portable posix shell functions
Public domain - http://unlicense.org
https://github.com/client9/shlib/blob/master/LICENSE.md
but credit (and pull requests) appreciated.
------------------------------------------------------------------------
EOF
is_command() {
command -v "$1" >/dev/null
}
cat /dev/null <<EOF
------------------------------------------------------------------------
End of functions from https://github.com/client9/shlib
------------------------------------------------------------------------
EOF
# parse_args, show usage and exit if necessary
parse_args "$@"
# do it
execute