Update nfs host example setup script.

This commit is contained in:
2026-06-08 20:29:17 +00:00
parent bee49690f8
commit d38fae74d4

View File

@@ -8,16 +8,18 @@ SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")" PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
usage() { usage() {
echo "Usage: setup-nfs-host.sh [server] [media-path] [options]" echo "Usage: setup-nfs-host.sh [server] [media-path]"
echo "" echo ""
echo "Set up NFS server on the specified host." echo "Set up NFS server on the specified host."
echo "" echo ""
echo "Creates a 'wildcloud' system user and exports the media path with"
echo "all_squash so all NFS clients write as 'wildcloud' on the server."
echo ""
echo "Examples:" echo "Examples:"
echo " setup-nfs-host.sh box-01 /data/media" echo " setup-nfs-host.sh box-01 /data/media"
echo "" echo ""
echo "Options:" echo "Options:"
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo " -e, --export-options Set the NFS export options"
} }
@@ -28,15 +30,6 @@ while [[ $# -gt 0 ]]; do
usage usage
exit 0 exit 0
;; ;;
-e|--export-options)
if [[ -z "$2" ]]; then
echo "Error: --export-options requires a value"
exit 1
else
NFS_EXPORT_OPTIONS="$2"
fi
shift 2
;;
-*) -*)
echo "Unknown option $1" echo "Unknown option $1"
usage usage
@@ -75,15 +68,8 @@ if [[ -z "${NFS_MEDIA_PATH}" ]]; then
exit 1 exit 1
fi fi
# Set default for NFS_EXPORT_OPTIONS if not already set
if [[ -z "${NFS_EXPORT_OPTIONS}" ]]; then
export NFS_EXPORT_OPTIONS="*(rw,sync,no_subtree_check,no_root_squash)"
echo "Using default NFS_EXPORT_OPTIONS: ${NFS_EXPORT_OPTIONS}"
fi
echo "Target NFS host: ${NFS_HOST}" echo "Target NFS host: ${NFS_HOST}"
echo "Media path: ${NFS_MEDIA_PATH}" echo "Media path: ${NFS_MEDIA_PATH}"
echo "Export options: ${NFS_EXPORT_OPTIONS}"
# Function to check if we're running on the correct host # Function to check if we're running on the correct host
check_host() { check_host() {
@@ -120,27 +106,38 @@ install_nfs_server() {
fi fi
} }
# Function to create wildcloud system user
create_wildcloud_user() {
if id wildcloud >/dev/null 2>&1; then
echo "wildcloud user already exists: $(id wildcloud)"
else
echo "Creating wildcloud system user..."
sudo useradd --system --no-create-home --shell /bin/false wildcloud
echo "Created wildcloud user: $(id wildcloud)"
fi
}
# Function to create media directory # Function to create media directory
create_media_directory() { create_media_directory() {
echo "Creating media directory: ${NFS_MEDIA_PATH}" echo "Creating media directory: ${NFS_MEDIA_PATH}"
# Create directory if it doesn't exist
sudo mkdir -p "${NFS_MEDIA_PATH}" sudo mkdir -p "${NFS_MEDIA_PATH}"
sudo chown -R wildcloud:wildcloud "${NFS_MEDIA_PATH}"
# Set appropriate permissions
# Using 755 for directory, allowing read/execute for all, write for owner
sudo chmod 755 "${NFS_MEDIA_PATH}" sudo chmod 755 "${NFS_MEDIA_PATH}"
echo "Media directory created with appropriate permissions" echo "Media directory created:"
echo "Directory info:" ls -la "$(dirname "${NFS_MEDIA_PATH}")/"
ls -la "${NFS_MEDIA_PATH}/"
} }
# Function to configure NFS exports # Function to configure NFS exports
configure_nfs_exports() { configure_nfs_exports() {
echo "Configuring NFS exports..." echo "Configuring NFS exports..."
local export_line="${NFS_MEDIA_PATH} ${NFS_EXPORT_OPTIONS}" local uid gid
uid=$(id -u wildcloud)
gid=$(id -g wildcloud)
local export_options="*(rw,sync,no_subtree_check,all_squash,anonuid=${uid},anongid=${gid})"
local export_line="${NFS_MEDIA_PATH} ${export_options}"
local exports_file="/etc/exports" local exports_file="/etc/exports"
# Backup existing exports file # Backup existing exports file
@@ -264,7 +261,8 @@ show_usage_instructions() {
echo echo
echo "=== NFS/SMB Host Setup Complete ===" echo "=== NFS/SMB Host Setup Complete ==="
echo echo
echo "NFS and SMB servers are now running on this host with media directory: ${NFS_MEDIA_PATH}" echo "NFS and SMB servers are now running on this host."
echo "Media directory: ${NFS_MEDIA_PATH} (owned by wildcloud, uid=$(id -u wildcloud))"
echo echo
echo "Access methods:" echo "Access methods:"
echo "1. NFS (for Kubernetes): Use setup-nfs-k8s.sh to register with cluster" echo "1. NFS (for Kubernetes): Use setup-nfs-k8s.sh to register with cluster"
@@ -293,6 +291,7 @@ show_usage_instructions() {
main() { main() {
check_host check_host
install_nfs_server install_nfs_server
create_wildcloud_user
create_media_directory create_media_directory
configure_nfs_exports configure_nfs_exports
start_nfs_services start_nfs_services