Files
worklog/package.sh
T
azzz 5c4b8d84ed WorkLog 全量合并:密码登录体系、每日自动备份、发信日志、活动邮件通知一键参加
- 认证:注册设密码(双次确认,>=10 位)、密码/验证码双模式登录、邮箱验证码找回重置密码
- 备份:服务内置每天 23:00 自动备份到 data/backups/(默认保留 14 份),backup_db.py 支持手动/crontab
- 发信日志:logs/mail-YYYYMM.log 记录每次发信成败与失败原因(535 认证失败/断连细分),按月滚动保留 6 个月
- 通知:发起活动群发邮件(参与不发),邮件内一键参加(一次性令牌、7 天有效、私密活动不群发)
- 前端:报错细分(字段/类型/状态码全中文)、验证码按钮 60 秒防连点
- 部署:Dockerfile + entrypoint(seed 机制)、限流/唯一索引/令牌摘要等安全加固
- 工具:repair_db/clear_db 的 SQL 全部常量化,无动态拼接
- 测试:43 项全覆盖(注册/登录/活动/通知/备份/日志/安全)
2026-10-29 19:00:48 +08:00

69 lines
2.6 KiB
Bash
Raw 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
# 打包脚本:停掉本地正在运行的 WorkLog 服务,然后打成 zip(不含数据库/日志/运行产物)。
# 用法:bash package.sh (产物:worklog-<日期>.zip,放在项目同级目录)
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_NAME="WorkLog"
PORT="${WORKLOG_PORT:-37777}"
PYTHON="${PYTHON:-python}"
# ---------- 1. 关闭本地服务 ----------
# 优先按端口找进程(Windows 用 netstat,Linux/mac 用 lsof/ss)
stopped=0
if command -v netstat.exe >/dev/null 2>&1 && command -v taskkill.exe >/dev/null 2>&1; then
pids=$(netstat.exe -ano | grep -E "TCP.*:${PORT}\s.*LISTENING" | awk '{print $5}' | sort -u || true)
for pid in $pids; do
if [ -n "$pid" ] && [ "$pid" != "0" ]; then
echo "停止进程 PID=$pid (端口 $PORT)"
taskkill.exe //F //PID "$pid" || true
stopped=1
fi
done
else
if command -v lsof >/dev/null 2>&1; then
pids=$(lsof -ti tcp:"$PORT" 2>/dev/null || true)
elif command -v ss >/dev/null 2>&1; then
pids=$(ss -lptn "sport = :$PORT" 2>/dev/null | grep -oP 'pid=\K[0-9]+' | sort -u)
else
pids=""
fi
for pid in $pids; do
echo "停止进程 PID=$pid (端口 $PORT)"
kill -9 "$pid" 2>/dev/null || true
stopped=1
done
fi
[ "$stopped" = "1" ] && echo "本地服务已停止" || echo "端口 $PORT 上没有运行中的服务"
sleep 1
# ---------- 2. 打包 ----------
STAMP="$(date +%Y%m%d-%H%M%S)"
ZIP_NAME="worklog-${STAMP}.zip"
# 用 Python zipfile 打包(Windows Git Bash 无 zip 命令),排除数据库/日志/缓存
"$PYTHON" - "$PROJECT_DIR" "$ZIP_NAME" << 'PYEOF'
import fnmatch, os, sys, zipfile
project, zip_name = os.path.abspath(sys.argv[1]), sys.argv[2]
out_path = os.path.join(os.path.dirname(project), zip_name)
skip_dirs = {"__pycache__", ".venv", ".git", "data"}
skip_files = {".env", ".run-dev.log"}
skip_ext = (".pyc", ".zip", ".log")
with zipfile.ZipFile(out_path, "w", zipfile.ZIP_DEFLATED) as zf:
for root, dirs, files in os.walk(project):
dirs[:] = [d for d in dirs if d not in skip_dirs]
for f in files:
if (f in skip_files or f.endswith(skip_ext)
or (f.startswith('.env.') and f != '.env.example')
or any(fnmatch.fnmatch(f, pattern) for pattern in ('*.db', '*.db-*', '*.sqlite', '*.sqlite-*', '*.sqlite3', '*.sqlite3-*', '*.bak*'))):
continue
full = os.path.join(root, f)
arc = os.path.relpath(full, project).replace(os.sep, "/")
zf.write(full, arc)
print("packed ->", out_path)
PYEOF
echo "打包完成:$(dirname "$PROJECT_DIR")/$ZIP_NAME"