-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·139 lines (121 loc) · 4.39 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·139 lines (121 loc) · 4.39 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
#!/usr/bin/env bash
# Zen Proxy installer for Linux & macOS
# Usage:
# curl -fsSL https://raw.githubusercontent.com/12errh/zen-proxy/main/install.sh | bash
# # or, from a local checkout:
# bash install.sh --local /path/to/zen-proxy
#
# Env options:
# ZEN_PROXY_REPO GitHub "owner/repo" (default: 12errh/zen-proxy)
# ZEN_PROXY_DIR install directory (default: ~/.zen-proxy)
# ZEN_PROXY_PORT default port (default: 8787)
set -euo pipefail
REPO="${ZEN_PROXY_REPO:-12errh/zen-proxy}"
INSTALL_DIR="${ZEN_PROXY_DIR:-$HOME/.zen-proxy}"
PORT="${ZEN_PROXY_PORT:-8787}"
LOCAL_SRC=""
RESET_MODELS=0
while [ "$#" -gt 0 ]; do
case "$1" in
--local) LOCAL_SRC="${2:-}"; shift 2 ;;
--reset-models) RESET_MODELS=1; shift ;;
*) shift ;;
esac
done
info() { printf "\033[32m%s\033[0m\n" "$*"; }
warn() { printf "\033[33m%s\033[0m\n" "$*"; }
die() { printf "\033[31m%s\033[0m\n" "$*" >&2; exit 1; }
if [ -z "$INSTALL_DIR" ] || [ "$INSTALL_DIR" = "/" ]; then
die "Refusing to install into '$INSTALL_DIR'"
fi
command -v curl >/dev/null 2>&1 || die "curl is required. Install it first."
command -v node >/dev/null 2>&1 || die "Node.js >= 18 is required. See https://nodejs.org"
NODE_MAJOR=$(node -e 'console.log(process.versions.node.split(".")[0])' 2>/dev/null || echo 0)
if [ "$NODE_MAJOR" -lt 18 ]; then die "Node.js >= 18 is required (found $(node -v)). See https://nodejs.org"; fi
mkdir -p "$INSTALL_DIR"
info "Installing zen-proxy to $INSTALL_DIR"
# Preserve an existing config across the wipe/copy below.
CFG_BAK="$(mktemp)"
if [ -f "$INSTALL_DIR/zen-proxy.json" ]; then
cp "$INSTALL_DIR/zen-proxy.json" "$CFG_BAK"
fi
if [ -n "$LOCAL_SRC" ]; then
[ -d "$LOCAL_SRC" ] || die "Local source not found: $LOCAL_SRC"
cp -r "$LOCAL_SRC/." "$INSTALL_DIR/"
rm -rf "$INSTALL_DIR/.mimocode" "$INSTALL_DIR/node_modules" "$INSTALL_DIR/.git" "$INSTALL_DIR/zen-proxy.json.tmp"
info "Copied from local source: $LOCAL_SRC"
else
TARBALL="https://codeload.github.com/$REPO/tar.gz/refs/heads/main"
info "Downloading $TARBALL …"
TMP="$(mktemp -d)"
curl -fsSL "$TARBALL" -o "$TMP/repo.tar.gz"
tar -xzf "$TMP/repo.tar.gz" -C "$TMP"
rm -rf "$INSTALL_DIR"/*
cp -r "$TMP"/*/. "$INSTALL_DIR/"
rm -rf "$TMP"
info "Downloaded and extracted $REPO"
fi
if [ -s "$CFG_BAK" ]; then
cp "$CFG_BAK" "$INSTALL_DIR/zen-proxy.json"
fi
rm -f "$CFG_BAK"
if [ ! -f "$INSTALL_DIR/zen-proxy.mjs" ]; then
die "zen-proxy.mjs not found after install — check ZEN_PROXY_REPO"
fi
if [ ! -f "$INSTALL_DIR/zen-proxy.json" ]; then
printf '{ "host": "127.0.0.1", "port": %s }\n' "$PORT" > "$INSTALL_DIR/zen-proxy.json"
info "Created default config with port $PORT"
elif [ "$RESET_MODELS" = "1" ]; then
# Drop a model list that an older build may have trimmed, keeping every other
# setting (keys, port, aliases) untouched.
if command -v node >/dev/null 2>&1; then
node -e '
const fs = require("fs");
const p = process.argv[1];
const c = JSON.parse(fs.readFileSync(p, "utf8"));
delete c.fallbackModels;
fs.writeFileSync(p, JSON.stringify(c, null, 2));
' "$INSTALL_DIR/zen-proxy.json" && info "Reset model list to defaults (keys preserved)"
fi
fi
cat > "$INSTALL_DIR/zen-proxy" <<EOF
#!/usr/bin/env bash
exec node "$INSTALL_DIR/zen-proxy.mjs" "\$@"
EOF
chmod +x "$INSTALL_DIR/zen-proxy"
ln -sf "$INSTALL_DIR/zen-proxy" "$HOME/.local/bin/zen-proxy" 2>/dev/null || {
mkdir -p "$HOME/.local/bin"
ln -sf "$INSTALL_DIR/zen-proxy" "$HOME/.local/bin/zen-proxy"
}
info ""
info "✓ zen-proxy installed!"
info " Dashboard: http://127.0.0.1:$PORT"
info ""
info "Run it: zen-proxy"
info "Or add PATH: export PATH=\"\$HOME/.local/bin:\$PATH\""
info ""
info "Point your AI agent at:"
info " baseURL = http://127.0.0.1:$PORT/v1"
info " apiKey = public"
info " model = space-bunny-free (or any model listed in the dashboard)"
if command -v systemctl >/dev/null 2>&1 && [ -w /etc/systemd/system ]; then
info ""
read -r -p "Install as a systemd service (auto-start)? [y/N] " ans || true
if [[ "$ans" =~ ^[Yy]$ ]]; then
cat > /etc/systemd/system/zen-proxy.service <<SVC
[Unit]
Description=Zen Proxy
After=network.target
[Service]
ExecStart=$(command -v node) $INSTALL_DIR/zen-proxy.mjs
Restart=always
RestartSec=3
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
SVC
systemctl daemon-reload
systemctl enable --now zen-proxy
info "systemd service zen-proxy started."
fi
fi