Update install.sh
This commit is contained in:
164
install.sh
164
install.sh
@@ -1,142 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
REPO_URL="https://git.bitmaster.cc/BitMaster/tesla-bot.git"
|
||||
CLONE_DIR="tesla-bot"
|
||||
CRON_NAME="tesla-inventory-bot"
|
||||
# MAIN LOOP
|
||||
while true; do
|
||||
clear
|
||||
banner
|
||||
system_status
|
||||
echo -e "${YELLOW}1. Install bot (clone + build)"
|
||||
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 ""
|
||||
read -rp "$(echo -e "${YELLOW}🔗 Choose [1-7]: ${NC}")" choice
|
||||
|
||||
GREEN="\e[32m"
|
||||
RED="\e[31m"
|
||||
YELLOW="\e[33m"
|
||||
NC="\e[0m"
|
||||
case $choice in
|
||||
1) clone_and_build ;;
|
||||
2) run_bot_once ;;
|
||||
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}"; sleep 1 ;;
|
||||
esac
|
||||
|
||||
function banner() {
|
||||
echo -e "${GREEN}"
|
||||
echo "=============================="
|
||||
echo "🚗 Tesla Inventory Bot Setup"
|
||||
echo "=============================="
|
||||
echo -e "${NC}"
|
||||
}
|
||||
|
||||
function system_status() {
|
||||
echo -e "${YELLOW}...checking system status...${NC}"
|
||||
|
||||
echo -n "📦 Docker: "
|
||||
if command -v docker &>/dev/null; then
|
||||
echo -e "${GREEN}Installed${NC}"
|
||||
docker_status="ok"
|
||||
else
|
||||
echo -e "${RED}Missing${NC}"
|
||||
docker_status="missing"
|
||||
fi
|
||||
|
||||
echo -n "🐳 Docker Compose: "
|
||||
if docker compose version &>/dev/null; then
|
||||
echo -e "${GREEN}Available (v2)${NC}"
|
||||
compose_status="ok"
|
||||
else
|
||||
echo -e "${RED}Missing or incompatible${NC}"
|
||||
compose_status="missing"
|
||||
fi
|
||||
|
||||
echo -n "📁 Project folder '$CLONE_DIR': "
|
||||
if [ -d "$CLONE_DIR" ]; then
|
||||
echo -e "${YELLOW}Exists${NC}"
|
||||
folder_status="exists"
|
||||
else
|
||||
echo -e "${GREEN}Not present${NC}"
|
||||
folder_status="missing"
|
||||
fi
|
||||
|
||||
echo -n "📦 Docker image '$CRON_NAME': "
|
||||
if docker images --format '{{.Repository}}' | grep -q "$CRON_NAME"; then
|
||||
echo -e "${YELLOW}Already built${NC}"
|
||||
image_status="built"
|
||||
else
|
||||
echo -e "${RED}Not built${NC}"
|
||||
image_status="missing"
|
||||
fi
|
||||
|
||||
echo -n "📦 Docker container '$CRON_NAME': "
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^$CRON_NAME$"; then
|
||||
echo -e "${RED}Not running${NC}"
|
||||
container_status="exists"
|
||||
else
|
||||
echo -e "${GREEN}Not running${NC}"
|
||||
container_status="missing"
|
||||
fi
|
||||
}
|
||||
|
||||
function clone_and_build() {
|
||||
check_and_install_docker
|
||||
|
||||
if [ "$folder_status" = "exists" ] || [ "$image_status" = "built" ]; then
|
||||
echo -e "${YELLOW}⚠️ Project folder or image already exists.${NC}"
|
||||
read -rp "$(echo -e "${YELLOW}🔁 Do you want to reinstall everything? This will remove old data. [Y/n] ${NC}")" confirm
|
||||
confirm="${confirm,,}"
|
||||
if [[ "$confirm" =~ ^(y|yes| )?$ ]]; then
|
||||
echo -e "${YELLOW}🧹 Cleaning up...${NC}"
|
||||
docker rm -f "$CRON_NAME" >/dev/null 2>&1
|
||||
docker rmi -f "$CRON_NAME" >/dev/null 2>&1
|
||||
rm -rf "$CLONE_DIR"
|
||||
echo -e "${GREEN}✅ Cleaned up previous install.${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Installation aborted.${NC}"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}📥 Cloning repo...${NC}"
|
||||
git clone "$REPO_URL" "$CLONE_DIR"
|
||||
cd "$CLONE_DIR" || exit 1
|
||||
echo -e "${GREEN}🔧 Building Docker image...${NC}"
|
||||
docker compose build
|
||||
|
||||
echo -e "${YELLOW}📨 Enter your Telegram bot token:${NC}"
|
||||
read -rp "🔑 TELEGRAM_TOKEN: " token
|
||||
|
||||
echo -e "${YELLOW}🤖 Auto detecting the Telegram chat-ID...${NC}"
|
||||
auto_chat_id=$(curl -s "https://api.telegram.org/bot$token/getUpdates" | grep -oE '"id":[0-9-]+' | head -n1 | cut -d: -f2)
|
||||
|
||||
if [ -n "$auto_chat_id" ]; then
|
||||
echo -e "${GREEN}✅ Auto-detected chat ID: $auto_chat_id${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Could not auto-detect chat ID. You may enter it manually.${NC}"
|
||||
fi
|
||||
|
||||
read -rp "🆔 TELEGRAM_CHAT_ID [default: $auto_chat_id]: " chat_id
|
||||
chat_id="${chat_id:-$auto_chat_id}"
|
||||
|
||||
if [ -z "$chat_id" ]; then
|
||||
echo -e "${RED}❌ No chat ID provided or detected. Aborting.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -i "s|^TELEGRAM_TOKEN = .*|TELEGRAM_TOKEN = \"$token\"|" bot.py
|
||||
sed -i "s|^CHAT_ID = .*|CHAT_ID = \"$chat_id\"|" bot.py
|
||||
echo -e "${GREEN}✅ Credentials updated in bot.py${NC}"
|
||||
|
||||
echo -e "${YELLOW}📤 Sending test Telegram message...${NC}"
|
||||
curl -s -X POST "https://api.telegram.org/bot$token/sendMessage" \
|
||||
-d chat_id="$chat_id" \
|
||||
-d text="✅ Tesla bot kuruldu ve Telegram bağlantısı başarılı!" \
|
||||
-d parse_mode="HTML" > /dev/null
|
||||
echo -e "${GREEN}✅ Test message sent. Check your Telegram!${NC}"
|
||||
|
||||
read -rp "$(echo -e "${GREEN}🔁 Press Enter to return to the main menu...${NC}")"
|
||||
}
|
||||
|
||||
function run_bot_once() {
|
||||
echo -e "${YELLOW}🔍 Checking bot status...${NC}"
|
||||
if [ ! -f "$CLONE_DIR/bot.py" ]; then
|
||||
echo -e "${RED}❌ Bot not installed. Please run option 1 first.${NC}"
|
||||
else
|
||||
echo -e "${GREEN}📤 Running the bot in Docker to send test message...${NC}"
|
||||
docker compose -f "$CLONE_DIR/docker-compose.yml" run --rm "$CRON_NAME"
|
||||
status=$?
|
||||
if [ $status -eq 0 ]; then
|
||||
echo -e "${GREEN}✅ Bot ran successfully. Check your Telegram!${NC}"
|
||||
elif [ $status -eq 137 ]; then
|
||||
echo -e "${RED}⚠️ Bot was terminated early. It may have been interrupted (e.g., Ctrl+C).${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Bot failed to run. Check Docker logs or credentials.${NC}"
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user