Files
HomeLabScripts/nfs/nfsClient2.sh
2025-04-28 21:13:58 +02:00

39 lines
1.3 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.
#!/bin/bash
# ==== Konfigurierbare Standardwerte ====
SERVER_IP="192.168.178.132"
REMOTE_PATH="fastData"
LOCAL_MOUNT="/fastData"
AUTO_MOUNT="${AUTO_MOUNT:-}"
# ==== Interaktive Abfrage, falls Variablen fehlen ====
[[ -z "$SERVER_IP" ]] && read -rp "Server-IP-Adresse: " SERVER_IP
[[ -z "$REMOTE_PATH" ]] && read -rp "Remote NFS Pfad (z.B. /fastData): " REMOTE_PATH
[[ -z "$LOCAL_MOUNT" ]] && read -rp "Lokales Mount-Verzeichnis (z.B. /mnt/nfs): " LOCAL_MOUNT
[[ -z "$AUTO_MOUNT" ]] && read -rp "Automatisch beim Booten mounten? (ja/nein): " AUTO_MOUNT
# ==== Verzeichnis vorbereiten ====
sudo mkdir -p "$LOCAL_MOUNT"
# Mount durchführen
echo "Mounten von $SERVER_IP:$REMOTE_PATH nach $LOCAL_MOUNT ..."
sudo mount -t nfs "$SERVER_IP:$REMOTE_PATH" "$LOCAL_MOUNT"
if [[ $? -ne 0 ]]; then
echo "❌ Fehler beim Mounten!"
exit 1
fi
# Berechtigungen setzen, damit jeder schreiben darf
sudo chmod 777 "$LOCAL_MOUNT"
echo "✅ Erfolgreich gemountet. Alle Benutzer haben vollen Zugriff auf $LOCAL_MOUNT"
# ==== Automatisches Mounten einrichten ====
if [[ "$AUTO_MOUNT" == "ja" ]]; then
echo "Füge Mount zur /etc/fstab hinzu..."
LINE="$SERVER_IP:$REMOTE_PATH $LOCAL_MOUNT nfs defaults,_netdev 0 0"
grep -qxF "$LINE" /etc/fstab || echo "$LINE" | sudo tee -a /etc/fstab
echo "✅ Automatisches Mounten aktiviert."
fi