diff --git a/install.sh b/install.sh index 08305de..3344fd1 100644 --- a/install.sh +++ b/install.sh @@ -22,19 +22,25 @@ REPO_RAW="${GOTETELEGRAM_REPO_RAW:-https://raw.githubusercontent.com/anten-ka/go echo -e "${GREEN}[*] GoTelegram Bot — установка...${NC}" -# Зависимости +# Зависимости (python3, curl, git для приватного репо) if ! command -v python3 &>/dev/null; then if command -v apt-get &>/dev/null; then - apt-get update && apt-get install -y python3 python3-pip python3-venv curl + apt-get update && apt-get install -y python3 python3-pip python3-venv curl git elif command -v dnf &>/dev/null; then - dnf install -y python3 python3-pip python3-virtualenv curl 2>/dev/null || dnf install -y python3 python3-pip curl + dnf install -y python3 python3-pip python3-virtualenv curl git 2>/dev/null || dnf install -y python3 python3-pip curl git elif command -v yum &>/dev/null; then - yum install -y python3 python3-pip curl + yum install -y python3 python3-pip curl git else echo -e "${RED}Установите python3 и curl.${NC}" exit 1 fi fi +if [ -n "$GITHUB_TOKEN" ] && ! command -v git &>/dev/null; then + echo -e "${GREEN}[*] Установка git для клонирования приватного репо...${NC}" + if command -v apt-get &>/dev/null; then apt-get update && apt-get install -y git; fi + if command -v dnf &>/dev/null; then dnf install -y git; fi + if command -v yum &>/dev/null; then yum install -y git; fi +fi if ! command -v docker &>/dev/null; then echo -e "${YELLOW}[!] Docker не найден. Нужен для /install в боте.${NC}" fi @@ -42,34 +48,30 @@ fi mkdir -p "$BOT_DIR" cd "$BOT_DIR" -# Скачивание файлов бота по raw URL (с токеном для приватного репо) -fetch_file() { - local f="$1" - if [ -n "$GITHUB_TOKEN" ]; then - curl -sL -f -H "Authorization: token $GITHUB_TOKEN" "$REPO_RAW/gotelegram-bot/$f" -o "$BOT_DIR/$f" 2>/dev/null && return 0 - fi - curl -sL -f "$REPO_RAW/gotelegram-bot/$f" -o "$BOT_DIR/$f" 2>/dev/null && return 0 - return 1 -} - +# Получение файлов бота: при токене — только git clone (raw для приватного не работает) if [ ! -f "$BOT_DIR/bot.py" ]; then echo -e "${GREEN}[*] Загрузка файлов из репозитория...${NC}" - OK=1 - for f in bot.py requirements.txt config.example.env; do - fetch_file "$f" || { OK=0; break; } - done - if [ "$OK" -eq 0 ] && [ -n "$GITHUB_TOKEN" ] && command -v git &>/dev/null; then - echo -e "${GREEN}[*] Клонирование по токену...${NC}" + if [ -n "$GITHUB_TOKEN" ] && command -v git &>/dev/null; then TMP="/tmp/gotelegram_pro_$$" - git clone --depth 1 --branch main "https://${GITHUB_TOKEN}@github.com/anten-ka/gotelegram_pro.git" "$TMP" 2>/dev/null && { + if git clone --depth 1 --branch main "https://${GITHUB_TOKEN}@github.com/anten-ka/gotelegram_pro.git" "$TMP" 2>/tmp/gotelegram_clone_err_$$; then cp -r "$TMP/gotelegram-bot"/* "$BOT_DIR/" rm -rf "$TMP" - } + else + echo -e "${RED}Ошибка клонирования:${NC}" + cat /tmp/gotelegram_clone_err_$$ 2>/dev/null + rm -rf "$TMP" /tmp/gotelegram_clone_err_$$ 2>/dev/null + exit 1 + fi + rm -f /tmp/gotelegram_clone_err_$$ + else + # Публичный репо — пробуем curl + for f in bot.py requirements.txt config.example.env; do + curl -sL -f "$REPO_RAW/gotelegram-bot/$f" -o "$BOT_DIR/$f" 2>/dev/null || true + done fi if [ ! -f "$BOT_DIR/bot.py" ]; then echo -e "${RED}Не удалось загрузить файлы. Для приватного репо запустите с токеном:${NC}" echo -e " ${YELLOW}gotelegram ВАШ_GITHUB_ТОКЕН${NC}" - echo -e " или: ${YELLOW}GITHUB_TOKEN=ВАШ_ТОКЕН gotelegram${NC}" exit 1 fi fi