#!/bin/bash REPO_URL="https://git.bitmaster.cc/BitMaster/tesla-bot.git" CLONE_DIR="tesla-bot" CRON_NAME="tesla-inventory-bot" GREEN="\e[32m" RED="\e[31m" YELLOW="\e[33m" NC="\e[0m" PIP_OK=false PYTHON_OK=false function banner() { echo -e "${GREEN}" echo "==============================" echo "🚗 Tesla Inventory Bot Setup (No Docker)" echo "==============================" echo -e "${NC}" } function check_requirements() { echo -e "${YELLOW}...checking system status...${NC}" echo -n "📦 Python3: " if command -v python3 &>/dev/null; then echo -e "${GREEN}Installed${NC}" PYTHON_OK=true else echo -e "${RED}Missing${NC}" fi echo -n "📦 pip3: " if command -v pip3 &>/dev/null; then echo -e "${GREEN}Installed${NC}" PIP_OK=true else echo -e "${RED}Missing${NC}" fi echo -n "📁 Project folder '$CLONE_DIR': " if [ -d "$CLONE_DIR" ]; then echo -e "${GREEN}Exists${NC}" else echo -e "${RED}Not present${NC}" fi if [ "$PYTHON_OK" = false ]; then echo -e "${YELLOW}❓ Python3 is required. Install now? [Y/n]${NC}" read -rp "> " confirm; confirm="${confirm,,}" if [[ "$confirm" =~ ^(y|yes| )?$ ]]; then sudo apt update && sudo apt install -y python3 else echo -e "${RED}⚠️ Cannot proceed without Python3. Exiting.${NC}"; exit 1 fi fi if [ "$PIP_OK" = false ]; then echo -e "${YELLOW}❓ pip3 is required. Install now? [Y/n]${NC}" read -rp "> " confirm; confirm="${confirm,,}" if [[ "$confirm" =~ ^(y|yes| )?$ ]]; then sudo apt update && sudo apt install -y python3-pip else echo -e "${RED}⚠️ Cannot proceed without pip3. Exiting.${NC}"; exit 1 fi fi } function clone_and_setup() { echo -e "${GREEN}📥 Cloning repo...${NC}" rm -rf "$CLONE_DIR" git clone "$REPO_URL" "$CLONE_DIR" || { echo -e "${RED}❌ git clone failed${NC}"; return; } cd "$CLONE_DIR" echo -e "${GREEN}📦 Installing Python dependencies...${NC}" pip3 install -r requirements.txt echo -e "${YELLOW}📨 Enter your Telegram bot token:${NC}" read -rp "🔑 TELEGRAM_TOKEN: " token echo -e "${YELLOW}🤖 Auto-detecting your Telegram chat ID...${NC}" auto_chat_id=$(python3 - </dev/null | grep -v "$CRON_NAME"; echo "*/$interval * * * * cd $(pwd)/$CLONE_DIR && python3 bot.py >> cron.log 2>&1") | crontab - echo -e "${GREEN}✅ Cronjob set for every $interval min.${NC}" fi fi read -rp "$(echo -e "${GREEN}🔁 Press Enter to return...${NC}")" } function remove_cronjob() { crontab -l | grep -v "$CRON_NAME" | crontab - echo -e "${GREEN}✅ Cronjob removed.${NC}" read -rp "$(echo -e "${GREEN}🔁 Press Enter to return...${NC}")" } while true; do clear; banner; check_requirements echo -e "${YELLOW}1. Install bot and configure" echo -e "2. Run bot manually now" echo -e "3. Setup new cronjob" echo -e "4. Remove existing cronjob" echo -e "5. Exit${NC}" read -rp "$(echo -e "${YELLOW}🔗 Choose [1-5]: ${NC}")" choice case $choice in 1) clone_and_setup ;; 2) run_bot_now ;; 3) setup_cronjob ;; 4) remove_cronjob ;; 5) echo -e "${RED}❌ Exiting...${NC}"; exit 0 ;; *) echo -e "${RED}❌ Invalid option.${NC}"; sleep 1 ;; esac done