-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·85 lines (70 loc) · 1.99 KB
/
bootstrap.sh
File metadata and controls
executable file
·85 lines (70 loc) · 1.99 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
#!/bin/bash
# Baudbot bootstrap installer (non-root entrypoint)
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/modem-dev/baudbot/main/bootstrap.sh | bash
# baudbot install
#
# What this does:
# 1) Downloads the bootstrap baudbot CLI from GitHub
# 2) Installs it to /usr/local/bin/baudbot (using sudo/doas if needed)
# 3) Prints next step: `baudbot install`
set -euo pipefail
BAUDBOT_CLI_URL="${BAUDBOT_CLI_URL:-https://raw.githubusercontent.com/modem-dev/baudbot/main/bin/baudbot}"
BAUDBOT_TARGET_BIN="${BAUDBOT_BOOTSTRAP_TARGET:-/usr/local/bin/baudbot}"
TARGET_DIR="$(dirname "$BAUDBOT_TARGET_BIN")"
TMP_CLI="$(mktemp /tmp/baudbot-cli.XXXXXX)"
cleanup() {
rm -f "$TMP_CLI"
}
trap cleanup EXIT
download_file() {
local url="$1"
local dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$dest"
return 0
fi
if command -v wget >/dev/null 2>&1; then
wget -q "$url" -O "$dest"
return 0
fi
echo "❌ bootstrap requires curl or wget" >&2
exit 1
}
escalate_prefix() {
if [ "$(id -u)" -eq 0 ]; then
return 0
fi
if command -v sudo >/dev/null 2>&1; then
echo "sudo"
return 0
fi
if command -v doas >/dev/null 2>&1; then
echo "doas"
return 0
fi
echo ""
return 1
}
echo "==> Downloading baudbot bootstrap CLI"
download_file "$BAUDBOT_CLI_URL" "$TMP_CLI"
chmod 0755 "$TMP_CLI"
if [ -w "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
install -m 0755 "$TMP_CLI" "$BAUDBOT_TARGET_BIN"
else
ESCALATOR="$(escalate_prefix || true)"
if [ -z "$ESCALATOR" ]; then
echo "❌ cannot write to $TARGET_DIR and no sudo/doas found" >&2
echo "Try running as root, or set BAUDBOT_BOOTSTRAP_TARGET to a user-writable path." >&2
exit 1
fi
echo "==> Installing to $BAUDBOT_TARGET_BIN using $ESCALATOR"
"$ESCALATOR" mkdir -p "$TARGET_DIR"
"$ESCALATOR" install -m 0755 "$TMP_CLI" "$BAUDBOT_TARGET_BIN"
fi
echo "✅ Installed baudbot bootstrap CLI to $BAUDBOT_TARGET_BIN"
echo ""
echo "Next step:"
echo " baudbot install"