-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·112 lines (97 loc) · 3.1 KB
/
install.sh
File metadata and controls
executable file
·112 lines (97 loc) · 3.1 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
#!/bin/sh
# tx installer — downloads the latest (or pinned) tx binary for your platform.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/jamesaphoenix/tx/main/install.sh | sh
#
# Environment variables:
# TX_VERSION Pin a specific version (e.g. "0.5.9"). Default: latest.
# TX_INSTALL_DIR Install location. Default: ~/.local/bin
set -e
REPO="jamesaphoenix/tx"
main() {
# -- Check prerequisites --
if ! command -v curl >/dev/null 2>&1; then
echo "Error: curl is required but not found. Install curl and try again." >&2
exit 1
fi
# -- Detect platform --
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin) ;;
linux) ;;
*)
echo "Error: unsupported OS '$OS'. tx binaries are available for macOS and Linux." >&2
exit 1
;;
esac
ARCH=$(uname -m)
case "$ARCH" in
arm64|aarch64) ARCH="arm64" ;;
x86_64|amd64) ARCH="x64" ;;
*)
echo "Error: unsupported architecture '$ARCH'. tx binaries are available for x64 and arm64." >&2
exit 1
;;
esac
# -- Resolve version --
if [ -n "$TX_VERSION" ]; then
VERSION="$TX_VERSION"
else
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| head -1 \
| sed 's/.*"tag_name": *"v\{0,1\}\([^"]*\)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: could not determine latest version from GitHub. Set TX_VERSION to install a specific version." >&2
exit 1
fi
fi
# -- Validate version looks like semver (digits and dots only) --
case "$VERSION" in
*[!0-9.]*)
echo "Error: version '$VERSION' contains invalid characters (expected digits and dots only)." >&2
exit 1
;;
[0-9]*.[0-9]*.[0-9]*) ;;
*)
echo "Error: extracted version '$VERSION' does not look like a valid version." >&2
exit 1
;;
esac
# -- Build download URL --
ARTIFACT="tx-${OS}-${ARCH}"
URL="https://github.com/${REPO}/releases/download/v${VERSION}/${ARTIFACT}"
# -- Install directory --
INSTALL_DIR="${TX_INSTALL_DIR:-$HOME/.local/bin}"
mkdir -p "$INSTALL_DIR"
# -- Download --
TMPFILE=$(mktemp)
trap 'rm -f "$TMPFILE"' EXIT INT TERM
echo "Downloading tx v${VERSION} (${OS}/${ARCH})..."
HTTP_CODE=$(curl -fSL -w '%{http_code}' -o "$TMPFILE" "$URL" 2>/dev/null) || true
if [ "$HTTP_CODE" != "200" ] || [ ! -s "$TMPFILE" ]; then
rm -f "$TMPFILE"
echo "Error: failed to download ${URL}" >&2
echo " HTTP status: ${HTTP_CODE}" >&2
echo " Check that v${VERSION} exists and has a ${ARTIFACT} binary at:" >&2
echo " https://github.com/${REPO}/releases/tag/v${VERSION}" >&2
exit 1
fi
# -- Install --
mv "$TMPFILE" "${INSTALL_DIR}/tx"
chmod +x "${INSTALL_DIR}/tx"
echo "Installed tx v${VERSION} to ${INSTALL_DIR}/tx"
# -- PATH check --
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Note: ${INSTALL_DIR} is not in your PATH."
echo "Add it by appending this line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
}
main