Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·150 lines (128 loc) · 4.92 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·150 lines (128 loc) · 4.92 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
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
144
145
146
147
148
149
150
#!/bin/sh
# Install the slackwater CLI.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/openwatersio/slackwater/main/install.sh | sh
#
# Environment variables:
# SLACKWATER_VERSION - version to install, e.g. 1.0.0-beta.1 (default: the newest
# stable release, or the newest beta when none is stable)
# SLACKWATER_INSTALL_DIR - installation directory (default: /usr/local/bin)
set -e
REPO="openwatersio/slackwater"
INSTALL_DIR="${SLACKWATER_INSTALL_DIR:-/usr/local/bin}"
# Detect OS
OS="$(uname -s)"
case "$OS" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) echo "Error: unsupported OS: $OS" >&2; exit 1 ;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) arch="x64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "Error: unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
TARGET="${os}-${arch}"
# Only linux-x64 and darwin-arm64 binaries are available
if [ "$TARGET" != "linux-x64" ] && [ "$TARGET" != "darwin-arm64" ]; then
echo "Error: no pre-built binary for ${TARGET}." >&2
echo "Install via npm instead: npm install -g @slackwater/cli" >&2
exit 1
fi
# Resolve the release tag. Every package in the repo gets its own GitHub release,
# and only @slackwater/cli releases carry binaries, so releases/latest can't be used.
# Takes the newest stable CLI release, or the newest prerelease when none is stable.
TAG_PREFIX="@slackwater/cli@"
if [ -n "$SLACKWATER_VERSION" ]; then
case "$SLACKWATER_VERSION" in
"$TAG_PREFIX"*) TAG="$SLACKWATER_VERSION" ;;
*) TAG="${TAG_PREFIX}${SLACKWATER_VERSION#v}" ;;
esac
else
TAG=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases?per_page=100" \
| awk -F'"' -v prefix="$TAG_PREFIX" '
$2 == "tag_name" { tag = $4 }
$2 == "draft" { draft = ($3 ~ /true/) }
$2 == "prerelease" && !draft && index(tag, prefix) == 1 {
if ($3 ~ /false/ && stable == "") stable = tag
if (newest == "") newest = tag
}
END { print (stable != "" ? stable : newest) }')
fi
if [ -z "$TAG" ]; then
echo "Error: could not find a slackwater CLI release." >&2
exit 1
fi
ARCHIVE="slackwater-${TARGET}.tar.gz"
BASE_URL="https://github.com/${REPO}/releases/download/${TAG}"
echo "Installing slackwater ${TAG#"$TAG_PREFIX"} (${TARGET})..."
# Download archive and checksums
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
curl -fsSL "${BASE_URL}/${ARCHIVE}" -o "${TMPDIR}/${ARCHIVE}"
curl -fsSL "${BASE_URL}/checksums.txt" -o "${TMPDIR}/checksums.txt"
# Verify checksum
EXPECTED=$(grep "${ARCHIVE}" "${TMPDIR}/checksums.txt" | cut -d' ' -f1)
if [ -z "$EXPECTED" ]; then
echo "Error: no checksum found for ${ARCHIVE}" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "${TMPDIR}/${ARCHIVE}" | cut -d' ' -f1)
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "${TMPDIR}/${ARCHIVE}" | cut -d' ' -f1)
else
echo "Error: no sha256sum or shasum command found" >&2
exit 1
fi
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "Error: checksum verification failed" >&2
echo " expected: ${EXPECTED}" >&2
echo " got: ${ACTUAL}" >&2
exit 1
fi
# Extract
tar xzf "${TMPDIR}/${ARCHIVE}" -C "$TMPDIR"
# Run the binary before installing it, so a missing system library fails here
# with instructions instead of on first use
if ! "${TMPDIR}/slackwater" --version >/dev/null 2>"${TMPDIR}/run.log"; then
echo "Error: the downloaded slackwater binary does not run on this system:" >&2
sed 's/^/ /' "${TMPDIR}/run.log" >&2
if [ "$os" = "linux" ] && grep -q "shared libraries" "${TMPDIR}/run.log"; then
echo "The Linux binary needs libstdc++ and libatomic. On Debian or Ubuntu:" >&2
echo " sudo apt-get install libstdc++6 libatomic1" >&2
echo "Or install with npm, which runs on your existing Node: npm install -g @slackwater/cli" >&2
fi
exit 1
fi
# Install
if [ -w "$INSTALL_DIR" ]; then
SUDO=""
else
echo "Writing to ${INSTALL_DIR} requires elevated permissions."
SUDO="sudo"
fi
$SUDO mv "${TMPDIR}/slackwater" "${INSTALL_DIR}/slackwater"
$SUDO chmod +x "${INSTALL_DIR}/slackwater"
echo "Installed slackwater to ${INSTALL_DIR}/slackwater"
# The binary embeds the station database, whose attribution terms are in NOTICE
if [ -f "${TMPDIR}/NOTICE" ]; then
RELEASE_URL="https://github.com/${REPO}/releases/tag/${TAG}"
case "$INSTALL_DIR" in
/bin | /bin/ | /*/bin | /*/bin/)
PREFIX="$(dirname "$INSTALL_DIR")"
DOC_DIR="${PREFIX%/}/share/doc/slackwater"
if $SUDO mkdir -p "$DOC_DIR" 2>/dev/null && $SUDO cp "${TMPDIR}/LICENSE" "${TMPDIR}/NOTICE" "$DOC_DIR/"; then
echo "Installed license and data attribution to ${DOC_DIR}"
else
echo "Could not write to ${DOC_DIR}; LICENSE and NOTICE are in the ${ARCHIVE} download at ${RELEASE_URL}" >&2
fi
;;
*)
echo "LICENSE and NOTICE (data attribution) are in the ${ARCHIVE} download at ${RELEASE_URL}"
;;
esac
fi