Files
iiEsaywebUI/scripts/fix_user_agent_aggressive.sh
2026-02-19 18:12:09 +00:00

60 lines
3.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
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
# Агрессивное исправление бага с User-Agent в Open WebUI
# Ищет и исправляет проблемную строку во всех возможных местах
echo "=== АГРЕССИВНОЕ ИСПРАВЛЕНИЕ USER-AGENT ==="
echo ""
# Находим все файлы с проблемной строкой
echo "Поиск всех файлов с проблемной строкой User-Agent..."
PROBLEM_FILES=$(docker exec open-webui find /app/backend -name "*.py" -type f -exec grep -l "github.com/open-webui" {} \; 2>/dev/null)
if [ -z "$PROBLEM_FILES" ]; then
echo "Файлы не найдены через docker exec, пробуем другой способ..."
# Альтернативный способ - ищем через grep в контейнере
docker exec open-webui sh -c 'find /app/backend -name "*.py" -type f | xargs grep -l "github.com/open-webui" 2>/dev/null' | while read pyfile; do
if [ -n "$pyfile" ]; then
echo "Исправление файла: $pyfile"
docker exec open-webui sed -i "s/' (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot'/'Open-WebUI-RAG-Bot'/g" "$pyfile"
docker exec open-webui sed -i 's/" (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot"/"Open-WebUI-RAG-Bot"/g' "$pyfile"
docker exec open-webui sed -i "s/ (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot/Open-WebUI-RAG-Bot/g" "$pyfile"
docker exec open-webui sed -i 's/"User-Agent": " [^"]*RAG Bot"/"User-Agent": "Open-WebUI-RAG-Bot"/g' "$pyfile"
docker exec open-webui sed -i "s/'User-Agent': ' [^']*RAG Bot'/'User-Agent': 'Open-WebUI-RAG-Bot'/g" "$pyfile"
fi
done
else
echo "$PROBLEM_FILES" | while read pyfile; do
echo "Исправление файла: $pyfile"
docker exec open-webui sed -i "s/' (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot'/'Open-WebUI-RAG-Bot'/g" "$pyfile"
docker exec open-webui sed -i 's/" (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot"/"Open-WebUI-RAG-Bot"/g' "$pyfile"
docker exec open-webui sed -i "s/ (https:\/\/github\.com\/open-webui\/open-webui) RAG Bot/Open-WebUI-RAG-Bot/g" "$pyfile"
docker exec open-webui sed -i 's/"User-Agent": " [^"]*RAG Bot"/"User-Agent": "Open-WebUI-RAG-Bot"/g' "$pyfile"
docker exec open-webui sed -i "s/'User-Agent': ' [^']*RAG Bot'/'User-Agent': 'Open-WebUI-RAG-Bot'/g" "$pyfile"
done
fi
# Очищаем кеш Python
echo ""
echo "Очистка кеша Python..."
docker exec open-webui find /app/backend -name "*.pyc" -delete 2>/dev/null
docker exec open-webui find /app/backend -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
# Проверяем результат
echo ""
echo "Проверка результата..."
RAG_BOT_COUNT=$(docker exec open-webui grep -r "github.com/open-webui.*RAG Bot" /app/backend 2>/dev/null | wc -l)
if [ "$RAG_BOT_COUNT" -eq 0 ]; then
echo "✓ Проблемная строка не найдена - патч применен успешно"
else
echo "⚠ Найдено вхождений проблемной строки: $RAG_BOT_COUNT"
echo "Проблемные файлы:"
docker exec open-webui grep -r "github.com/open-webui.*RAG Bot" /app/backend 2>/dev/null | cut -d: -f1 | sort -u
fi
echo ""
echo "Перезапуск Open WebUI..."
docker restart open-webui
echo ""
echo "Готово! Подождите 15 секунд и проверьте поиск."