镜像制作

This commit is contained in:
2025-11-24 11:50:15 +08:00
parent 12592c5a24
commit 07bd166257
53 changed files with 3822 additions and 2140 deletions

View File

@@ -14,12 +14,12 @@ YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 数据库配置
DB_HOST="localhost"
DB_PORT="3306"
DB_USER="root"
DB_PASSWORD="123456"
DB_NAME="school_news"
# 数据库配置(优先使用环境变量)
DB_HOST="${DB_HOST:-localhost}"
DB_PORT="${DB_PORT:-3306}"
DB_USER="${DB_USER:-root}"
DB_PASSWORD="${DB_PASSWORD:-123456}"
DB_NAME="${DB_NAME:-school_news}"
# 脚本目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -101,19 +101,6 @@ execute_init_script() {
import_sensitive_words() {
print_message $BLUE "开始导入敏感词数据..."
# 检查conda是否可用
if ! command -v conda &> /dev/null; then
print_message $YELLOW "conda命令未找到跳过敏感词导入"
return 0
fi
# 检查schoolNewsCrawler环境是否存在
if ! conda env list | grep -q "schoolNewsCrawler"; then
print_message $YELLOW "conda环境 'schoolNewsCrawler' 不存在,跳过敏感词导入"
print_message $YELLOW "提示: 可以使用以下命令创建环境: conda create -n schoolNewsCrawler python=3.10"
return 0
fi
# 切换到敏感词脚本目录
local sensitive_dir="$SCRIPT_DIR/sensitiveData"
if [ ! -d "$sensitive_dir" ]; then
@@ -121,25 +108,63 @@ import_sensitive_words() {
return 0
fi
if [ ! -f "$sensitive_dir/writeWord.py" ]; then
print_message $YELLOW "敏感词脚本不存在: $sensitive_dir/writeWord.py"
# 检查Shell脚本是否存在
if [ -f "$sensitive_dir/importSensitiveWords.sh" ]; then
print_message $BLUE "使用Shell脚本导入敏感词"
cd "$sensitive_dir"
# 导出数据库配置环境变量
export DB_HOST="$DB_HOST"
export DB_PORT="$DB_PORT"
export DB_USER="$DB_USER"
export DB_PASSWORD="$DB_PASSWORD"
export DB_NAME="$DB_NAME"
export AUTO_CONFIRM=true
bash importSensitiveWords.sh -y
if [ $? -eq 0 ]; then
print_message $GREEN "敏感词数据导入成功"
else
print_message $YELLOW "敏感词数据导入失败,但不影响系统运行"
fi
cd "$SCRIPT_DIR"
return 0
fi
print_message $BLUE "激活conda环境: schoolNewsCrawler"
cd "$sensitive_dir"
# 使用conda run来在指定环境中执行命令添加-y参数自动确认
conda run -n schoolNewsCrawler python writeWord.py -y
if [ $? -eq 0 ]; then
print_message $GREEN "敏感词数据导入成功"
else
print_message $YELLOW "敏感词数据导入失败,但不影响系统运行"
# 兼容旧的Python脚本如果Shell脚本不存在
if [ -f "$sensitive_dir/writeWord.py" ]; then
print_message $YELLOW "使用Python脚本导入敏感词建议使用Shell版本"
# 检查conda是否可用
if ! command -v conda &> /dev/null; then
print_message $YELLOW "conda命令未找到跳过敏感词导入"
return 0
fi
# 检查schoolNewsCrawler环境是否存在
if ! conda env list | grep -q "schoolNewsCrawler"; then
print_message $YELLOW "conda环境 'schoolNewsCrawler' 不存在,跳过敏感词导入"
return 0
fi
cd "$sensitive_dir"
conda run -n schoolNewsCrawler python writeWord.py -y
if [ $? -eq 0 ]; then
print_message $GREEN "敏感词数据导入成功"
else
print_message $YELLOW "敏感词数据导入失败,但不影响系统运行"
fi
cd "$SCRIPT_DIR"
return 0
fi
# 返回脚本目录
cd "$SCRIPT_DIR"
# 如果两个脚本都不存在
print_message $YELLOW "敏感词导入脚本不存在,跳过导入"
print_message $YELLOW "提示: 可以使用 importSensitiveWords.sh (推荐) 或 writeWord.py"
}
# 验证初始化结果