97 lines
2.7 KiB
Bash
Executable File
97 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# PointCab Webexport Server - Installationsscript
|
|
# Für Ubuntu 24.04 LTS
|
|
|
|
set -e
|
|
|
|
# Farben für Output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}========================================${NC}"
|
|
echo -e "${GREEN}PointCab Webexport Server Installation${NC}"
|
|
echo -e "${GREEN}========================================${NC}"
|
|
echo ""
|
|
|
|
# Root-Check
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo -e "${RED}Bitte als Root ausführen: sudo ./install.sh${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Variablen
|
|
INSTALL_DIR="/var/www/pointcab_webexport_server"
|
|
DB_NAME="pointcab_db"
|
|
DB_USER="pointcab_user"
|
|
|
|
# Passwort abfragen
|
|
read -sp "PostgreSQL-Passwort für $DB_USER: " DB_PASS
|
|
echo ""
|
|
read -sp "Admin-Passwort für Dashboard: " ADMIN_PASS
|
|
echo ""
|
|
read -sp "Session-Secret (mind. 32 Zeichen): " SESSION_SECRET
|
|
echo ""
|
|
|
|
echo -e "\n${YELLOW}[1/8] System aktualisieren...${NC}"
|
|
apt update && apt upgrade -y
|
|
|
|
echo -e "\n${YELLOW}[2/8] PostgreSQL installieren...${NC}"
|
|
apt install -y postgresql postgresql-contrib
|
|
systemctl start postgresql
|
|
systemctl enable postgresql
|
|
|
|
echo -e "\n${YELLOW}[3/8] Datenbank einrichten...${NC}"
|
|
sudo -u postgres psql <<EOF
|
|
CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';
|
|
CREATE DATABASE $DB_NAME OWNER $DB_USER;
|
|
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
|
|
EOF
|
|
|
|
echo -e "\n${YELLOW}[4/8] Node.js installieren...${NC}"
|
|
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
|
apt install -y nodejs
|
|
|
|
echo -e "\n${YELLOW}[5/8] PM2 installieren...${NC}"
|
|
npm install -g pm2
|
|
|
|
echo -e "\n${YELLOW}[6/8] Projekt einrichten...${NC}"
|
|
mkdir -p $INSTALL_DIR
|
|
cp -r nodejs_space $INSTALL_DIR/
|
|
mkdir -p $INSTALL_DIR/backups
|
|
mkdir -p $INSTALL_DIR/nodejs_space/uploads
|
|
|
|
# .env erstellen
|
|
cat > $INSTALL_DIR/nodejs_space/.env << EOF
|
|
PORT=3000
|
|
NODE_ENV=production
|
|
DATABASE_URL="postgresql://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME"
|
|
UPLOAD_DIR=$INSTALL_DIR/nodejs_space/uploads
|
|
SESSION_SECRET=$SESSION_SECRET
|
|
ADMIN_PASSWORD=$ADMIN_PASS
|
|
EOF
|
|
|
|
echo -e "\n${YELLOW}[7/8] Abhängigkeiten installieren und kompilieren...${NC}"
|
|
cd $INSTALL_DIR/nodejs_space
|
|
npm install
|
|
npx prisma generate
|
|
npx prisma db push
|
|
npm run build
|
|
|
|
echo -e "\n${YELLOW}[8/8] PM2 starten...${NC}"
|
|
pm2 start dist/main.js --name pointcab-server
|
|
pm2 startup
|
|
pm2 save
|
|
|
|
echo ""
|
|
echo -e "${GREEN}========================================${NC}"
|
|
echo -e "${GREEN}Installation abgeschlossen!${NC}"
|
|
echo -e "${GREEN}========================================${NC}"
|
|
echo ""
|
|
echo -e "Server läuft auf: ${YELLOW}http://localhost:3000${NC}"
|
|
echo -e "Admin-Dashboard: ${YELLOW}http://localhost:3000/admin/dashboard${NC}"
|
|
echo ""
|
|
echo -e "PM2 Status: ${YELLOW}pm2 status${NC}"
|
|
echo -e "PM2 Logs: ${YELLOW}pm2 logs pointcab-server${NC}"
|
|
echo "" |