Files
HomeLabScripts/nfs/server.sh

38 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
echo "📦 NFS Server Setup für globalen Share"
# ───── Eingabe: Freizugebender Ordner ─────
read -p "📁 Welcher Ordner soll für ALLE Nutzer freigegeben werden? (z.B. /srv/nfs/global): " NFS_DIR
# ───── Verzeichnis vorbereiten ─────
if [ ! -d "$NFS_DIR" ]; then
echo "📁 Erstelle Verzeichnis $NFS_DIR..."
mkdir -p "$NFS_DIR"
fi
# ───── Zugriffsrechte setzen ─────
chown nobody:nogroup "$NFS_DIR"
chmod 777 "$NFS_DIR" # Jeder kann lesen, schreiben und ausführen
# ───── Lokales Subnetz erkennen ─────
LOCAL_SUBNET=$(ip route | awk '/src/ {print $1; exit}')
# ───── /etc/exports vorbereiten ─────
EXPORT_LINE="$NFS_DIR $LOCAL_SUBNET(rw,sync,no_subtree_check,no_root_squash)"
if ! grep -qF "$EXPORT_LINE" /etc/exports; then
echo "$EXPORT_LINE" >> /etc/exports
echo "✅ Export hinzugefügt: $EXPORT_LINE"
else
echo " Export existiert bereits."
fi
# ───── NFS-Dienste neu laden ─────
exportfs -ra
systemctl restart nfs-kernel-server
echo ""
echo "🚀 NFS-Share '$NFS_DIR' ist jetzt aktiv für Subnetz: $LOCAL_SUBNET"
echo "👥 Zugriff: Alle Nutzer, ohne Einschränkung auf UID oder Gruppe"