From 7bb88f2c2478fa54e3a2bb0e1fa0ae0039b851b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9=20=D0=9B=D0=B8?= =?UTF-8?q?=D1=82=D0=B2=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Sun, 26 Apr 2026 10:51:30 +0300 Subject: [PATCH] Auto-update existing Telegram bot during upgrade --- install.sh | 26 ++++++++++++++++++++++++++ tests/test_bot_features.py | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/install.sh b/install.sh index 0211851..afb8d24 100755 --- a/install.sh +++ b/install.sh @@ -963,6 +963,31 @@ bot_service_status() { fi } +auto_update_bot_if_possible() { + [ -d "$SCRIPT_DIR/gotelegram-bot" ] || return 0 + [ "$(bot_service_status)" = "not_installed" ] && return 0 + [ -f "$BOT_DIR/.env" ] || return 0 + + local needs_update=0 + [ -f "$SCRIPT_DIR/gotelegram-bot/bot.py" ] && \ + ! cmp -s "$SCRIPT_DIR/gotelegram-bot/bot.py" "$BOT_DIR/bot.py" && needs_update=1 + [ -f "$SCRIPT_DIR/gotelegram-bot/i18n.py" ] && \ + ! cmp -s "$SCRIPT_DIR/gotelegram-bot/i18n.py" "$BOT_DIR/i18n.py" && needs_update=1 + [ -f "$SCRIPT_DIR/gotelegram-bot/requirements.txt" ] && \ + ! cmp -s "$SCRIPT_DIR/gotelegram-bot/requirements.txt" "$BOT_DIR/requirements.txt" && needs_update=1 + + local lang_file lang_name + for lang_file in "$SCRIPT_DIR"/gotelegram-bot/lang/*.json; do + [ -e "$lang_file" ] || continue + lang_name=$(basename "$lang_file") + ! cmp -s "$lang_file" "$BOT_DIR/lang/$lang_name" && needs_update=1 + done + + [ "$needs_update" = "1" ] || return 0 + bot_install >/dev/null 2>&1 || \ + log_warning "Telegram bot auto-update failed; run menu 12 → Telegram-bot → Install/update" +} + menu_bot() { local st st=$(bot_service_status) @@ -1788,6 +1813,7 @@ main() { fi auto_migrate_legacy_state || true + auto_update_bot_if_possible || true auto_install_admin_web_if_possible || true # First-run language picker (before banner so banner appears in chosen lang) diff --git a/tests/test_bot_features.py b/tests/test_bot_features.py index 1d2e21b..c5c6c66 100644 --- a/tests/test_bot_features.py +++ b/tests/test_bot_features.py @@ -7,6 +7,7 @@ from pathlib import Path ROOT = Path(__file__).resolve().parents[1] BOT_PATH = ROOT / "gotelegram-bot" / "bot.py" CATALOG_PATH = ROOT / "templates_catalog.json" +INSTALL_PATH = ROOT / "install.sh" class BotFeatureTests(unittest.TestCase): @@ -79,6 +80,23 @@ class BotFeatureTests(unittest.TestCase): self.assertIn("await get_telemt_version()", body) self.assertNotIn('sh("telemt", "--version")', body) + def test_installer_auto_updates_existing_bot_files(self): + source = INSTALL_PATH.read_text(encoding="utf-8") + auto_body = re.search( + r"auto_update_bot_if_possible\(\).*?(?=\n\n[A-Za-z0-9_]+\(\) |\n\n#)", + source, + flags=re.S, + ) + self.assertIsNotNone(auto_body) + + auto_text = auto_body.group(0) + self.assertIn('bot_service_status', auto_text) + self.assertIn('bot_install', auto_text) + self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/bot.py" "$BOT_DIR/bot.py"', auto_text) + self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/i18n.py" "$BOT_DIR/i18n.py"', auto_text) + self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/requirements.txt" "$BOT_DIR/requirements.txt"', auto_text) + self.assertIn('auto_migrate_legacy_state || true\n auto_update_bot_if_possible || true\n auto_install_admin_web_if_possible || true', source) + if __name__ == "__main__": unittest.main()