cv-2026/scripts/regen_telegram_session.sh

45 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerate a Telegram session string.
# Reads TELEGRAM_API_ID / TELEGRAM_API_HASH from the project .env,
# then runs the generator from the telegram-mcp install.
#
# Usage:
# bash scripts/regen_telegram_session.sh # regenerate usulsu (main)
# bash scripts/regen_telegram_session.sh helper # regenerate samuishechka
#
# After running, paste the printed session string into the project .env:
# usulsu → TELEGRAM_SESSION_STRING=...
# helper → TELEGRAM_SESSION_STRING_HELPER=...
set -euo pipefail
ACCOUNT="${1:-}" # "helper" for samuishechka, empty for usulsu
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TELEGRAM_DIR="/projects/my-utils/telegram"
if [ ! -f "$PROJECT_ROOT/.env" ]; then
echo "missing $PROJECT_ROOT/.env" >&2
exit 1
fi
set -a
. "$PROJECT_ROOT/.env"
set +a
if [ -z "${TELEGRAM_API_ID:-}" ] || [ -z "${TELEGRAM_API_HASH:-}" ]; then
echo "TELEGRAM_API_ID / TELEGRAM_API_HASH missing in $PROJECT_ROOT/.env" >&2
exit 1
fi
if [ "$ACCOUNT" = "helper" ]; then
echo "Regenerating session for samuishechka (helper account)."
echo "When prompted for label, enter: helper"
else
echo "Regenerating session for usulsu (main account)."
echo "When prompted for label, leave empty (press Enter)."
fi
echo ""
cd "$TELEGRAM_DIR"
exec .venv/bin/python session_string_generator.py --qr "$@"