diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..53f15c8 --- /dev/null +++ b/setup.sh @@ -0,0 +1,80 @@ +#!/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 # Oder passen Sie dies an Ihr System an +fi + +# Eingabe des Dateinamens für das Node.js-Projekt +read -p "Geben Sie den Namen der .js-Datei für Ihr Node.js-Projekt ein (ohne die Dateiendung): " FILE_NAME + +# 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" # Version anpassen +echo -e "Description: Node.js project" +echo -e "Entry point: $FILE_NAME.js" +echo -e "Test command: " +echo -e "Git repository: " +echo -e "Keywords: " +echo -e "Author: M_Viper" # Author anpassen +echo -e "License: ISC" # License anpassen + +# 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 + +# 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 $FILE_NAME.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 Support 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 + +# Erstellen Sie das start_bot.sh-Skript +echo -e "Creating start_bot.sh script..." +echo -e "#!/bin/bash\n\npm2 start $FILE_NAME.js" > start_bot.sh +chmod +x start_bot.js + +echo "Das Skript wurde erfolgreich erstellt. Verwenden Sie start_bot.sh, um Ihren Bot zu starten."