-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·117 lines (101 loc) · 2.71 KB
/
install.sh
File metadata and controls
executable file
·117 lines (101 loc) · 2.71 KB
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
#!/bin/sh
set -eu
REPO="${CERTBRO_REPO:-regfish/certbro}"
VERSION="${CERTBRO_VERSION:-latest}"
INSTALL_DIR="${CERTBRO_INSTALL_DIR:-/usr/local/bin}"
BIN_NAME="certbro"
detect_os() {
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$os" in
linux|darwin) printf '%s\n' "$os" ;;
*)
echo "unsupported operating system: $os" >&2
exit 1
;;
esac
}
detect_arch() {
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) printf 'amd64\n' ;;
arm64|aarch64) printf 'arm64\n' ;;
*)
echo "unsupported architecture: $arch" >&2
exit 1
;;
esac
}
sha256_file() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1" | awk '{print $1}'
return
fi
if command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$1" | awk '{print $1}'
return
fi
echo "missing sha256 tool (need sha256sum or shasum)" >&2
exit 1
}
download() {
url="$1"
out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$out"
return
fi
if command -v wget >/dev/null 2>&1; then
wget -qO "$out" "$url"
return
fi
echo "missing downloader (need curl or wget)" >&2
exit 1
}
os="$(detect_os)"
arch="$(detect_arch)"
archive="${BIN_NAME}_${os}_${arch}.tar.gz"
checksums="checksums.txt"
if [ "$VERSION" = "latest" ]; then
base_url="https://github.com/${REPO}/releases/latest/download"
else
base_url="https://github.com/${REPO}/releases/download/${VERSION}"
fi
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT INT TERM
download "${base_url}/${archive}" "${tmpdir}/${archive}"
download "${base_url}/${checksums}" "${tmpdir}/${checksums}"
expected="$(awk -v file="$archive" '$2 == file { print $1 }' "${tmpdir}/${checksums}")"
if [ -z "$expected" ]; then
echo "checksum entry for ${archive} not found" >&2
exit 1
fi
actual="$(sha256_file "${tmpdir}/${archive}")"
if [ "$expected" != "$actual" ]; then
echo "checksum mismatch for ${archive}" >&2
exit 1
fi
tar -xzf "${tmpdir}/${archive}" -C "${tmpdir}"
if [ ! -f "${tmpdir}/${BIN_NAME}" ]; then
echo "archive did not contain ${BIN_NAME}" >&2
exit 1
fi
if [ -d "${INSTALL_DIR}" ]; then
:
elif [ -w "$(dirname "${INSTALL_DIR}")" ]; then
mkdir -p "${INSTALL_DIR}"
elif command -v sudo >/dev/null 2>&1; then
sudo mkdir -p "${INSTALL_DIR}"
else
echo "cannot create install directory ${INSTALL_DIR}" >&2
exit 1
fi
if [ -w "${INSTALL_DIR}" ]; then
install -m 0755 "${tmpdir}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"
else
if ! command -v sudo >/dev/null 2>&1; then
echo "install directory is not writable and sudo is unavailable: ${INSTALL_DIR}" >&2
exit 1
fi
sudo install -m 0755 "${tmpdir}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"
fi
echo "installed ${BIN_NAME} to ${INSTALL_DIR}/${BIN_NAME}"