返回 CodeWhale
install-services.sh
根目录 / scripts / tencent-lighthouse / install-services.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 if [[ "${EUID}" -ne 0 ]]; then
5 echo "Run as root: sudo bash scripts/tencent-lighthouse/install-services.sh" >&2
6 exit 1
7 fi
8
9 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
10 CODEWHALE_USER="${CODEWHALE_USER:-${DEEPSEEK_USER:-codewhale}}"
11 CODEWHALE_ROOT="${CODEWHALE_ROOT:-${DEEPSEEK_ROOT:-/opt/codewhale}}"
12 BRIDGE_KIND="${CODEWHALE_BRIDGE:-${DEEPSEEK_BRIDGE:-feishu}}"
13
14 case "${BRIDGE_KIND}" in
15 feishu|lark)
16 BRIDGE_SRC="integrations/feishu-bridge"
17 BRIDGE_DST="${CODEWHALE_ROOT}/bridge"
18 BRIDGE_UNIT="codewhale-feishu-bridge.service"
19 BRIDGE_ENV="/etc/codewhale/feishu-bridge.env"
20 BRIDGE_ENV_EXAMPLE="deploy/tencent-lighthouse/examples/feishu-bridge.env.example"
21 BRIDGE_STATE_DIR="/var/lib/codewhale-feishu-bridge"
22 VALIDATOR="integrations/feishu-bridge/scripts/validate-config.mjs"
23 ;;
24 telegram)
25 BRIDGE_SRC="integrations/telegram-bridge"
26 BRIDGE_DST="${CODEWHALE_ROOT}/telegram-bridge"
27 BRIDGE_UNIT="codewhale-telegram-bridge.service"
28 BRIDGE_ENV="/etc/codewhale/telegram-bridge.env"
29 BRIDGE_ENV_EXAMPLE="deploy/tencent-lighthouse/examples/telegram-bridge.env.example"
30 BRIDGE_STATE_DIR="/var/lib/codewhale-telegram-bridge"
31 VALIDATOR="integrations/telegram-bridge/scripts/validate-config.mjs"
32 ;;
33 *)
34 echo "Unknown bridge '${BRIDGE_KIND}'. Use CODEWHALE_BRIDGE=feishu or CODEWHALE_BRIDGE=telegram." >&2
35 exit 1
36 ;;
37 esac
38
39 install -d -m 0750 -o root -g "${CODEWHALE_USER}" /etc/codewhale
40 install -d -m 0700 -o "${CODEWHALE_USER}" -g "${CODEWHALE_USER}" "${BRIDGE_STATE_DIR}"
41 install -d -o "${CODEWHALE_USER}" -g "${CODEWHALE_USER}" "${BRIDGE_DST}"
42
43 if [[ ! -f /etc/codewhale/runtime.env && -f "${REPO_ROOT}/deploy/tencent-lighthouse/examples/runtime.env.example" ]]; then
44 install -m 0640 -o root -g "${CODEWHALE_USER}" \
45 "${REPO_ROOT}/deploy/tencent-lighthouse/examples/runtime.env.example" \
46 /etc/codewhale/runtime.env
47 fi
48
49 if [[ ! -f "${BRIDGE_ENV}" && -f "${REPO_ROOT}/${BRIDGE_ENV_EXAMPLE}" ]]; then
50 install -m 0640 -o root -g "${CODEWHALE_USER}" \
51 "${REPO_ROOT}/${BRIDGE_ENV_EXAMPLE}" \
52 "${BRIDGE_ENV}"
53 fi
54 rsync -a --delete \
55 --exclude node_modules \
56 "${REPO_ROOT}/${BRIDGE_SRC}/" \
57 "${BRIDGE_DST}/"
58 chown -R "${CODEWHALE_USER}:${CODEWHALE_USER}" "${BRIDGE_DST}"
59
60 if [[ -f "${BRIDGE_DST}/package-lock.json" ]]; then
61 sudo -u "${CODEWHALE_USER}" npm --prefix "${BRIDGE_DST}" ci --omit=dev
62 else
63 sudo -u "${CODEWHALE_USER}" npm --prefix "${BRIDGE_DST}" install --omit=dev
64 fi
65
66 install -m 0644 "${REPO_ROOT}/deploy/tencent-lighthouse/systemd/codewhale-runtime.service" /etc/systemd/system/codewhale-runtime.service
67 install -m 0644 "${REPO_ROOT}/deploy/tencent-lighthouse/systemd/${BRIDGE_UNIT}" "/etc/systemd/system/${BRIDGE_UNIT}"
68
69 systemctl daemon-reload
70 systemctl enable codewhale-runtime "${BRIDGE_UNIT}"
71
72 cat <<'EOF'
73 Services installed but not started.
74
75 Before starting, verify:
76 /etc/codewhale/runtime.env
77 EOF
78 cat <<EOF
79 ${BRIDGE_ENV}
80 sudo -u ${CODEWHALE_USER} node ${REPO_ROOT}/${VALIDATOR} --env ${BRIDGE_ENV} --runtime-env /etc/codewhale/runtime.env --workspace-root /opt/whalebro --check-filesystem
81 Then run:
82 sudo systemctl start codewhale-runtime
83 sudo systemctl start ${BRIDGE_UNIT}
84 sudo CODEWHALE_BRIDGE=${BRIDGE_KIND} bash /opt/whalebro/codewhale/scripts/tencent-lighthouse/doctor.sh
85 sudo journalctl -u ${BRIDGE_UNIT} -f
86 EOF
87
87 lines BASH