Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·91 lines (71 loc) · 1.98 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·91 lines (71 loc) · 1.98 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
#!/usr/bin/env sh
set -eu
if (set -o pipefail) >/dev/null 2>&1; then
set -o pipefail
fi
REPO="${KIOX_REPO:-sourceplane/kiox}"
BIN_NAME="${KIOX_BIN_NAME:-kiox}"
INSTALL_DIR="${KIOX_INSTALL_DIR:-${HOME}/.local/bin}"
REQUESTED_VERSION="${KIOX_VERSION:-latest}"
need_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "error: required command not found: $1" >&2
exit 1
}
}
need_cmd curl
need_cmd tar
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$OS" in
darwin|linux) ;;
*)
echo "error: unsupported OS: $OS (supported: darwin, linux)" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*)
echo "error: unsupported architecture: $ARCH (supported: amd64, arm64)" >&2
exit 1
;;
esac
resolve_version() {
if [ "$REQUESTED_VERSION" != "latest" ]; then
echo "$REQUESTED_VERSION"
return
fi
api="https://api.github.com/repos/${REPO}/releases/latest"
tag="$(curl -fsSL "$api" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)"
if [ -z "$tag" ]; then
echo "error: could not resolve latest release tag from ${api}" >&2
exit 1
fi
echo "$tag"
}
VERSION="$(resolve_version)"
ASSET_VERSION="${VERSION#v}"
ARCHIVE="${BIN_NAME}_${ASSET_VERSION}_${OS}_${ARCH}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
TMP_DIR="$(mktemp -d)"
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
echo "Installing ${BIN_NAME} ${VERSION} for ${OS}/${ARCH}"
echo "Download: ${URL}"
curl -fL "$URL" -o "$TMP_DIR/$ARCHIVE"
tar -xzf "$TMP_DIR/$ARCHIVE" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then
echo "error: archive did not contain expected binary: ${BIN_NAME}" >&2
exit 1
fi
mkdir -p "$INSTALL_DIR"
install -m 0755 "$TMP_DIR/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
echo "Installed to: $INSTALL_DIR/$BIN_NAME"
if ! command -v "$BIN_NAME" >/dev/null 2>&1; then
echo "Note: add $INSTALL_DIR to your PATH"
fi
echo "Run: $BIN_NAME version"