#!/usr/bin/env bash set -euo pipefail APP_DIR=/opt/okx-codex-trader OBSERVER_SERVICE=eth-nextgen-micro-observer.service EXECUTOR_SERVICE=bb-squeeze-executor.service SHORT_BIAS_SERVICE=short-bias-readonly-observer.service CALENDAR_SERVICE=calendar-fusion-observer.service FOCUSED_SERVICE=eth-focused-portfolio-observer.service BB_T_GATED_SERVICE=bb-squeeze-t-gated-observer.service CRASH_FOLLOW_SERVICE=crash-follow-short-observer.service sudo useradd --system --create-home --shell /usr/sbin/nologin okxbot 2>/dev/null || true sudo mkdir -p "$APP_DIR" /etc/okx-codex-trader sudo rsync -a --delete \ --exclude .git \ --exclude .venv \ --exclude .pytest_cache \ --exclude data \ --exclude var \ ./ "$APP_DIR"/ sudo apt-get update sudo apt-get install -y python3-venv sudo python3 -m venv "$APP_DIR/.venv" sudo "$APP_DIR/.venv/bin/python" -m pip install --upgrade pip sudo "$APP_DIR/.venv/bin/python" -m pip install backtesting requests pandas pytest sudo mkdir -p "$APP_DIR/var" sudo chown -R okxbot:okxbot "$APP_DIR" if [ ! -f /etc/okx-codex-trader/okx.env ]; then sudo tee /etc/okx-codex-trader/okx.env >/dev/null <<'ENV' OKX_TRADING_ENV=live OKX_API_KEY= OKX_API_SECRET= OKX_API_PASSPHRASE= ENV sudo chmod 600 /etc/okx-codex-trader/okx.env fi sudo install -m 0644 "$APP_DIR/deploy/$OBSERVER_SERVICE" "/etc/systemd/system/$OBSERVER_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$EXECUTOR_SERVICE" "/etc/systemd/system/$EXECUTOR_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$SHORT_BIAS_SERVICE" "/etc/systemd/system/$SHORT_BIAS_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$CALENDAR_SERVICE" "/etc/systemd/system/$CALENDAR_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$FOCUSED_SERVICE" "/etc/systemd/system/$FOCUSED_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$BB_T_GATED_SERVICE" "/etc/systemd/system/$BB_T_GATED_SERVICE" sudo install -m 0644 "$APP_DIR/deploy/$CRASH_FOLLOW_SERVICE" "/etc/systemd/system/$CRASH_FOLLOW_SERVICE" sudo systemctl daemon-reload sudo systemctl disable --now eth-nextgen-micro-executor.service 2>/dev/null || true sudo systemctl enable "$OBSERVER_SERVICE" sudo systemctl enable "$EXECUTOR_SERVICE" sudo systemctl enable "$SHORT_BIAS_SERVICE" sudo systemctl enable "$CALENDAR_SERVICE" sudo systemctl enable "$FOCUSED_SERVICE" sudo systemctl enable "$BB_T_GATED_SERVICE" sudo systemctl enable "$CRASH_FOLLOW_SERVICE" sudo systemctl restart "$OBSERVER_SERVICE" sudo systemctl restart "$EXECUTOR_SERVICE" sudo systemctl restart "$SHORT_BIAS_SERVICE" sudo systemctl restart "$CALENDAR_SERVICE" sudo systemctl restart "$FOCUSED_SERVICE" sudo systemctl restart "$BB_T_GATED_SERVICE" sudo systemctl restart "$CRASH_FOLLOW_SERVICE" sudo systemctl status "$OBSERVER_SERVICE" --no-pager sudo systemctl status "$EXECUTOR_SERVICE" --no-pager sudo systemctl status "$SHORT_BIAS_SERVICE" --no-pager sudo systemctl status "$CALENDAR_SERVICE" --no-pager sudo systemctl status "$FOCUSED_SERVICE" --no-pager sudo systemctl status "$BB_T_GATED_SERVICE" --no-pager sudo systemctl status "$CRASH_FOLLOW_SERVICE" --no-pager