Update deploy-to-opt.sh to enhance npm cache management by excluding .npm and .npm-cache directories, and setting a custom npm cache directory during dependency installation and client build.

This commit is contained in:
Torsten Schulz (local)
2025-12-04 17:01:51 +01:00
parent c63c26bfe4
commit 34df89c1ac
2 changed files with 75 additions and 3 deletions

58
fix-npm-cache.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
# Fix npm Cache-Berechtigungen für /opt/ypchat
set -e
TARGET_DIR="/opt/ypchat"
USER="www-data"
GROUP="www-data"
echo "=========================================="
echo "npm Cache-Berechtigungen reparieren"
echo "=========================================="
# Prüfe ob als root ausgeführt
if [ "$EUID" -ne 0 ]; then
echo "FEHLER: Dieses Skript muss als root ausgeführt werden!"
echo "Bitte führe aus: sudo ./fix-npm-cache.sh"
exit 1
fi
# Erstelle lokales npm Cache-Verzeichnis
NPM_CACHE_DIR="$TARGET_DIR/.npm-cache"
echo "Erstelle lokales npm Cache-Verzeichnis: $NPM_CACHE_DIR"
mkdir -p "$NPM_CACHE_DIR"
chown -R $USER:$GROUP "$NPM_CACHE_DIR"
echo "✓ Cache-Verzeichnis erstellt"
# Setze npm Cache für root (falls nötig)
echo "Setze npm Cache-Konfiguration..."
npm config set cache "$NPM_CACHE_DIR" --global 2>/dev/null || true
# Setze npm Cache für www-data
echo "Setze npm Cache für $USER..."
sudo -u $USER bash -c "npm config set cache '$NPM_CACHE_DIR'"
sudo -u $USER bash -c "cd '$TARGET_DIR/client' && npm config set cache '$NPM_CACHE_DIR'"
echo "✓ npm Cache konfiguriert"
# Optional: Repariere /var/www/.npm falls vorhanden
if [ -d "/var/www/.npm" ]; then
echo "Repariere /var/www/.npm Berechtigungen..."
chown -R $USER:$GROUP "/var/www/.npm" 2>/dev/null || true
echo "✓ /var/www/.npm repariert"
else
echo " /var/www/.npm existiert nicht (ok, wird nicht benötigt)"
fi
echo ""
echo "=========================================="
echo "npm Cache repariert!"
echo "=========================================="
echo ""
echo "Du kannst jetzt die Installation fortsetzen:"
echo " cd $TARGET_DIR"
echo " sudo -u $USER npm run install:all"
echo ""