fix(v2.4.4): robust venv creation + UTF-8 safe install frame

- install.sh bot_install: always ensure python3-venv+pip, verify pip exists, check pip install exit code, sanity-check imports
- install.sh: replace box-frame with simple bullet lines (printf %-Ns was byte-counting, breaking Cyrillic UTF-8)
- common.sh: 2.4.4
- bot.py: 2.4.4
This commit is contained in:
anten-ka
2026-04-10 14:03:28 +03:00
parent 4b63b79184
commit 3919f201f5
3 changed files with 58 additions and 17 deletions

View File

@@ -100,7 +100,7 @@ logger = logging.getLogger(__name__)
# CONFIGURATION # CONFIGURATION
# ============================================================================ # ============================================================================
GOTELEGRAM_VERSION = "2.4.3" GOTELEGRAM_VERSION = "2.4.4"
GOTELEGRAM_CONFIG = "/opt/gotelegram/config.json" GOTELEGRAM_CONFIG = "/opt/gotelegram/config.json"
TELEMT_CONFIG = "/etc/telemt/config.toml" TELEMT_CONFIG = "/etc/telemt/config.toml"
TELEMT_SERVICE = "telemt" TELEMT_SERVICE = "telemt"

71
install.sh Executable file → Normal file
View File

@@ -751,11 +751,21 @@ menu_bot() {
bot_install() { bot_install() {
log_step "$(t bot_install_step)" log_step "$(t bot_install_step)"
# Python # Python + venv + pip (always ensure — python3 can be present without venv/pip)
if ! command -v python3 &>/dev/null; then local need_py=0
command -v python3 &>/dev/null || need_py=1
# python3-venv not having its own command; probe by trying 'python3 -m venv --help'
if ! python3 -m venv --help &>/dev/null; then need_py=1; fi
# pip check
if ! python3 -m pip --version &>/dev/null; then need_py=1; fi
if [ "$need_py" = "1" ]; then
log_info "$(t bot_install_python)" log_info "$(t bot_install_python)"
if command -v apt-get &>/dev/null; then if command -v apt-get &>/dev/null; then
apt-get update -qq && apt-get install -y -qq python3 python3-pip python3-venv apt-get update -qq
# python3-full pulls venv, pip, distutils — safer than piece-by-piece
apt-get install -y -qq python3 python3-venv python3-pip python3-full 2>/dev/null || \
apt-get install -y -qq python3 python3-venv python3-pip
elif command -v dnf &>/dev/null; then elif command -v dnf &>/dev/null; then
dnf install -y -q python3 python3-pip dnf install -y -q python3 python3-pip
elif command -v yum &>/dev/null; then elif command -v yum &>/dev/null; then
@@ -786,13 +796,45 @@ bot_install() {
[ -f "$SCRIPT_DIR/templates_catalog.json" ] && \ [ -f "$SCRIPT_DIR/templates_catalog.json" ] && \
cp "$SCRIPT_DIR/templates_catalog.json" "$GOTELEGRAM_DIR/" cp "$SCRIPT_DIR/templates_catalog.json" "$GOTELEGRAM_DIR/"
# Venv # Venv — create, and verify pip exists (python3-venv can silently create broken venv)
if [ ! -d "$BOT_DIR/venv" ]; then if [ ! -d "$BOT_DIR/venv" ] || [ ! -x "$BOT_DIR/venv/bin/pip" ]; then
log_info "$(t bot_create_venv)" log_info "$(t bot_create_venv)"
python3 -m venv "$BOT_DIR/venv" rm -rf "$BOT_DIR/venv"
if ! python3 -m venv "$BOT_DIR/venv" 2>/tmp/venv_err; then
log_error "venv creation failed: $(cat /tmp/venv_err 2>/dev/null)"
# Try to fix by reinstalling python3-venv
if command -v apt-get &>/dev/null; then
apt-get install --reinstall -y -qq python3-venv python3-pip python3-full 2>/dev/null || true
python3 -m venv "$BOT_DIR/venv" || { log_error "venv still broken, aborting"; return 1; }
else
return 1
fi fi
fi
fi
if [ ! -x "$BOT_DIR/venv/bin/pip" ]; then
log_info "bootstrapping pip via ensurepip..."
"$BOT_DIR/venv/bin/python" -m ensurepip --upgrade 2>/dev/null || true
fi
if [ ! -x "$BOT_DIR/venv/bin/pip" ]; then
log_error "pip missing in venv — install python3-venv manually: apt install python3-venv python3-pip"
return 1
fi
log_info "$(t bot_install_deps)" log_info "$(t bot_install_deps)"
"$BOT_DIR/venv/bin/pip" install -r "$BOT_DIR/requirements.txt" -q if ! "$BOT_DIR/venv/bin/pip" install -r "$BOT_DIR/requirements.txt" -q 2>/tmp/pip_err; then
log_error "pip install failed:"
tail -n 5 /tmp/pip_err >&2
return 1
fi
# Sanity check: verify critical imports succeed
if ! "$BOT_DIR/venv/bin/python" -c "import telegram, toml, dotenv" 2>/tmp/imp_err; then
log_error "dependency import check failed:"
cat /tmp/imp_err >&2
return 1
fi
# Configuration # Configuration
if [ ! -f "$BOT_DIR/.env" ]; then if [ ! -f "$BOT_DIR/.env" ]; then
@@ -862,14 +904,13 @@ SVCEOF
has_ids=$(grep "^ALLOWED_IDS=" "$BOT_DIR/.env" 2>/dev/null | cut -d= -f2) has_ids=$(grep "^ALLOWED_IDS=" "$BOT_DIR/.env" 2>/dev/null | cut -d= -f2)
if [ -z "$has_ids" ]; then if [ -z "$has_ids" ]; then
echo "" echo ""
echo -e " ${YELLOW}╔══════════════════════════════════════════════════════╗${NC}" # Simple bullet-style block (no box — printf %-Ns breaks on UTF-8 multibyte chars)
printf " ${YELLOW}${NC} ${BOLD}%-52s${NC} ${YELLOW}${NC}\n" "$(t bot_wait_admin_title)" echo -e " ${YELLOW}${NC} ${BOLD}$(t bot_wait_admin_title)${NC}"
echo -e " ${YELLOW}${NC} ${YELLOW}${NC}" echo ""
printf " ${YELLOW}${NC} %s ${CYAN}/start${NC}%*s${YELLOW}${NC}\n" "$(t bot_wait_admin_msg1)" 0 "" echo -e " $(t bot_wait_admin_msg1) ${CYAN}/start${NC}"
printf " ${YELLOW}${NC} %-52s ${YELLOW}${NC}\n" "$(t bot_wait_admin_msg2)" echo -e " $(t bot_wait_admin_msg2)"
echo -e " ${YELLOW}${NC} ${YELLOW}${NC}" echo ""
printf " ${YELLOW}${NC} ${DIM}%-52s${NC} ${YELLOW}${NC}\n" "$(t bot_wait_admin_skip)" echo -e " ${DIM}$(t bot_wait_admin_skip)${NC}"
echo -e " ${YELLOW}╚══════════════════════════════════════════════════════╝${NC}"
echo "" echo ""
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')

View File

@@ -3,7 +3,7 @@
# Colors, logging, spinner, system helpers, v1 compat, i18n-aware # Colors, logging, spinner, system helpers, v1 compat, i18n-aware
# ── Version ─────────────────────────────────────────────────────────────────── # ── Version ───────────────────────────────────────────────────────────────────
GOTELEGRAM_VERSION="2.4.3" GOTELEGRAM_VERSION="2.4.4"
GOTELEGRAM_NAME="GoTelegram" GOTELEGRAM_NAME="GoTelegram"
# ── Пути ────────────────────────────────────────────────────────────────────── # ── Пути ──────────────────────────────────────────────────────────────────────