-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·192 lines (165 loc) · 6.05 KB
/
install.sh
File metadata and controls
executable file
·192 lines (165 loc) · 6.05 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
#!/bin/sh
# Rampart install script
# Usage: curl -fsSL https://rampart.sh/install | sh
# curl -fsSL https://rampart.sh/install | sh -s -- --version v0.1.0
# curl -fsSL https://rampart.sh/install | sh -s -- --auto-setup
set -e
REPO="peg/rampart"
INSTALL_DIR="/usr/local/bin"
BINARY="rampart"
VERSION=""
AUTO_SETUP="${RAMPART_AUTO_SETUP:-0}"
# Colors (if terminal supports them).
if [ -t 1 ]; then
BOLD="\033[1m"
GREEN="\033[32m"
RED="\033[31m"
YELLOW="\033[33m"
RESET="\033[0m"
else
BOLD="" GREEN="" RED="" YELLOW="" RESET=""
fi
info() { printf "${GREEN}▸${RESET} %s\n" "$1"; }
warn() { printf "${YELLOW}▸${RESET} %s\n" "$1"; }
error() { printf "${RED}✗${RESET} %s\n" "$1" >&2; exit 1; }
# Parse args.
while [ $# -gt 0 ]; do
case "$1" in
--version) VERSION="$2"; shift 2 ;;
--version=*) VERSION="${1#--version=}"; shift ;;
--auto-setup) AUTO_SETUP=1; shift ;;
*) error "Unknown option: $1" ;;
esac
done
# Detect OS.
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
*) error "Unsupported OS: $OS (need linux or darwin)" ;;
esac
# Detect architecture.
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH (need amd64 or arm64)" ;;
esac
info "Detected ${BOLD}${OS}/${ARCH}${RESET}"
# Determine version.
if [ -z "$VERSION" ]; then
info "Fetching latest version..."
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')
if [ -z "$VERSION" ]; then
error "Could not determine latest version. Try: --version v0.1.0"
fi
fi
info "Installing ${BOLD}rampart ${VERSION}${RESET}"
# Build download URLs.
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
BINARY_URL="${BASE_URL}/rampart-${OS}-${ARCH}"
CHECKSUM_URL="${BASE_URL}/rampart-${OS}-${ARCH}.sha256"
# Create temp directory.
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
# Download binary.
info "Downloading binary..."
if ! curl -fsSL -o "${TMP_DIR}/${BINARY}" "$BINARY_URL"; then
error "Download failed. Check that ${VERSION} exists at:\n ${BINARY_URL}"
fi
# Download and verify checksum.
info "Verifying checksum..."
if curl -fsSL -o "${TMP_DIR}/${BINARY}.sha256" "$CHECKSUM_URL" 2>/dev/null; then
EXPECTED=$(awk '{print $1}' "${TMP_DIR}/${BINARY}.sha256")
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "${TMP_DIR}/${BINARY}" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "${TMP_DIR}/${BINARY}" | awk '{print $1}')
else
warn "No sha256sum or shasum found — skipping verification"
ACTUAL="$EXPECTED"
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
error "Checksum mismatch!\n Expected: ${EXPECTED}\n Got: ${ACTUAL}"
fi
info "Checksum verified ✓"
else
warn "No checksum file found — skipping verification"
fi
# Install.
chmod +x "${TMP_DIR}/${BINARY}"
if [ "$(id -u)" -eq 0 ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
INSTALL_DIR="$HOME/.local/bin"
else
INSTALL_DIR="/usr/local/bin"
fi
if [ -w "$INSTALL_DIR" ]; then
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
info "Need sudo to install to ${INSTALL_DIR}"
sudo mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
info "Installed to ${BOLD}${INSTALL_DIR}/${BINARY}${RESET}"
# Verify.
if command -v rampart >/dev/null 2>&1; then
printf "\n"
rampart version 2>/dev/null || true
printf "\n${GREEN}${BOLD}Ready!${RESET} Run ${BOLD}rampart quickstart${RESET} to get started.\n"
else
printf "\n${YELLOW}Note:${RESET} ${INSTALL_DIR} may not be in your PATH.\n"
printf "Add it: ${BOLD}export PATH=\"${INSTALL_DIR}:\$PATH\"${RESET}\n"
printf "Then run: ${BOLD}rampart quickstart${RESET}\n"
fi
# Detect AI agents and suggest setup commands.
detect_agents_and_suggest() {
printf "\n"
# Detect OpenClaw
OPENCLAW_FOUND=0
if command -v openclaw >/dev/null 2>&1; then
OPENCLAW_FOUND=1
elif [ -f "$HOME/.local/bin/openclaw" ] || [ -f "/usr/local/bin/openclaw" ] || [ -f "/usr/bin/openclaw" ]; then
OPENCLAW_FOUND=1
fi
# Detect Claude Code (claude CLI)
CLAUDE_FOUND=0
if command -v claude >/dev/null 2>&1; then
CLAUDE_FOUND=1
elif [ -f "$HOME/.claude/settings.json" ]; then
CLAUDE_FOUND=1
fi
if [ "$OPENCLAW_FOUND" -eq 1 ] || [ "$CLAUDE_FOUND" -eq 1 ]; then
printf "${GREEN}${BOLD}✓ AI agent(s) detected!${RESET}\n\n"
fi
if [ "$OPENCLAW_FOUND" -eq 1 ]; then
if [ "$AUTO_SETUP" = "1" ]; then
printf "${GREEN}▸${RESET} Auto-setup: protecting OpenClaw...\n"
rampart setup openclaw 2>&1 || printf "${YELLOW} ↳ Auto-setup failed — run manually: rampart setup openclaw${RESET}\n"
else
printf " Run this to protect your OpenClaw agent:\n"
printf " ${BOLD}rampart setup openclaw${RESET}\n"
printf "\n"
fi
fi
if [ "$CLAUDE_FOUND" -eq 1 ]; then
if [ "$AUTO_SETUP" = "1" ]; then
printf "${GREEN}▸${RESET} Auto-setup: protecting Claude Code...\n"
rampart setup claude-code 2>&1 || printf "${YELLOW} ↳ Auto-setup failed — run manually: rampart setup claude-code${RESET}\n"
else
printf " Run this to protect Claude Code:\n"
printf " ${BOLD}rampart setup claude-code${RESET}\n"
printf "\n"
fi
fi
if [ "$OPENCLAW_FOUND" -eq 0 ] && [ "$CLAUDE_FOUND" -eq 0 ]; then
printf " To protect an AI agent, run:\n"
printf " ${BOLD}rampart setup openclaw${RESET} — for OpenClaw\n"
printf " ${BOLD}rampart setup claude-code${RESET} — for Claude Code\n"
printf "\n"
fi
}
if command -v rampart >/dev/null 2>&1; then
detect_agents_and_suggest
fi