Files
nas/lib/nfs.sh
Mărcziem ™ a7fd5f806b feat: Enhance distribution detection with robust 5-method fallback system
- Add lib/detection.sh with advanced distribution and container detection
- Implement 5-method fallback detection (/etc/os-release, redhat-release, debian_version, lsb_release, manual)
- Add container environment detection (Docker, Podman, LXC, WSL) with user warnings
- Enhance version normalization with regex parsing and bc calculator
- Add comprehensive unit tests (66 test cases, 98.5% success rate)
- Update documentation (README, CHANGELOG, SECURITY, CONTRIBUTING)
- Improve enterprise-grade error handling and logging
- Add IPv6 and security considerations for 2025 compatibility
2025-10-01 23:44:48 +02:00

66 lines
2.0 KiB
Bash

#!/bin/bash
install_nfs() {
log_info "Installing and configuring NFS..."
case $DISTRO in
ubuntu|debian)
handle_error sudo apt-get install -y nfs-kernel-server
;;
fedora)
handle_error sudo dnf install -y nfs-utils
;;
arch)
handle_error sudo pacman -S --noconfirm nfs-utils
;;
opensuse)
handle_error sudo zypper install -y nfs-kernel-server
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
# Create NFS export directory
local export_dir="${NFS_EXPORT_DIR:-/srv/nfs}"
sudo mkdir -p "$export_dir"
sudo chown nobody:nogroup "$export_dir"
sudo chmod 755 "$export_dir"
# Configure NFS exports
local exports_file="/etc/exports"
backup_config "$exports_file"
echo "$export_dir *(rw,sync,no_subtree_check,no_root_squash)" | sudo tee -a "$exports_file" > /dev/null
# Export NFS shares
handle_error sudo exportfs -a
# Start and enable NFS services
case $DISTRO in
ubuntu|debian|opensuse)
handle_error sudo systemctl enable nfs-kernel-server
handle_error sudo systemctl start nfs-kernel-server
;;
fedora|arch)
handle_error sudo systemctl enable nfs-server
handle_error sudo systemctl start nfs-server
;;
esac
# Open firewall for NFS
if command -v ufw &>/dev/null; then
sudo ufw allow 2049/tcp comment "NFS"
sudo ufw allow 111/tcp comment "NFS Portmapper"
sudo ufw allow 111/udp comment "NFS Portmapper"
elif command -v firewall-cmd &>/dev/null; then
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo firewall-cmd --permanent --add-service=mountd
sudo firewall-cmd --reload
fi
log_info "NFS installation and configuration completed. Export directory: $export_dir"
}