-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
225 lines (202 loc) · 6.8 KB
/
Copy pathinstall.sh
File metadata and controls
225 lines (202 loc) · 6.8 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
#!/usr/bin/env sh
# CtrlNode Bridge — Linux/macOS installer
# Usage:
# curl -fsSL https://github.com/ctrlnode-ai/ctrlnode/releases/latest/download/install.sh | sh
#
# With custom install directory:
# curl -fsSL https://github.com/ctrlnode-ai/ctrlnode/releases/latest/download/install.sh | sh -s -- --dir ~/.local/bin
set -e
REPO="ctrlnode-ai/ctrlnode"
BINARY_NAME="ctrlnode"
# Default to ~/.local/bin when not root (no sudo needed).
# Pass --dir /usr/local/bin to install system-wide.
if [ "$(id -u)" -eq 0 ]; then
DEFAULT_DIR="/usr/local/bin"
else
DEFAULT_DIR="$HOME/.local/bin"
fi
INSTALL_DIR="$DEFAULT_DIR"
# --- parse args ---
while [ $# -gt 0 ]; do
case "$1" in
--dir) INSTALL_DIR="$2"; shift 2 ;;
--dir=*) INSTALL_DIR="${1#*=}"; shift ;;
*) shift ;;
esac
done
DEFAULT_WORKSPACE="$HOME"
WORKSPACE_ROOT=""
echo ""
echo "CtrlNode Bridge Installer"
echo "--------------------------"
echo ""
# --- workspace directory ---
echo "Where is your workspace?"
echo " This is the root folder where ctrlnode will read and write files."
echo " For security, the bridge cannot access anything outside this folder."
echo " If you are a developer, point this to your source code root (e.g. ~/code)."
if [ -t 1 ] && [ -e /dev/tty ]; then
printf "Workspace [%s]: " "$DEFAULT_WORKSPACE" > /dev/tty
read -r ws_answer < /dev/tty
WORKSPACE_ROOT="${ws_answer:-$DEFAULT_WORKSPACE}"
else
WORKSPACE_ROOT="$DEFAULT_WORKSPACE"
fi
echo " Workspace: $WORKSPACE_ROOT"
echo " Tip: to change it later, set BASE_PATH and restart ctrlnode."
echo ""
# Persist workspace
SHELL_RC=""
if [ -f "$HOME/.bashrc" ]; then SHELL_RC="$HOME/.bashrc"
elif [ -f "$HOME/.zshrc" ]; then SHELL_RC="$HOME/.zshrc"
elif [ -f "$HOME/.profile" ]; then SHELL_RC="$HOME/.profile"
fi
if [ -n "$SHELL_RC" ]; then
grep -v 'BASE_PATH' "$SHELL_RC" > "${SHELL_RC}.tmp" && mv "${SHELL_RC}.tmp" "$SHELL_RC"
echo "export BASE_PATH=\"$WORKSPACE_ROOT\"" >> "$SHELL_RC"
fi
export BASE_PATH="$WORKSPACE_ROOT"
# --- detect OS and arch ---
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
case "$ARCH" in
x86_64)
if grep -q avx2 /proc/cpuinfo 2>/dev/null; then
ASSET="ctrlnode-linux-x64"
else
ASSET="ctrlnode-linux-x64-baseline"
fi
;;
aarch64|arm64)
echo "ERROR: Linux ARM64 binary not yet available." >&2
exit 1
;;
*)
echo "ERROR: Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
;;
Darwin)
case "$ARCH" in
arm64) ASSET="ctrlnode-darwin-arm64" ;;
x86_64)
echo "ERROR: macOS Intel binary not yet available." >&2
exit 1
;;
*)
echo "ERROR: Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
;;
*)
echo "ERROR: Unsupported OS: $OS. On Windows use install.ps1 instead." >&2
exit 1
;;
esac
# --- fetch latest release from GitHub ---
echo "Fetching latest release..."
if command -v curl >/dev/null 2>&1; then
TAG="$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
elif command -v wget >/dev/null 2>&1; then
TAG="$(wget -qO- "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
else
echo "ERROR: curl or wget required." >&2
exit 1
fi
if [ -z "$TAG" ]; then
echo "ERROR: Could not determine latest release tag." >&2
exit 1
fi
echo " Release: $TAG"
echo " Asset: $ASSET"
echo ""
echo "Downloading..."
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
TMP_FILE="$(mktemp)"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_FILE"
else
wget -qO "$TMP_FILE" "$DOWNLOAD_URL"
fi
# --- install ---
DEST="${INSTALL_DIR}/${BINARY_NAME}"
# Stop any running instance before replacing the binary
if [ -f "$DEST" ]; then
if command -v pkill >/dev/null 2>&1; then
pkill -x "$BINARY_NAME" 2>/dev/null && sleep 0.5 || true
fi
fi
mkdir -p "$INSTALL_DIR"
if [ -w "$INSTALL_DIR" ]; then
cp "$TMP_FILE" "$DEST"
chmod +x "$DEST"
else
echo "Requires sudo to install to $INSTALL_DIR..."
sudo cp "$TMP_FILE" "$DEST"
sudo chmod +x "$DEST"
fi
# macOS: remove quarantine flag
if [ "$OS" = "Darwin" ]; then
xattr -d com.apple.quarantine "$DEST" 2>/dev/null || true
fi
echo ""
echo "OK Installed: $DEST"
echo " Version: $TAG"
echo ""
# Ensure ~/.local/bin is in PATH when using user-local install
PATH_UPDATED=0
if [ "$INSTALL_DIR" = "$HOME/.local/bin" ]; then
if [ -n "$SHELL_RC" ] && ! grep -q '\.local/bin' "$SHELL_RC" 2>/dev/null; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
PATH_UPDATED=1
fi
export PATH="$HOME/.local/bin:$PATH"
hash -r 2>/dev/null || true
fi
# If run as root via sudo, fix ownership of ~/.ctrlnode so the real user can write to it
if [ "$(id -u)" -eq 0 ] && [ -n "$SUDO_USER" ]; then
REAL_HOME="$(getent passwd "$SUDO_USER" | cut -d: -f6 2>/dev/null || echo "")"
if [ -n "$REAL_HOME" ] && [ -d "$REAL_HOME/.ctrlnode" ]; then
chown -R "$SUDO_USER:$SUDO_USER" "$REAL_HOME/.ctrlnode" 2>/dev/null || true
echo " Fixed ownership of $REAL_HOME/.ctrlnode -> $SUDO_USER"
fi
fi
if [ "$PATH_UPDATED" -eq 1 ]; then
echo "┌─────────────────────────────────────────────────────┐"
echo "│ IMPORTANT: reload your shell before running ctrlnode │"
echo "│ │"
echo "│ source $SHELL_RC"
echo "│ │"
echo "│ Then start the Bridge: ctrlnode │"
echo "└─────────────────────────────────────────────────────┘"
else
echo "Next: start the Bridge:"
echo " ctrlnode"
fi
echo ""
echo "Workspace: $WORKSPACE_ROOT"
echo "When you run the Bridge for the first time, it will prompt for your pairing token or read it from a .env file."
echo "Full setup (token + API keys): ctrlnode --setup"
echo "Get your token at: https://app.ctrlnode.ai (Settings -> Bridge)"
echo ""
# --- optional: run the bridge now ---
if [ -t 1 ] && [ -e /dev/tty ]; then
printf "Do you want to run ctrlnode now? (Y/n): " > /dev/tty
read -r run_now < /dev/tty
case "$run_now" in
n|N|no|No)
echo "You can start it later with: ctrlnode"
;;
*)
echo "Starting ctrlnode..."
# Redirect stdin from /dev/tty so ctrlnode's readline reads from the
# terminal, not the curl pipe. Without this, readline captures the
# prompt text itself as the answer and saves a corrupted PAIRING_TOKEN.
BASE_PATH="$WORKSPACE_ROOT" "$DEST" < /dev/tty
;;
esac
fi