Update install.sh

This commit is contained in:
2025-06-19 13:53:38 +00:00
parent 512c9aa896
commit e35e9955c0

View File

@@ -48,7 +48,6 @@ function check_requirements() {
echo -e "${RED}Not present${NC}"
fi
# Prompt installation if needed
if [ "$PYTHON_OK" = false ]; then
echo -e "${YELLOW}❓ Python3 is required. Do you want to install it now? [Y/n]${NC}"
read -rp "> " confirm
@@ -72,7 +71,83 @@ function check_requirements() {
fi
}
# (Die restlichen Funktionen wie clone_and_setup, run_bot_now, setup_cronjob, etc. bleiben gleich)
function clone_and_setup() {
echo -e "${GREEN}📥 Cloning repo...${NC}"
rm -rf "$CLONE_DIR"
git clone "$REPO_URL" "$CLONE_DIR"
cd "$CLONE_DIR" || exit 1
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 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}"
cd ..
read -rp "$(echo -e "${GREEN}🔁 Press Enter to return to the main menu...${NC}")"
}
function run_bot_now() {
if [ ! -f "$CLONE_DIR/bot.py" ]; then
echo -e "${RED}❌ Bot not installed. Please run option 1 first.${NC}"
else
echo -e "${YELLOW}⚙️ Running bot.py...${NC}"
python3 "$CLONE_DIR/bot.py"
fi
read -rp "$(echo -e "${GREEN}🔁 Press Enter to return to the main menu...${NC}")"
}
function setup_cronjob() {
echo -e "${YELLOW}Setting up cronjob...${NC}"
if [ ! -d "$CLONE_DIR" ]; then
echo -e "${RED}❌ Bot not installed. Run option 1 first.${NC}"
else
echo -e "${YELLOW}⏱ How often should the bot run? (in minutes, 1-60)${NC}"
read -rp "Interval: " interval
if ! [[ "$interval" =~ ^[0-9]+$ ]] || [ "$interval" -lt 1 ] || [ "$interval" -gt 60 ]; then
echo -e "${RED}❌ Invalid input. Must be between 1 and 60.${NC}"
else
(crontab -l 2>/dev/null | grep -v "$CRON_NAME"; echo "*/$interval * * * * cd $(pwd)/$CLONE_DIR && python3 bot.py >> cron.log 2>&1") | crontab -
echo -e "${GREEN}✅ Cronjob installed to run every $interval minute(s).${NC}"
fi
fi
read -rp "$(echo -e "${GREEN}🔁 Press Enter to return to the main menu...${NC}")"
}
function remove_cronjob() {
echo -e "${YELLOW}Removing bot cronjob...${NC}"
crontab -l 2>/dev/null | grep -v "$CRON_NAME" | crontab -
echo -e "${GREEN}✅ Cronjob removed.${NC}"
read -rp "$(echo -e "${GREEN}🔁 Press Enter to return to the main menu...${NC}")"
}
while true; do
clear
@@ -87,7 +162,7 @@ while true; do
read -rp "$(echo -e "${YELLOW}🔗 Choose [1-5]: ${NC}")" choice
case $choice in
1) clone_and_setup ;; # wird weiter oben definiert
1) clone_and_setup ;;
2) run_bot_now ;;
3) setup_cronjob ;;
4) remove_cronjob ;;