-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·123 lines (106 loc) · 3.45 KB
/
install.sh
File metadata and controls
executable file
·123 lines (106 loc) · 3.45 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
#!/bin/sh
set -e
# Install script for tltv-cli
# Usage: curl -sSL https://raw.githubusercontent.com/tltv-org/cli/main/install.sh | sh
REPO="tltv-org/cli"
BINARY="tltv"
main() {
# Detect OS
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux) ;;
darwin) ;;
freebsd) ;;
mingw*|msys*|cygwin*)
echo "Error: This script does not support Windows."
echo "Download the .zip from https://github.com/${REPO}/releases/latest"
exit 1
;;
*) echo "Error: Unsupported OS: $OS"; exit 1 ;;
esac
# Detect architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "Error: Unsupported architecture: $ARCH"; exit 1 ;;
esac
# Get latest version tag from GitHub API
VERSION=$(curl -sS "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed 's/.*: "//;s/".*//')
if [ -z "$VERSION" ]; then
echo "Error: Failed to determine latest version"
exit 1
fi
# Pick install directory: use INSTALL_DIR if set, otherwise find a
# user-writable directory already in PATH. Fall back to ~/.local/bin.
if [ -n "$INSTALL_DIR" ]; then
: # user override, use as-is
else
INSTALL_DIR=""
for dir in "$HOME/.local/bin" "$HOME/bin" /usr/local/bin; do
case ":$PATH:" in
*":$dir:"*)
if [ -w "$dir" ] || [ ! -e "$dir" -a -w "$(dirname "$dir")" ]; then
INSTALL_DIR="$dir"
break
fi
;;
esac
done
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
fi
ARCHIVE="tltv-cli_${VERSION}_${OS}-${ARCH}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
echo "Installing ${BINARY} ${VERSION} (${OS}/${ARCH})..."
# Download and extract to temp dir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
if ! curl -sfL "$URL" | tar xz -C "$tmpdir" 2>/dev/null; then
echo "Error: Failed to download ${URL}"
echo "Check https://github.com/${REPO}/releases for available builds."
exit 1
fi
# Create install dir if needed
mkdir -p "$INSTALL_DIR"
# Install binary
mv "$tmpdir/$BINARY" "$INSTALL_DIR/$BINARY"
chmod +x "$INSTALL_DIR/$BINARY"
echo "Installed ${BINARY} ${VERSION} to ${INSTALL_DIR}/${BINARY}"
# Add to PATH if needed
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
# Use $HOME-relative path so the line is portable
case "$INSTALL_DIR" in
"$HOME"/*) PATH_EXPR="\$HOME${INSTALL_DIR#$HOME}" ;;
*) PATH_EXPR="$INSTALL_DIR" ;;
esac
LINE="export PATH=${PATH_EXPR}:\$PATH"
# Detect shell profile
PROFILE=""
if [ -n "$ZSH_VERSION" ] || [ "$(basename "$SHELL")" = "zsh" ]; then
PROFILE="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ] || [ "$(basename "$SHELL")" = "bash" ]; then
PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.profile" ]; then
PROFILE="$HOME/.profile"
fi
if [ -n "$PROFILE" ]; then
# Don't add if already present
if ! grep -qF "$INSTALL_DIR" "$PROFILE" 2>/dev/null; then
echo "" >> "$PROFILE"
echo "# tltv" >> "$PROFILE"
echo "$LINE" >> "$PROFILE"
echo "Added ${INSTALL_DIR} to PATH in ${PROFILE}"
echo "Restart your shell or run: source ${PROFILE}"
fi
else
echo ""
echo "NOTE: Could not detect shell profile."
echo "Add this to your shell config:"
echo " $LINE"
fi
;;
esac
}
main