#!/bin/sh # 在主机上生成 GitHub webhook secret 并写入 /etc/codex-app-server/env,绝不打印 secret。 # 用法(主机 root 执行):sh deploy/setup-webhook-secret.sh # 效果:若 env 文件里已有 GITHUB_WEBHOOK_SECRET 则不动它并退出(避免轮换后 GitHub 端旧 secret 失效); # 否则生成 32 字节随机 hex,追加到 env 文件,重启 codex-cloud-server。 # 生成的 secret 只存在主机 env 文件里(0600 root),不要把它发回聊天、不要写进仓库。 set -eu ENV_FILE=/etc/codex-app-server/env if grep -q '^GITHUB_WEBHOOK_SECRET=' "$ENV_FILE" 2>/dev/null; then echo "GITHUB_WEBHOOK_SECRET already set, leaving it unchanged." exit 0 fi SECRET=$(openssl rand -hex 32) printf 'GITHUB_WEBHOOK_SECRET=%s\n' "$SECRET" >> "$ENV_FILE" chmod 600 "$ENV_FILE" systemctl restart codex-cloud-server echo "Webhook secret generated and stored in $ENV_FILE only; server restarted." echo "Next step: paste the same secret into GitHub repo Settings -> Webhooks -> Secret (the value is on the host only, read it from $ENV_FILE as root if you need to copy it)."