Files
blog/write-server/entrypoint.sh
T

38 lines
1.2 KiB
Bash
Raw Normal View History

2026-06-21 22:30:54 +08:00
#!/bin/sh
# Docker entrypoint script
# 修复挂载目录权限后以 nextjs 用户启动应用
# 创建必要的子目录(以 root 身份)
mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
2026-06-21 23:28:31 +08:00
# 修复 recycle 目录权限
2026-06-21 22:30:54 +08:00
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
2026-06-21 23:28:31 +08:00
# 修复博客目录权限(让 nextjs 用户可写)
if [ -d "/blog/content" ]; then
chown -R nextjs:nodejs /blog/content
fi
if [ -d "/blog/static" ]; then
chown -R nextjs:nodejs /blog/static
fi
2026-06-21 23:58:29 +08:00
if [ -d "/blog/.git" ]; then
chown -R nextjs:nodejs /blog/.git
fi
2026-06-21 23:28:31 +08:00
if [ -f "/blog/hugo.toml" ]; then
chown nextjs:nodejs /blog/hugo.toml
fi
2026-06-21 22:56:07 +08:00
2026-06-21 23:58:29 +08:00
# 配置 git(容器内 nextjs 用户)
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
2026-06-22 00:41:05 +08:00
su-exec nextjs git config --global --add safe.directory /blog 2>/dev/null
2026-06-21 23:58:29 +08:00
2026-06-22 00:52:51 +08:00
# 修复 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
2026-06-21 23:28:31 +08:00
# 以 nextjs 用户启动应用
exec su-exec nextjs "$@"