forked from nexustar/usher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·211 lines (175 loc) · 5.55 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·211 lines (175 loc) · 5.55 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
#!/usr/bin/env bash
# Install usher from a GitHub release binary.
#
# curl -fsSL https://raw.githubusercontent.com/nexustar/usher/main/install.sh | bash
#
# What it does:
# 1. Downloads the latest release binary to ~/.local/bin/usher (override with USHER_INSTALL_DIR)
# 2. Installs a user-level service (launchd on macOS, systemd on Linux)
#
# To uninstall:
# usher setup --remove
# # macOS: launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/io.github.nexustar.usher.plist
# # Linux: systemctl --user disable --now usher
# rm ~/.local/bin/usher
set -euo pipefail
REPO="nexustar/usher"
INSTALL_DIR="${USHER_INSTALL_DIR:-$HOME/.local/bin}"
# --- helpers ----------------------------------------------------------------
die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; }
info() { printf '\033[34m==>\033[0m %s\n' "$*"; }
need() {
command -v "$1" >/dev/null 2>&1 || die "'$1' is required but not found"
}
# --- detect platform --------------------------------------------------------
detect_platform() {
local os arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
darwin) ;;
linux) ;;
*) die "unsupported OS: $os" ;;
esac
case "$arch" in
x86_64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*) die "unsupported architecture: $arch" ;;
esac
PLATFORM="${os}-${arch}"
}
# --- download ---------------------------------------------------------------
download_binary() {
need curl
local url="https://github.com/${REPO}/releases/latest/download/usher-${PLATFORM}"
mkdir -p "$INSTALL_DIR"
info "Downloading usher-${PLATFORM} → ${INSTALL_DIR}/usher"
curl -fSL --progress-bar "$url" -o "${INSTALL_DIR}/usher"
chmod +x "${INSTALL_DIR}/usher"
}
# --- ensure PATH ------------------------------------------------------------
ensure_path() {
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) return ;;
esac
export PATH="${INSTALL_DIR}:${PATH}"
local line="export PATH=\"${INSTALL_DIR}:\$PATH\""
local rc=""
case "${SHELL:-}" in
*/zsh) rc="$HOME/.zshrc" ;;
*/bash) rc="$HOME/.bashrc" ;;
esac
if [ -z "$rc" ] || [ ! -f "$rc" ]; then
for f in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.zshrc" "$HOME/.zprofile" "$HOME/.profile"; do
[ -f "$f" ] && rc="$f" && break
done
fi
if [ -n "$rc" ]; then
grep -qF "$INSTALL_DIR" "$rc" 2>/dev/null || printf '\n%s\n' "$line" >> "$rc"
info "Added ${INSTALL_DIR} to PATH in ${rc}"
else
info "Add to your shell profile: ${line}"
fi
}
# --- service install --------------------------------------------------------
install_service_darwin() {
local plist_dir="$HOME/Library/LaunchAgents"
local plist="${plist_dir}/io.github.nexustar.usher.plist"
local bin="${INSTALL_DIR}/usher"
mkdir -p "$plist_dir"
# Collect PATH dirs that contain claude / codex / usher.
local svc_path=""
for cmd in claude codex; do
local p
p="$(command -v "$cmd" 2>/dev/null || true)"
[ -n "$p" ] && svc_path="${svc_path:+${svc_path}:}$(dirname "$p")"
done
svc_path="${svc_path:+${svc_path}:}${INSTALL_DIR}:/usr/bin:/bin"
cat > "$plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.github.nexustar.usher</string>
<key>ProgramArguments</key>
<array>
<string>${bin}</string>
<string>serve</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/usher.log</string>
<key>StandardErrorPath</key>
<string>/tmp/usher.err</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>${svc_path}</string>
</dict>
</dict>
</plist>
EOF
launchctl bootout "gui/$(id -u)" "$plist" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$plist"
info "LaunchAgent installed and started"
info " Logs: /tmp/usher.log"
info " Stop: launchctl bootout gui/$(id -u) ${plist}"
}
install_service_linux() {
local unit_dir="$HOME/.config/systemd/user"
local unit="${unit_dir}/usher.service"
local bin="${INSTALL_DIR}/usher"
need systemctl
# Collect PATH dirs that contain claude / codex / usher.
local svc_path=""
for cmd in claude codex; do
local p
p="$(command -v "$cmd" 2>/dev/null || true)"
[ -n "$p" ] && svc_path="${svc_path:+${svc_path}:}$(dirname "$p")"
done
svc_path="${svc_path:+${svc_path}:}${INSTALL_DIR}:/usr/bin:/bin"
mkdir -p "$unit_dir"
cat > "$unit" <<EOF
[Unit]
Description=usher — Claude/Codex session router
After=network.target
[Service]
Type=simple
ExecStart=${bin} serve
Restart=on-failure
RestartSec=3
Environment=PATH=${svc_path}
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now usher
if [ "$(loginctl show-user "$USER" --property=Linger 2>/dev/null)" != "Linger=yes" ]; then
info "To keep usher running after logout: sudo loginctl enable-linger $USER"
fi
info "systemd user service installed and started"
info " Logs: journalctl --user -u usher -f"
info " Stop: systemctl --user disable --now usher"
}
install_service() {
case "$(uname -s)" in
Darwin) install_service_darwin ;;
Linux) install_service_linux ;;
esac
}
# --- main -------------------------------------------------------------------
main() {
detect_platform
download_binary
ensure_path
install_service
echo
info "Done! usher is running on http://127.0.0.1:7777"
info "Set a password for remote access: usher set-password"
}
main "$@"