diff --git a/install.sh b/install.sh index e6be294..e30dba6 100644 --- a/install.sh +++ b/install.sh @@ -43,18 +43,16 @@ function check_and_install_docker() { function menu() { echo -e "${YELLOW}1. Install bot (clone + build)" - echo -e "2. Enable .log file logging" - echo -e "3. Setup new cronjob (every X min)" - echo -e "4. Show current cronjobs" - echo -e "5. Remove existing cronjob" - echo -e "6. Exit${NC}" + echo -e "2. Check bot status + send test Telegram message" + echo -e "3. Enable .log file logging" + echo -e "4. Setup new cronjob (every X min)" + echo -e "5. Show current cronjobs" + echo -e "6. Remove existing cronjob" + echo -e "7. Exit${NC}" echo "" } function set_telegram_credentials() { - # REMOVE THIS LINE: - # cd "$CLONE_DIR" || exit 1 - echo -e "${YELLOW}📨 Enter your Telegram bot token:${NC}" read -rp "🔑 TELEGRAM_TOKEN: " token echo -e "${YELLOW}👥 Enter your Telegram chat ID:${NC}" @@ -64,7 +62,6 @@ function set_telegram_credentials() { echo -e "${GREEN}✅ Credentials updated in bot.py${NC}" } - function clone_and_build() { if [ -d "$CLONE_DIR" ]; then echo -e "${RED}⚠️ Folder '$CLONE_DIR' already exists.${NC}" @@ -85,7 +82,6 @@ function clone_and_build() { set_telegram_credentials } - function enable_logging() { cd "$CLONE_DIR" || exit 1 sed -i '1s|^|exec > >(tee -a /app/bot.log) 2>&1\n|' bot.py @@ -117,18 +113,39 @@ function remove_cronjob() { echo -e "${GREEN}🗑️ Cronjob removed.${NC}" } +function check_bot_status() { + if [ ! -d "$CLONE_DIR" ]; then + echo -e "${RED}❌ Folder '$CLONE_DIR' not found. Please install the bot first.${NC}" + return + fi + + cd "$CLONE_DIR" || exit 1 + + if ! docker images | grep -q "$CRON_NAME"; then + echo -e "${RED}❌ Docker image '$CRON_NAME' not found. Please build it first.${NC}" + return + fi + + echo -e "${GREEN}✅ Docker image found.${NC}" + echo -e "${YELLOW}📨 Running the bot once to send a test Telegram message...${NC}" + docker compose run --rm "$CRON_NAME" + echo -e "${GREEN}✅ Done. If your Telegram is configured, you should receive a message now.${NC}" +} + +# Main menu loop while true; do clear banner menu - read -rp "$(echo -e "${YELLOW}👉 Choose [1-6]: ${NC}")" choice + read -rp "$(echo -e "${YELLOW}👉 Choose [1-7]: ${NC}")" choice case $choice in 1) clone_and_build ;; - 2) enable_logging ;; - 3) setup_cronjob ;; - 4) show_cronjobs ;; - 5) remove_cronjob ;; - 6) echo -e "${RED}❌ Exiting...${NC}"; exit 0 ;; + 2) check_bot_status ;; + 3) enable_logging ;; + 4) setup_cronjob ;; + 5) show_cronjobs ;; + 6) remove_cronjob ;; + 7) echo -e "${RED}❌ Exiting...${NC}"; exit 0 ;; *) echo -e "${RED}❌ Invalid option.${NC}" ;; esac read -rp "$(echo -e "${GREEN}🔁 Press Enter to continue...${NC}")"