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

42 lines
1.2 KiB
Bash

#!/bin/sh
# Docker entrypoint script
# 修复挂载目录权限后以 nextjs 用户启动应用
# 创建必要的子目录(以 root 身份)
mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
# 修复 recycle 目录权限
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
# 修复博客目录权限(让 nextjs 用户可写)
if [ -d "/blog" ]; then
chown nextjs:nodejs /blog
fi
if [ -d "/blog/content" ]; then
chown -R nextjs:nodejs /blog/content
fi
if [ -d "/blog/static" ]; then
chown -R nextjs:nodejs /blog/static
fi
if [ -d "/blog/.git" ]; then
chown -R nextjs:nodejs /blog/.git
fi
if [ -f "/blog/hugo.toml" ]; then
chown nextjs:nodejs /blog/hugo.toml
fi
# 配置 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
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 "$@"