-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·378 lines (317 loc) · 9.73 KB
/
install.sh
File metadata and controls
executable file
·378 lines (317 loc) · 9.73 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/sh
# rig installer
# Usage: curl -fsSL https://raw.githubusercontent.com/roelentless/rig/develop/install.sh | sh
#
# Downloads a prebuilt binary from GitHub Releases.
# Checks prerequisites, shows the install plan, asks before running.
# Safe to re-run for upgrades. Pass -y to skip the prompt.
REPO="roelentless/rig"
REPO_URL="https://github.com/${REPO}"
# --- Colors (only when terminal) ---
if [ -t 1 ]; then
BOLD='\033[1m'
DIM='\033[2m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
CYAN='\033[36m'
RESET='\033[0m'
else
BOLD='' DIM='' RED='' GREEN='' YELLOW='' CYAN='' RESET=''
fi
ok() { printf " ${GREEN}✓${RESET} %s\n" "$1"; }
miss() { printf " ${RED}✗${RESET} %-28s %s\n" "$1" "$2"; }
skip() { printf " ${DIM}- %-28s %s${RESET}\n" "$1" "$2"; }
info() { printf " ${CYAN}→${RESET} %s\n" "$1"; }
warn() { printf " ${YELLOW}!${RESET} %s\n" "$1"; }
err() { printf " ${RED}✗${RESET} %s\n" "$1" >&2; }
has() { command -v "$1" >/dev/null 2>&1; }
# curl is required to fetch releases - abort immediately if missing
if ! has curl; then
printf " curl is required but not installed.\n" >&2
exit 1
fi
# Prompt Y/n - reads from /dev/tty when stdin is a pipe
prompt_yn() {
if [ "${AUTO_YES}" = true ]; then return 0; fi
if [ -t 0 ]; then
printf "%s" "$1"
read -r answer
elif [ -e /dev/tty ]; then
printf "%s" "$1"
read -r answer < /dev/tty
else
return 0
fi
case "$answer" in
n|N|no|No) return 1 ;;
*) return 0 ;;
esac
}
# ============================================================================
# Platform detection
# ============================================================================
detect_platform() {
OS=$(uname -s)
ARCH=$(uname -m)
case "$OS" in
Darwin) PLATFORM="macos" ;;
Linux) PLATFORM="linux" ;;
*)
err "Unsupported OS: $OS"
err "rig supports macOS and Linux."
err "See: ${REPO_URL}#install"
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64) ARCH_LABEL="amd64" ;;
arm64|aarch64) ARCH_LABEL="arm64" ;;
*)
err "Unsupported architecture: $ARCH"
err "See: ${REPO_URL}#install"
exit 1
;;
esac
}
# ============================================================================
# Install location
# ============================================================================
install_dir() {
case "$PLATFORM" in
linux) echo "$HOME/.local/bin" ;;
macos) echo "/usr/local/bin" ;;
esac
}
# ============================================================================
# Version check
# ============================================================================
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/'
}
get_installed_version() {
if has rig; then
rig version 2>/dev/null | head -1 | sed 's/[^0-9.]*//'
fi
}
# ============================================================================
# Dependency check
# ============================================================================
check_deps() {
HAS_TMUX=false; HAS_WATCHEXEC=false; HAS_RIG=false
has tmux && HAS_TMUX=true
has watchexec && HAS_WATCHEXEC=true
has rig && HAS_RIG=true
}
show_status() {
printf "\n Checking dependencies...\n\n"
if $HAS_TMUX; then
ok "$(tmux -V 2>/dev/null || echo tmux)"
else
miss "tmux" "(required) terminal multiplexer"
fi
if $HAS_WATCHEXEC; then
ok "watchexec"
else
skip "watchexec" "(optional) file watcher for auto-restart"
fi
}
# ============================================================================
# watchexec install
# ============================================================================
WE_REPO="watchexec/watchexec"
install_watchexec() {
# macOS: prefer brew when available
if [ "$PLATFORM" = "macos" ] && has brew; then
info "Installing watchexec via Homebrew..."
if brew install watchexec; then
ok "watchexec installed via Homebrew"
return 0
else
warn "brew install failed, falling back to webi..."
fi
fi
info "Installing watchexec via webi..."
if curl -fsSL https://webi.sh/watchexec | sh >/dev/null 2>&1; then
ok "watchexec installed"
else
err "watchexec install failed."
err "Install manually: https://github.com/${WE_REPO}/releases"
return 1
fi
}
maybe_install_watchexec() {
if $HAS_WATCHEXEC; then return; fi
echo ""
if [ "$INSTALL_WATCHEXEC" = true ]; then
install_watchexec
elif [ "$AUTO_YES" != true ]; then
if prompt_yn " Install watchexec? (optional, enables file watching) [Y/n] "; then
install_watchexec
else
info "Skipped. Install later:"
if [ "$PLATFORM" = "macos" ] && has brew; then
info " brew install watchexec"
else
info " https://github.com/${WE_REPO}/releases"
fi
fi
fi
}
# ============================================================================
# Install
# ============================================================================
install_rig() {
DEST_DIR=$(install_dir)
DEST="$DEST_DIR/rig"
LATEST=$(get_latest_version)
if [ -z "$LATEST" ]; then
err "Could not determine latest version from GitHub."
err "Check your network connection or visit: ${REPO_URL}/releases"
exit 1
fi
# Version check - skip if already up to date
if $HAS_RIG; then
CURRENT=$(get_installed_version)
if [ "$CURRENT" = "$LATEST" ]; then
printf "\n"
ok "rig ${CURRENT} is already up to date"
maybe_install_watchexec
printf "\n"
exit 0
fi
info "Upgrading rig ${CURRENT} → ${LATEST}"
else
info "Installing rig ${LATEST}"
fi
TARBALL="rig-${PLATFORM}-${ARCH_LABEL}.tar.gz"
URL="${REPO_URL}/releases/download/${LATEST}/${TARBALL}"
info "Downloading ${URL}"
TMP_DIR=$(mktemp -d)
TMP_TAR="$TMP_DIR/$TARBALL"
if ! curl -fsSL -o "$TMP_TAR" "$URL"; then
rm -rf "$TMP_DIR"
err "Download failed: ${URL}"
err "Check if a release exists for your platform: ${REPO_URL}/releases"
exit 1
fi
tar xzf "$TMP_TAR" -C "$TMP_DIR"
# Ensure destination directory exists
mkdir -p "$DEST_DIR"
# Install binary (may need elevated privileges on macOS /usr/local/bin)
if [ -w "$DEST_DIR" ] || [ -w "$DEST" ] 2>/dev/null; then
mv "$TMP_DIR/rig" "$DEST"
chmod +x "$DEST"
elif has sudo; then
sudo mv "$TMP_DIR/rig" "$DEST"
sudo chmod +x "$DEST"
else
err "Cannot write to ${DEST_DIR}. Run as root or install sudo."
rm -rf "$TMP_DIR"
exit 1
fi
rm -rf "$TMP_DIR"
ok "rig ${LATEST} installed to ${DEST}"
}
# ============================================================================
# PATH verification
# ============================================================================
verify_path() {
DEST_DIR=$(install_dir)
# Already in PATH — nothing to do
case ":$PATH:" in
*":$DEST_DIR:"*) return ;;
esac
PATH_LINE="export PATH=\"${DEST_DIR}:\$PATH\""
# Add to ~/.profile (POSIX login shell config, sourced by bash/sh/dash)
add_to_profile "$HOME/.profile" "$PATH_LINE"
# For zsh users, also add to ~/.zprofile (zsh doesn't source ~/.profile)
CURRENT_SHELL=$(basename "${SHELL:-/bin/sh}")
if [ "$CURRENT_SHELL" = "zsh" ]; then
add_to_profile "$HOME/.zprofile" "$PATH_LINE"
fi
echo ""
warn "Open a new terminal or run: source ~/.profile"
}
add_to_profile() {
PROFILE_FILE="$1"
LINE="$2"
# Already present — skip
if [ -f "$PROFILE_FILE" ] && grep -qF "$LINE" "$PROFILE_FILE"; then
ok "PATH entry already in ${PROFILE_FILE}"
return
fi
printf '\n%s\n' "$LINE" >> "$PROFILE_FILE"
ok "Added PATH entry to ${PROFILE_FILE}"
}
# ============================================================================
# Main
# ============================================================================
main() {
AUTO_YES=false
INSTALL_WATCHEXEC=false
for arg in "$@"; do
case "$arg" in
-y|--yes) AUTO_YES=true ;;
--with-watchexec) INSTALL_WATCHEXEC=true ;;
-h|--help)
printf "rig installer\n\n"
printf "Usage: curl -fsSL https://raw.githubusercontent.com/roelentless/rig/develop/install.sh | sh\n\n"
printf "Options:\n"
printf " -y, --yes Skip confirmation prompt\n"
printf " --with-watchexec Also install watchexec (file watcher)\n"
printf " -h, --help Show this help\n"
exit 0
;;
esac
done
printf "\n ${BOLD}rig installer / upgrader${RESET}\n"
# Platform
detect_platform
printf "\n Platform: ${PLATFORM}/${ARCH_LABEL}\n"
# Check dependencies
check_deps
show_status
# tmux is required - hard error
if ! $HAS_TMUX; then
echo ""
err "tmux is required but not installed."
err "Install it first:"
case "$PLATFORM" in
macos) err " brew install tmux" ;;
linux) err " sudo apt install tmux (Debian/Ubuntu)"
err " sudo dnf install tmux (Fedora)"
err " sudo pacman -S tmux (Arch)" ;;
esac
exit 1
fi
# Show what we'll do
printf "\n ${BOLD}Install plan:${RESET}\n\n"
DEST_DIR=$(install_dir)
printf " Download prebuilt binary from GitHub Releases\n"
printf " Install to ${DEST_DIR}/rig\n"
echo ""
if ! prompt_yn " Proceed? [Y/n] "; then
echo ""
info "Aborted."
info "Manual download: ${REPO_URL}/releases"
echo ""
exit 0
fi
echo ""
install_rig
verify_path
maybe_install_watchexec
printf "\n"
ok "Done!"
printf "\n"
printf " Get started:\n"
printf " rig init Create a rig.yaml\n"
printf " rig --help Show all commands\n"
printf "\n"
printf " Docs: ${REPO_URL}\n"
printf " Skip prompt: curl -fsSL ...install.sh | sh -s -- -y\n"
printf "\n"
}
main "$@"