# ------------------------------------------------------------------------------ # Configure NFS mounts # This file is part of the init.sh project # Copyright (c) 2019-2023 Geoffray Levasseur # ------------------------------------------------------------------------------ # 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_: server acces to mount # * MOUNTPOINT_: mount point for # * MOUNTOPTS_: optionnaly, extra mount options for # ("defaults,_netdev" by default) # ------------------------------------------------------------------------------ # Module version export VER_conf_nfs="0.0.2" # Module's code conf_nfs() { pkginst nfs-common for mnt in $NFS_MOUNTS; do local mnt_serv=${!MOUNTSERV_$mnt} local mnt_point="${!MOUNTPOINT_$mnt}" local mnt_opts=${!MOUNTOPTS_$mnt:-"defaults,_netdev"} 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 "$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