Plex-Telegram-Bot/setup.sh

80 lines
2.5 KiB
Bash

#!/bin/bash
# Überprüfen, ob Node.js installiert ist
if ! command -v node &> /dev/null; then
echo "Node.js ist nicht installiert. Installiere Node.js automatisch..."
# Automatische Installation von Node.js, abhängig vom Linux-System
if command -v apt &> /dev/null; then
sudo apt update
sudo apt install -y nodejs
elif command -v yum &> /dev/null; then
sudo yum install -y nodejs
else
echo "Automatische Installation von Node.js wird nicht unterstützt. Bitte installieren Sie Node.js manuell und führen Sie das Skript erneut aus."
exit 1
fi
fi
# Überprüfen, ob npm installiert ist
if ! command -v npm &> /dev/null; then
echo "npm ist nicht installiert. Installiere npm automatisch..."
sudo apt install -y npm
fi
# Laden Sie die Umgebungsvariablen aus der .env-Datei
source .env
# Erstellen Sie ein neues Node.js-Projekt mit npm init und verwenden Sie Umgebungsvariablen
echo -e "Creating a new Node.js project..."
echo -e "Project name: $PROJECT_NAME"
echo -e "Version: 1.0.0"
echo -e "Description: Node.js project"
echo -e "Entry point: plex-bot.js"
echo -e "Test command: "
echo -e "Git repository: "
echo -e "Keywords: "
echo -e "Author: M_Viper"
echo -e "License: ISC"
# npm init -y sollte ohne sudo ausgeführt werden, um Probleme mit Dateiberechtigungen zu vermeiden
sudo npm init -y
# Installieren Sie die benötigten Pakete, einschließlich node-telegram-bot-api
sudo npm install
sudo npm install ping
sudo npm install node-telegram-bot-api
sudo npm install js-yaml
sudo npm install moment
sudo npm install yaml
sudo npm install dotenv
sudo npm install fs
sudo npm install request
sudo npm install nodemailer
sudo npm install axios
sudo npm install body-parser
sudo npm install express
sudo npm install path
sudo npm install yamljs
sudo npm install date-fns
sudo npm install yml
sudo npm install node-cache
sudo npm install node-schedule
sudo npm install dayjs
# Installieren Sie pm2, wenn es noch nicht installiert ist
if ! command -v pm2 &> /dev/null; then
sudo npm install -g pm2
fi
# Erstellen Sie ein Startskript für den Bot
echo -e "Creating start script..."
echo -e "#!/bin/bash\n\npm2 start plex-bot.js" > start_bot.sh
chmod +x start_bot.sh
# Erstellen Sie ein Autostart-Skript für den Bot
echo -e "Creating autostart script..."
echo -e "[Unit]\nDescription=Telegram Plex Bot\n\n[Service]\nExecStart=$(pwd)/start_bot.sh\n\n[Install]\nWantedBy=default.target" > telegram_bot.service
sudo mv telegram_bot.service /etc/systemd/system/
sudo systemctl enable telegram_bot