-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·195 lines (159 loc) · 6.07 KB
/
install.sh
File metadata and controls
executable file
·195 lines (159 loc) · 6.07 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
#
# Switchboard CLI installer
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/liberuum/switchboard-cli/main/install.sh | bash
#
# Environment variables:
# INSTALL_DIR — where to place the binary (default: /usr/local/bin)
# VERSION — specific version to install (default: latest for the channel)
# CHANNEL — "staging" or "stable" (default: stable)
set -euo pipefail
REPO="liberuum/switchboard-cli"
BINARY_NAME="switchboard"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
TMPDIR_CLEANUP=""
cleanup() { [ -n "$TMPDIR_CLEANUP" ] && rm -rf "$TMPDIR_CLEANUP"; }
trap cleanup EXIT
# --- helpers ----------------------------------------------------------------
info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
ok() { printf '\033[1;32m ✓\033[0m %s\n' "$*"; }
err() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
need_cmd() {
command -v "$1" > /dev/null 2>&1 || err "Required command not found: $1"
}
# --- detect platform --------------------------------------------------------
detect_platform() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
*) err "Unsupported OS: $os (only Linux and macOS are supported)" ;;
esac
case "$arch" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) err "Unsupported architecture: $arch" ;;
esac
echo "${os}-${arch}"
}
# --- resolve version --------------------------------------------------------
resolve_version() {
if [ -n "${VERSION:-}" ]; then
echo "$VERSION"
return
fi
need_cmd curl
local channel="${CHANNEL:-stable}"
local latest
if [ "$channel" = "staging" ]; then
# Staging: find the latest v0.0.0-staging.* prerelease tag
# Use grep -o to extract each tag_name onto its own line (API may return single-line JSON)
latest="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases" \
| grep -oE '"tag_name": *"[^"]+"' \
| grep 'staging' \
| head -1 \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')"
else
# Stable: use the /releases/latest endpoint (excludes prereleases)
latest="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep -oE '"tag_name": *"[^"]+"' \
| head -1 \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')"
fi
[ -n "$latest" ] || err "Could not determine latest ${channel} version. Set VERSION= explicitly."
echo "$latest"
}
# --- download and install ---------------------------------------------------
install() {
need_cmd curl
need_cmd tar
local platform version archive_name url tmpdir
platform="$(detect_platform)"
version="$(resolve_version)"
archive_name="${BINARY_NAME}-${version}-${platform}.tar.gz"
url="https://github.com/${REPO}/releases/download/${version}/${archive_name}"
info "Installing ${BINARY_NAME} ${version} (${platform})"
tmpdir="$(mktemp -d)"
TMPDIR_CLEANUP="$tmpdir"
info "Downloading ${url}"
curl -fsSL "$url" -o "${tmpdir}/${archive_name}" \
|| err "Download failed. Check that version '${version}' exists and has a release for ${platform}."
info "Extracting archive"
tar -xzf "${tmpdir}/${archive_name}" -C "$tmpdir"
# The archive should contain the binary at the top level
if [ ! -f "${tmpdir}/${BINARY_NAME}" ]; then
# Try to find it nested
local found
found="$(find "$tmpdir" -name "$BINARY_NAME" -type f | head -1)"
[ -n "$found" ] || err "Binary '${BINARY_NAME}' not found in archive"
mv "$found" "${tmpdir}/${BINARY_NAME}"
fi
# macOS: remove quarantine flag so Gatekeeper doesn't block the binary
if [ "$(uname -s)" = "Darwin" ]; then
xattr -d com.apple.quarantine "${tmpdir}/${BINARY_NAME}" 2>/dev/null || true
fi
info "Installing to ${INSTALL_DIR}/${BINARY_NAME}"
if [ -w "$INSTALL_DIR" ]; then
mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
else
sudo mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
fi
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
ok "Installed ${BINARY_NAME} ${version} to ${INSTALL_DIR}/${BINARY_NAME}"
# Check if INSTALL_DIR is in PATH
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
info "${INSTALL_DIR} is not in your PATH. Add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
# --- setup shell completions -----------------------------------------------
info "Setting up shell completions"
"${INSTALL_DIR}/${BINARY_NAME}" completions --install 2>/dev/null || true
# --- welcome message -------------------------------------------------------
echo ""
echo ""
printf '\033[1;36m'
cat << 'BANNER'
____ _ _ _ _ _
/ ___|_ _(_) |_ ___| |__ | |__ ___ __ _ _ __ __| |
\___ \ \ /\ / / | __/ __| '_ \| '_ \ / _ \ / _` | '__/ _` |
___) \ V V /| | || (__| | | | |_) | (_) | (_| | | | (_| |
|____/ \_/\_/ |_|\__\___|_| |_|_.__/ \___/ \__,_|_| \__,_|
BANNER
printf '\033[0m'
printf '\033[1m CLI %s\033[0m\n' "${version}"
echo ""
printf '\033[0;37m Welcome to the Switchboard CLI! You can now interact with any\n'
printf ' Switchboard instance straight from your terminal — manage drives,\n'
printf ' documents, permissions, and more.\033[0m\n'
echo ""
printf '\033[1;34m Get started:\033[0m\n'
echo ""
printf ' 1. Connect to an instance:\n'
echo ""
printf '\033[1;33m $ switchboard init\033[0m\n'
echo ""
printf ' You will be prompted for a GraphQL URL, for example:\n'
printf '\033[0;37m https://switchboard.powerhouse.xyz/graphql\033[0m\n'
echo ""
printf ' 2. Explore your data:\n'
echo ""
printf '\033[1;33m $ switchboard drives list\033[0m\n'
printf '\033[1;33m $ switchboard docs tree --drive <slug>\033[0m\n'
printf '\033[1;33m $ switchboard models list\033[0m\n'
echo ""
printf ' 3. Launch interactive mode:\n'
echo ""
printf '\033[1;33m $ switchboard -i\033[0m\n'
echo ""
printf '\033[0;37m Run \033[1mswitchboard guide overview\033[0;37m for a full walkthrough.\033[0m\n'
echo ""
}
install