-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
68 lines (56 loc) · 2.15 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# شناسایی سیستم عامل
OS=$(cat /etc/os-release | grep -w ID | cut -d '=' -f 2 | tr -d '"')
# دریافت اطلاعات لازم از کاربر
read -p "Please enter your Telegram bot token: " BOT_TOKEN
read -p "Please enter your authorized user ID (your Telegram numeric ID): " AUTHORIZED_USER_ID
read -p "Please enter your MySQL username: " MYSQL_USER
read -p "Please enter your MySQL password: " MYSQL_PASSWORD
read -p "Please enter your MySQL database name: " MYSQL_DB
read -p "Please enter your MySQL database host (e.g., localhost): " MYSQL_HOST
# تنظیم پیکربندیها در فایل config.cfg با اضافه کردن بخش [DEFAULT]
cat <<EOL >config.cfg
[DEFAULT]
BOT_TOKEN=$BOT_TOKEN
AUTHORIZED_USER_ID=$AUTHORIZED_USER_ID
DB_USER=$MYSQL_USER
DB_PASSWORD=$MYSQL_PASSWORD
DB_NAME=$MYSQL_DB
DB_HOST=$MYSQL_HOST
EOL
# نصب پیشنیازها
if [[ "$OS" == "ubuntu" || "$OS" == "debian" ]]; then
echo "Ubuntu or Debian detected. Installing dependencies..."
apt update -y
apt install -y curl python3-pip mariadb-client libmariadb-dev
elif [[ "$OS" == "centos" || "$OS" == "rhel" ]]; then
echo "CentOS or RHEL detected. Installing dependencies..."
yum update -y
yum install -y curl python3-pip mariadb mariadb-devel
else
echo "Unsupported operating system: $OS"
exit 1
fi
# نصب کتابخانههای پایتون با استفاده از مسیر کامل به فایل requirements.txt
pip3 install -r /root/telegram-backup-bot/requirements.txt
# ایجاد سرویس systemd
cat <<EOL >/etc/systemd/system/telegram-backup-bot.service
[Unit]
Description=Telegram Backup Bot
After=network.target
[Service]
ExecStart=/usr/bin/python3 /root/telegram-backup-bot/telegram_bot.py
WorkingDirectory=/root/telegram-backup-bot
StandardOutput=journal
StandardError=journal
Restart=on-failure
User=root
[Install]
WantedBy=multi-user.target
EOL
# بارگذاری مجدد systemd و فعال کردن سرویس
systemctl daemon-reload
systemctl enable telegram-backup-bot.service
systemctl start telegram-backup-bot.service
# بررسی وضعیت سرویس
systemctl status telegram-backup-bot.service