Files
init.sh/modules/conf_nfs.sh

67 lines
2.1 KiB
Bash

# ------------------------------------------------------------------------------
# Configure NFS mounts
# This file is part of the init.sh project
# Copyright (c) 2019-2023 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Variable list:
# * NFS_MOUNTS: list of mounts used in other variable names
# * MOUNTSERV_<mnt>: server acces to mount <mnt>
# * MOUNTPOINT_<mnt>: mount point for <mnt>
# * MOUNTOPTS_<mnt>: optionnaly, extra mount options for <mnt>
# ("defaults,_netdev" by default)
# ------------------------------------------------------------------------------
# Module version
export VER_conf_nfs="0.0.3"
# Module's code
conf_nfs()
{
pkginst nfs-common
for mnt in $NFS_MOUNTS; do
local mnt_serv=$(eval echo \$MOUNTSERV_$mnt)
local mnt_point=$(eval echo \$MOUNTPOINT_$mnt)
local mnt_opts=$(eval echo \$MOUNTOPTS_$mnt)
if [[ $(echo $mnt_opts | wc -w) == "0" ]]; then
mnt_opts="defaults,_netdev"
fi
if [[ -z $(grep "$mnt_serv" /etc/fstab) ]]; then
echo -e "${mnt_serv}\t${mnt_point}\tnfs4\t${mnt_opts}\t0\t0" >> /etc/fstab
fi
unset mnt_serv
if [[ ! -d $mnt_point ]]; then
mkdir -pv "$mnt_point"
fi
mount -v "$mnt_point"
unset mnt_point
done
}
# Preliminary checks code for the module
precheck_conf_nfs()
{
if [[ -n $NFS_MOUNTS ]]; then
for mnt in $NFS_MOUNTS; do
if [[ -z $(eval echo \$MOUNTSERV_$mnt) ]]; then
prnt E "The server mount for $NFS_MOUNT is not declared."
die 182
fi
if [[ -z $(eval echo \$MOUNTPOINT_$mnt) ]]; then
prnt E "The mountpoint for $NFS_MOUNT is not declared."
die 183
fi
prnt I "NFS server $(eval echo \$MOUNTSERV_$mnt) will be mounted on $(eval echo \$MOUNTPOINT_$mnt)."
done
fi
}
# Public functions might be exported
export -f conf_nfs
export -f precheck_conf_nfs
# EOF