Files
jiu/deploy/jiu-gencode.sh
wangjia 54451f0e52 feat(deploy): gencode 纳入 server 发版产物 + EC2 生码封装
server 流水线编译并发布 jiu-gencode 二进制(回滚路径随 release 资产
自动下载),部署到 /opt/jiu/backend/,对旧版回滚做存在性判断优雅跳过。
新增 deploy/jiu-gencode.sh 封装自动读 production.env,线上生码从此
一条 ssh 即可,无需本地交叉编译 + scp。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y2Wdwo7SmgBJU37cBrkhPK
2026-06-19 14:04:14 +08:00

31 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# jiu-gencode.sh — 平台方在 EC2 上批量生成兑换券(激活码)的便捷封装。
#
# 自动读取 /opt/jiu/config/production.env 的数据库连接,调用同目录的
# jiu-gencode 二进制写入码池 license_codes。随 server 发版部署到
# /opt/jiu/backend/,无需再本地交叉编译 + scp。
#
# 远程一行用法(在你的 Mac 上):
# ssh -i ~/.ssh/wangjia.pem ec2-user@18.136.60.128 \
# '/opt/jiu/backend/jiu-gencode.sh -type annual -days 365 -count 100 -batch 2026-summer'
# ssh -i ~/.ssh/wangjia.pem ec2-user@18.136.60.128 \
# '/opt/jiu/backend/jiu-gencode.sh -type trial -days 7 -count 1'
#
# 参数透传给 jiu-gencode-type trial|monthly|annual|lifetime -days N(0=永久)
# -devices N(0=不改门店现值) -count N -batch <批次> -note <备注>
set -euo pipefail
ENV_FILE="${JIU_ENV_FILE:-/opt/jiu/config/production.env}"
BIN="$(dirname "$0")/jiu-gencode"
[ -f "$ENV_FILE" ] || { echo "jiu-gencode: 找不到环境文件 $ENV_FILE" >&2; exit 1; }
[ -x "$BIN" ] || { echo "jiu-gencode: 找不到可执行文件 $BIN" >&2; exit 1; }
# 加载 production.env:跳过注释/空行,逐行 export(不回显,避免泄漏密钥)。
while IFS= read -r line; do
case "$line" in \#*|'') continue ;; esac
export "$line"
done < "$ENV_FILE"
exec "$BIN" "$@"