Files
singlechat/fix-npm-cache.sh

59 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 ""