-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
186 lines (164 loc) · 4.88 KB
/
install.sh
File metadata and controls
186 lines (164 loc) · 4.88 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
#!/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
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BINARY_NAME="ctrlnode"
DEFAULT_DIR="/usr/local/bin"
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 ---
mkdir -p "$INSTALL_DIR"
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
if [ -w "$INSTALL_DIR" ]; then
cp "$SRC_FILE" "$DEST"
else
echo "Requires sudo to install to $INSTALL_DIR..."
sudo cp "$SRC_FILE" "$DEST"
fi
chmod +x "$DEST"
# 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 ""
echo "Next: start the Bridge:"
echo " ctrlnode"
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..."
BASE_PATH="$WORKSPACE_ROOT" "$DEST"
;;
esac
fi