-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·180 lines (143 loc) · 7.65 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·180 lines (143 loc) · 7.65 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
#!/bin/bash
# install.sh — install and configure the ZINO agent platform.
# Run after bootstrap.sh. Idempotent — safe to re-run for upgrades.
# Run as root: sudo bash install.sh
set -euo pipefail
# ── Constants ────────────────────────────────────────────────────────────────
INSTALL_DIR="/opt/zino"
CONFIG_DIR="/etc/zino"
DATA_DIR="/var/lib/zino"
RUN_DIR="/run/zino"
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
SERVICE_USER="zino"
SERVICE_GROUP="zino"
# ── Preflight ────────────────────────────────────────────────────────────────
if [[ $EUID -ne 0 ]]; then
echo "Error: install.sh must be run as root." >&2
exit 1
fi
echo "=== ZINO Installation ==="
echo "Source: ${SRC_DIR}"
echo "Install: ${INSTALL_DIR}"
echo ""
# ── 1. Service user ─────────────────────────────────────────────────────────
if ! id "${SERVICE_USER}" &>/dev/null; then
echo "[1/10] Creating service user '${SERVICE_USER}'..."
useradd --system \
--no-create-home \
--home-dir "${INSTALL_DIR}" \
--shell /usr/sbin/nologin \
"${SERVICE_USER}"
else
echo "[1/10] Service user '${SERVICE_USER}' already exists."
fi
# ── 2. Directory structure ───────────────────────────────────────────────────
echo "[2/10] Creating directories..."
mkdir -p "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}/agents"
mkdir -p "${INSTALL_DIR}/zino_utils"
mkdir -p "${CONFIG_DIR}"
mkdir -p "${DATA_DIR}/mem/channels"
mkdir -p "${RUN_DIR}"
# ── 3. Application files ────────────────────────────────────────────────────
echo "[3/10] Syncing application files to ${INSTALL_DIR}..."
rsync -a "${SRC_DIR}/"*.py "${INSTALL_DIR}/"
rsync -a "${SRC_DIR}/zino_utils/"*.py "${INSTALL_DIR}/zino_utils/"
rsync -a "${SRC_DIR}/agents/"* "${INSTALL_DIR}/agents/"
rsync -a "${SRC_DIR}/requirements.txt" "${INSTALL_DIR}/"
#rsync -a "${SRC_DIR}/agents/tools/" "${INSTALL_DIR}/agents/tools/"
#rsync -a "${SRC_DIR}/agents/skills/" "${INSTALL_DIR}/agents/skills/"
# ── 4. Configuration ────────────────────────────────────────────────────────
if [[ ! -f "${CONFIG_DIR}/ZINO.toml" ]]; then
echo "[4/10] Installing default configuration..."
cp "${SRC_DIR}/ZINO.toml" "${CONFIG_DIR}/ZINO.toml"
# Rewrite paths for installed layout
sed -i 's|^data_dir *= *"data/mem"|data_dir = "/var/lib/zino/mem"|' \
"${CONFIG_DIR}/ZINO.toml"
else
echo "[4/10] Configuration exists at ${CONFIG_DIR}/ZINO.toml — not overwriting."
echo " To reset: rm ${CONFIG_DIR}/ZINO.toml and re-run install.sh"
fi
# ── 5. Environment file (API key) ───────────────────────────────────────────
if [[ ! -f "${CONFIG_DIR}/env" ]]; then
echo "[5/10] Creating environment file..."
cat > "${CONFIG_DIR}/env" <<'ENVEOF'
# /etc/zino/env — sourced by all ZINO systemd services.
# Set your LLM API key here.
# LLM_API_KEY=sk-your-key-here
ENVEOF
else
echo "[5/10] Environment file exists — not overwriting."
fi
# ── 6. Python virtual environment ───────────────────────────────────────────
echo "[6/10] Setting up Python virtual environment..."
python3 -m venv "${INSTALL_DIR}/venv"
"${INSTALL_DIR}/venv/bin/pip" install --upgrade pip --quiet
"${INSTALL_DIR}/venv/bin/pip" install -r "${SRC_DIR}/requirements.txt" --quiet
echo " $(${INSTALL_DIR}/venv/bin/python3 --version)"
echo " Packages installed:"
"${INSTALL_DIR}/venv/bin/pip" list --format=columns 2>/dev/null | grep -iE 'openai|dotenv' || true
# ── 7. Permissions ───────────────────────────────────────────────────────────
echo "[7/10] Setting ownership and permissions..."
chown -R "${SERVICE_USER}:${SERVICE_GROUP}" "${INSTALL_DIR}"
chmod 750 "${INSTALL_DIR}"
chown -R "${SERVICE_USER}:${SERVICE_GROUP}" "${DATA_DIR}"
chmod 750 "${DATA_DIR}"
chown -R "${SERVICE_USER}:${SERVICE_GROUP}" "${RUN_DIR}"
chmod 750 "${RUN_DIR}"
# Config readable by service, owned by root
chown root:"${SERVICE_GROUP}" "${CONFIG_DIR}"
chmod 750 "${CONFIG_DIR}"
chown root:"${SERVICE_GROUP}" "${CONFIG_DIR}/ZINO.toml"
chmod 640 "${CONFIG_DIR}/ZINO.toml"
chown root:"${SERVICE_GROUP}" "${CONFIG_DIR}/env"
chmod 640 "${CONFIG_DIR}/env"
# ── 8. tmpfiles.d (runtime directory across reboots) ────────────────────────
echo "[8/10] Installing tmpfiles.d configuration..."
cp "${SRC_DIR}/systemd/zino-tmpfiles.conf" /usr/lib/tmpfiles.d/zino.conf
systemd-tmpfiles --create
# ── 9. systemd units ────────────────────────────────────────────────────────
echo "[9/10] Installing systemd units..."
cp "${SRC_DIR}/systemd/zino.target" /etc/systemd/system/
cp "${SRC_DIR}/systemd/zino-rtr.service" /etc/systemd/system/
cp "${SRC_DIR}/systemd/zino-exc.service" /etc/systemd/system/
cp "${SRC_DIR}/systemd/zino-ctx.service" /etc/systemd/system/
cp "${SRC_DIR}/systemd/zino-daemon.service" /etc/systemd/system/
# Remove old units from previous installations (consolidated into ctx and daemon)
for old_unit in zino-sys zino-mem zino-agr; do
if [[ -f "/etc/systemd/system/${old_unit}.service" ]]; then
echo " Removing obsolete ${old_unit}.service"
systemctl disable --quiet "${old_unit}.service" 2>/dev/null || true
rm -f "/etc/systemd/system/${old_unit}.service"
fi
done
systemctl daemon-reload
# ── 10. Enable services ─────────────────────────────────────────────────────
echo "[10/10] Enabling ZINO services..."
systemctl enable --quiet zino.target
for svc in zino-rtr zino-exc zino-ctx zino-daemon; do
systemctl enable --quiet "${svc}.service"
done
# ── CLI wrapper ──────────────────────────────────────────────────────────────
cat > /usr/local/bin/zino-cli <<'CLIEOF'
#!/bin/bash
exec /opt/zino/venv/bin/python3 /opt/zino/zino_utils/zino-cli.py \
--config /etc/zino/ZINO.toml "$@"
CLIEOF
chmod 755 /usr/local/bin/zino-cli
# ── Done ─────────────────────────────────────────────────────────────────────
echo ""
echo "=== Installation complete ==="
echo ""
echo "Before starting ZINO, set your API key:"
echo " sudo editor /etc/zino/env"
echo " # uncomment and fill in LLM_API_KEY=sk-..."
echo ""
echo "Start all services:"
echo " sudo systemctl start zino.target"
echo ""
echo "Check status:"
echo " systemctl status 'zino-*'"
echo ""
echo "Quick test:"
echo " zino-cli \"Hello, what can you do?\""