forked from sympozium-ai/sympozium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·162 lines (133 loc) · 4.65 KB
/
install.sh
File metadata and controls
executable file
·162 lines (133 loc) · 4.65 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
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
# sympozium installer
# Usage: curl -fsSL https://deploy.sympozium.ai/install.sh | sh
# curl -fsSL https://deploy.sympozium.ai/install.sh | sh -s -- --local # Install to ~/.local/bin (no sudo)
#
# Downloads the latest sympozium CLI release from GitHub and installs
# the binary to /usr/local/bin (or ~/.local/bin with --local or if no sudo).
set -e
REPO="AlexsJones/sympozium"
BINARY="sympozium"
LOCAL_INSTALL=""
# --- helpers ---
info() { printf ' \033[1;34m>\033[0m %s\n' "$*"; }
warn() { printf ' \033[1;33m>\033[0m %s\n' "$*"; }
err() { printf ' \033[1;31m!\033[0m %s\n' "$*" >&2; exit 1; }
need() {
command -v "$1" >/dev/null 2>&1 \
|| err "Required tool '$1' not found. Please install it and try again."
}
# --- parse arguments ---
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--local|-l)
LOCAL_INSTALL="1"
;;
--help|-h)
echo "Usage: install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --local, -l Install to ~/.local/bin (no sudo required)"
echo " --help, -h Show this help message"
exit 0
;;
*)
warn "Unknown option: $1"
;;
esac
shift
done
}
# --- detect platform ---
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*) err "Unsupported OS: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) err "Unsupported architecture: $ARCH" ;;
esac
PLATFORM="${OS}-${ARCH}"
}
# --- fetch latest release ---
fetch_latest_tag() {
need curl
need tar
# Use the releases redirect instead of the API to avoid
# GitHub's 60-request/hour rate limit on unauthenticated API calls.
TAG="$(curl -fsSI "https://github.com/${REPO}/releases/latest" 2>/dev/null \
| grep -i '^location:' \
| head -1 \
| sed 's|.*/tag/||' \
| tr -d '\r\n')"
[ -n "$TAG" ] || err "Could not determine latest release. Check https://github.com/${REPO}/releases"
}
# --- download and install ---
install() {
ASSET="${BINARY}-${PLATFORM}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${TAG}/${ASSET}"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
info "Downloading ${BINARY} ${TAG} for ${PLATFORM}..."
curl -fsSL "$URL" -o "${TMPDIR}/${ASSET}" \
|| err "Download failed. Asset '${ASSET}' may not exist for your platform.\n Check: https://github.com/${REPO}/releases/tag/${TAG}"
info "Extracting..."
tar -xzf "${TMPDIR}/${ASSET}" -C "$TMPDIR"
BIN="$(find "$TMPDIR" -name "$BINARY" -type f | head -1)"
[ -n "$BIN" ] || err "Binary not found in archive. Release asset may have an unexpected layout."
chmod +x "$BIN"
# Determine install directory
if [ -n "$LOCAL_INSTALL" ]; then
# User explicitly requested local install
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
info "Installing to ${INSTALL_DIR} (--local mode)..."
elif [ -w /usr/local/bin ]; then
# /usr/local/bin is writable without sudo
INSTALL_DIR="/usr/local/bin"
elif command -v sudo >/dev/null 2>&1 && [ -t 0 ]; then
# sudo is available and we're in an interactive terminal
info "Installing to /usr/local/bin (requires sudo)..."
if sudo mv "$BIN" "/usr/local/bin/${BINARY}"; then
info "Installed ${BINARY} to /usr/local/bin/${BINARY}"
return
else
warn "sudo failed, falling back to ~/.local/bin"
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
else
# No write access and no interactive sudo, use local install
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
info "Installing to ${INSTALL_DIR} (no sudo available)..."
fi
mv "$BIN" "${INSTALL_DIR}/${BINARY}"
info "Installed ${BINARY} to ${INSTALL_DIR}/${BINARY}"
# Check if install dir is in PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
warn "Add ${INSTALL_DIR} to your PATH to use '${BINARY}' directly:"
echo ""
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
;;
esac
}
# --- main ---
main() {
parse_args "$@"
info "sympozium installer"
detect_platform
fetch_latest_tag
install
info "Done! Run 'sympozium install' to deploy Sympozium to your cluster."
}
main "$@"