Refactor deploy-to-opt.sh and fix-npm-cache.sh to set HOME environment variable during npm cache configuration, ensuring correct usage of custom cache directory and improving .npmrc management.

This commit is contained in:
Torsten Schulz (local)
2025-12-04 17:03:56 +01:00
parent 34df89c1ac
commit 9aef5ef901
2 changed files with 30 additions and 6 deletions

View File

@@ -30,10 +30,10 @@ echo "✓ Cache-Verzeichnis erstellt"
echo "Setze npm Cache-Konfiguration..."
npm config set cache "$NPM_CACHE_DIR" --global 2>/dev/null || true
# Setze npm Cache für www-data
# Setze npm Cache für www-data (mit HOME gesetzt, damit npm nicht /var/www/.npmrc verwendet)
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'"
sudo -u $USER bash -c "HOME='$TARGET_DIR' npm config set cache '$NPM_CACHE_DIR'"
sudo -u $USER bash -c "cd '$TARGET_DIR/client' && HOME='$TARGET_DIR' npm config set cache '$NPM_CACHE_DIR'"
echo "✓ npm Cache konfiguriert"
@@ -46,6 +46,28 @@ else
echo " /var/www/.npm existiert nicht (ok, wird nicht benötigt)"
fi
# Repariere /var/www/.npmrc falls vorhanden
if [ -f "/var/www/.npmrc" ]; then
echo "Repariere /var/www/.npmrc Berechtigungen..."
chown $USER:$GROUP "/var/www/.npmrc" 2>/dev/null || true
chmod 644 "/var/www/.npmrc" 2>/dev/null || true
echo "✓ /var/www/.npmrc repariert"
else
echo " /var/www/.npmrc existiert nicht (wird erstellt falls nötig)"
# Erstelle .npmrc in /var/www mit korrekten Berechtigungen
touch "/var/www/.npmrc" 2>/dev/null || true
chown $USER:$GROUP "/var/www/.npmrc" 2>/dev/null || true
chmod 644 "/var/www/.npmrc" 2>/dev/null || true
fi
# Erstelle lokale .npmrc im App-Verzeichnis
echo "Erstelle lokale .npmrc im App-Verzeichnis..."
cat > "$TARGET_DIR/.npmrc" << EOF
cache=$NPM_CACHE_DIR
EOF
chown $USER:$GROUP "$TARGET_DIR/.npmrc"
echo "✓ Lokale .npmrc erstellt"
echo ""
echo "=========================================="
echo "npm Cache repariert!"
@@ -53,6 +75,8 @@ echo "=========================================="
echo ""
echo "Du kannst jetzt die Installation fortsetzen:"
echo " cd $TARGET_DIR"
echo " sudo -u $USER npm run install:all"
echo " sudo -u $USER bash -c \"HOME='$TARGET_DIR' npm run install:all\""
echo ""
echo "Oder verwende das deploy-to-opt.sh Skript erneut."
echo ""