#!/bin/bash # # LibreBooking n8n Node - Installations-Skript für Linux/Mac # # Verwendung: # chmod +x install.sh # ./install.sh # # Optionen: # --no-link Überspringt npm link (nur Build) # --global Installiert global statt npm link # --help Zeigt diese Hilfe an # set -e # Farben für Ausgabe RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Konfiguration MIN_NODE_VERSION=18 REQUIRED_NPM_VERSION=8 # Optionen SKIP_LINK=false GLOBAL_INSTALL=false # Funktionen print_header() { echo -e "${BLUE}" echo "=============================================" echo " LibreBooking n8n Node Installer" echo "=============================================" echo -e "${NC}" } print_success() { echo -e "${GREEN}✓ $1${NC}" } print_warning() { echo -e "${YELLOW}⚠ $1${NC}" } print_error() { echo -e "${RED}✗ $1${NC}" } print_info() { echo -e "${BLUE}ℹ $1${NC}" } show_help() { echo "Verwendung: ./install.sh [OPTIONEN]" echo "" echo "Optionen:" echo " --no-link Überspringt npm link (nur Build)" echo " --global Installiert global mit npm install -g" echo " --help Zeigt diese Hilfe an" echo "" echo "Beispiele:" echo " ./install.sh # Standard-Installation mit npm link" echo " ./install.sh --no-link # Nur Dependencies installieren und Build" echo " ./install.sh --global # Globale Installation" exit 0 } check_command() { if command -v $1 &> /dev/null; then return 0 else return 1 fi } get_node_version() { node -v | sed 's/v//' | cut -d. -f1 } get_npm_version() { npm -v | cut -d. -f1 } # Parameter verarbeiten for arg in "$@"; do case $arg in --no-link) SKIP_LINK=true ;; --global) GLOBAL_INSTALL=true ;; --help|-h) show_help ;; *) print_error "Unbekannte Option: $arg" show_help ;; esac done # Start print_header # 1. Node.js prüfen echo "" print_info "Prüfe Voraussetzungen..." echo "" if ! check_command node; then print_error "Node.js ist nicht installiert!" echo " Bitte installiere Node.js v${MIN_NODE_VERSION} oder höher:" echo " https://nodejs.org/" exit 1 fi NODE_VERSION=$(get_node_version) if [ "$NODE_VERSION" -lt "$MIN_NODE_VERSION" ]; then print_error "Node.js Version $NODE_VERSION ist zu alt!" echo " Mindestens Version ${MIN_NODE_VERSION} benötigt." exit 1 fi print_success "Node.js v$(node -v | sed 's/v//') gefunden" # 2. npm prüfen if ! check_command npm; then print_error "npm ist nicht installiert!" exit 1 fi print_success "npm v$(npm -v) gefunden" # 3. n8n prüfen (optional, aber empfohlen) if check_command n8n; then print_success "n8n $(n8n --version 2>/dev/null || echo 'installiert') gefunden" else print_warning "n8n ist nicht global installiert." echo " Für npm link muss n8n global installiert sein:" echo " npm install -g n8n" echo "" if [ "$SKIP_LINK" = false ] && [ "$GLOBAL_INSTALL" = false ]; then read -p "Möchtest du trotzdem fortfahren? (j/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Jj]$ ]]; then exit 1 fi fi fi # 4. Dependencies installieren echo "" print_info "Installiere Dependencies..." npm install print_success "Dependencies installiert" # 5. TypeScript kompilieren echo "" print_info "Kompiliere TypeScript..." npm run build print_success "Build erfolgreich" # 6. npm link oder global install if [ "$GLOBAL_INSTALL" = true ]; then echo "" print_info "Installiere global..." npm install -g . print_success "Global installiert" elif [ "$SKIP_LINK" = false ]; then echo "" print_info "Verlinke mit npm link..." npm link print_success "npm link erfolgreich" # Prüfen ob n8n vorhanden und linken if check_command n8n; then N8N_PATH=$(npm root -g)/n8n if [ -d "$N8N_PATH" ]; then print_info "Verlinke mit n8n..." cd "$N8N_PATH" 2>/dev/null && npm link n8n-nodes-librebooking 2>/dev/null && cd - > /dev/null print_success "Mit n8n verlinkt" fi fi fi # Abschluss echo "" echo -e "${GREEN}=============================================${NC}" echo -e "${GREEN} Installation erfolgreich abgeschlossen!${NC}" echo -e "${GREEN}=============================================${NC}" echo "" echo "Nächste Schritte:" echo "" if [ "$SKIP_LINK" = true ]; then echo " 1. Führe 'npm link' aus, um den Node zu verlinken" echo " 2. Starte n8n neu: n8n start" else echo " 1. Starte n8n neu: n8n start" echo " (oder mit Docker: docker-compose restart)" fi echo "" echo " 2. Öffne n8n im Browser: http://localhost:5678" echo " 3. Der LibreBooking Node sollte verfügbar sein" echo "" echo "Bei Problemen siehe INSTALLATION.md oder README.md" echo ""