# Install mariadb-server
sudo apt-get install -y mariadb-server
# Install pip
sudo apt-get install -y python3-pip
# Install requirements
sudo pip3 install -r requirements.txt

# Execute SQL commands
sudo mysql -u root -p << EOF
CREATE USER 'bot'@'localhost' IDENTIFIED BY 'secret';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'bot'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
CREATE DATABASE vpn_shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EOF


# Create service file
echo "[Unit]
Description=VPN BOT
After=network.target mariadb.service

[Service]
ExecStart=/usr/bin/python3 /root/_bot/bot.py
WorkingDirectory=/root/_bot
User=root
Group=root
Restart=always

[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/VPNBot.service

# Add to auto-run bot
sudo systemctl daemon-reload
sudo systemctl enable VPNBot
sudo systemctl start VPNBot