conf_nfs: modernised code, added possibility to pass mount options

This commit is contained in:
2023-05-16 10:55:36 +02:00
parent 90e603be0c
commit e56dadbc2b

View File

@@ -1,28 +1,40 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Description of module conf_nfs # Configure NFS mounts
# Copyright (c) Year Your Name <your.mail@host.tld> # This file is part of the init.sh project
# Copyright (c) 2019-2023 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# <Licence header compatible with BSD-3 licence, you want to use> # 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: # Variable list:
# * <VARNAME>: role explaination # * 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 # Module version
export VER_conf_nfs="0.0.1" export VER_conf_nfs="0.0.2"
# Module's code # Module's code
conf_nfs() conf_nfs()
{ {
pkginst nfs-common pkginst nfs-common
for mnt in $NFS_MOUNTS; do for mnt in $NFS_MOUNTS; do
if [[ ! $(grep "$(eval echo \$MOUNTSERV_$mnt)/d" /etc/fstab) ]]; then local mnt_serv=${!MOUNTSERV_$mnt}
echo -e "$(eval echo \$MOUNTSERV_$mnt)\t$(eval echo \$MOUNTPOINT_$mnt)\tnfs4\tdefaults,_netdev\t0\t0" >> /etc/fstab local mnt_point=${!MOUNTPOINT_$mnt}
local mnt_opts=${!MOUNTOPTS_$mnt:-"defaults,_netdev"}
if [[ ! $(grep "$mnt_serv" /etc/fstab) ]]; then
echo -e "${mnt_serv}\t${mnt_point}\tnfs4\tdefaults,_netdev\t0\t0" >> /etc/fstab
fi fi
if [[ ! -d $(eval echo \$MOUNTPOINT_$mnt) ]]; then unset mnt_serv
mkdir -pv $(eval echo \$MOUNTPOINT_$mnt) if [[ ! -d $mnt_point ]]; then
mkdir -pv $mnt_point
fi fi
mount $(eval echo \$MOUNTPOINT_$mnt) mount $mnt_point
unset mnt_point
done done
} }