Files
Mofox-Core/entrypoint.sh
infinitycat 1934aa30f2 build:为 Docker 部署添加 entrypoint 脚本
- 新增 entrypoint.sh脚本,用于在容器启动时执行初始化操作
- 修改 Dockerfile,使用 entrypoint.sh 作为入口点
- 脚本功能包括:
  - 创建配置目录
  - 复制 bot配置文件
  - 复制环境配置文件
2025-04-02 15:24:12 +08:00

55 lines
1.5 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/sh
set -e # 遇到任何错误立即退出
# 定义常量
TEMPLATE_DIR="./template"
CONFIG_DIR="./config"
TARGET_ENV_FILE="./.env"
# 步骤 1: 创建 config 目录
if [ ! -d "$CONFIG_DIR" ]; then
echo "🛠️ 创建配置目录: $CONFIG_DIR"
mkdir -p "$CONFIG_DIR"
chmod 755 "$CONFIG_DIR" # 设置目录权限(按需修改)
else
echo " 配置目录已存在,跳过创建: $CONFIG_DIR"
fi
# 步骤 2: 复制 bot 配置文件
BOT_TEMPLATE="$TEMPLATE_DIR/bot_config_template.toml"
BOT_CONFIG="$CONFIG_DIR/bot_config.toml"
if [ -f "$BOT_TEMPLATE" ]; then
if [ ! -f "$BOT_CONFIG" ]; then
echo "📄 生成 Bot 配置文件: $BOT_CONFIG"
cp "$BOT_TEMPLATE" "$BOT_CONFIG"
chmod 644 "$BOT_CONFIG" # 设置文件权限(按需修改)
else
echo " Bot 配置文件已存在,跳过生成: $BOT_CONFIG"
fi
else
echo "❌ 错误:模板文件不存在: $BOT_TEMPLATE" >&2
exit 1
fi
# 步骤 3: 复制环境文件
ENV_TEMPLATE="$TEMPLATE_DIR/template.env"
ENV_TARGET="$TARGET_ENV_FILE"
if [ -f "$ENV_TEMPLATE" ]; then
if [ ! -f "$ENV_TARGET" ]; then
echo "🔧 生成环境配置文件: $ENV_TARGET"
cp "$ENV_TEMPLATE" "$ENV_TARGET"
chmod 600 "$ENV_TARGET" # 敏感文件建议更严格权限
else
echo " 环境文件已存在,跳过生成: $ENV_TARGET"
fi
else
echo "❌ 错误:模板文件不存在: $ENV_TEMPLATE" >&2
exit 1
fi
echo "✅ 所有初始化完成!"
# 执行 Docker CMD 命令
exec "$@"