Files
blog/write-server/entrypoint.sh
T
2026-06-22 14:59:24 +08:00

38 lines
1.1 KiB
Bash

#!/bin/sh
# Docker entrypoint script
# 创建必要的子目录(以 root 身份)
mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
# 修复 recycle 目录权限
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
# 自动哈希明文密码(users.json 中没有 salt 字段时)
if [ -f "/app/users.json" ]; then
if ! grep -q '"salt"' /app/users.json 2>/dev/null; then
echo "[entrypoint] 检测到明文密码,自动哈希..."
node /app/scripts/hash-users.js
echo "[entrypoint] 密码哈希完成"
fi
fi
# 修复博客目录权限
if [ -d "/blog" ]; then
chown -R nextjs:nodejs /blog
fi
# 配置 git
su-exec nextjs git config --global user.name "Write Server" 2>/dev/null
su-exec nextjs git config --global user.email "write@usj.cc" 2>/dev/null
su-exec nextjs git config --global --add safe.directory /blog 2>/dev/null
# 修复 SSH 密钥权限
if [ -d "/home/nextjs/.ssh" ]; then
chown -R nextjs:nodejs /home/nextjs/.ssh
chmod 700 /home/nextjs/.ssh 2>/dev/null
chmod 600 /home/nextjs/.ssh/* 2>/dev/null
fi
# 以 nextjs 用户启动应用
exec su-exec nextjs "$@"