Files
Blitz-Proxy/core/scripts/telegrambot/runbot.sh
Whispering Wind ebe09cc3e7 Color
2024-08-07 15:14:44 +03:30

90 lines
2.2 KiB
Bash

#!/bin/bash
source /etc/hysteria/core/scripts/utils.sh
define_colors
install_dependencies() {
echo "Installing dependencies from /etc/hysteria/requirements.txt..."
if ! pip3 install -r /etc/hysteria/requirements.txt > /dev/null 2>&1; then
echo "Error: Failed to install dependencies. Please check the requirements file and try again."
exit 1
fi
echo -e "${green}Dependencies installed successfully. ${NC}"
}
update_env_file() {
local api_token=$1
local admin_user_ids=$2
cat <<EOL > /etc/hysteria/core/scripts/telegrambot/.env
API_TOKEN=$api_token
ADMIN_USER_IDS=[$admin_user_ids]
EOL
}
create_service_file() {
cat <<EOL > /etc/systemd/system/hysteria-bot.service
[Unit]
Description=Hysteria Telegram Bot
After=network.target
[Service]
ExecStart=/usr/bin/python3 /etc/hysteria/core/scripts/telegrambot/tbot.py
WorkingDirectory=/etc/hysteria/core/scripts/telegrambot
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
EOL
}
start_service() {
local api_token=$1
local admin_user_ids=$2
if systemctl is-active --quiet hysteria-bot.service; then
echo "The hysteria-bot.service is already running."
return
fi
install_dependencies
update_env_file "$api_token" "$admin_user_ids"
create_service_file
systemctl daemon-reload
systemctl enable hysteria-bot.service > /dev/null 2>&1
systemctl start hysteria-bot.service > /dev/null 2>&1
if systemctl is-active --quiet hysteria-bot.service; then
echo -e "${green}Hysteria bot setup completed. The service is now running. ${NC}"
echo -e "\n\n"
else
echo "Hysteria bot setup completed. The service failed to start."
fi
}
stop_service() {
systemctl stop hysteria-bot.service > /dev/null 2>&1
systemctl disable hysteria-bot.service > /dev/null 2>&1
rm -f /etc/hysteria/core/scripts/telegrambot/.env
echo -e "\n"
echo "Hysteria bot service stopped and disabled. .env file removed."
}
case "$1" in
start)
start_service "$2" "$3"
;;
stop)
stop_service
;;
*)
echo "Usage: $0 {start|stop} <API_TOKEN> <ADMIN_USER_IDS>"
exit 1
;;
esac
define_colors