From 85c561f9a32f8f2b9ddf34e7d60ef4b7bf0d3680 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Fri, 15 Apr 2022 21:08:34 -0400 Subject: inital commit - various scripts --- mknfs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 mknfs (limited to 'mknfs') diff --git a/mknfs b/mknfs new file mode 100755 index 0000000..5b04a9f --- /dev/null +++ b/mknfs @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Configures and exports an NFS share + +help() { + echo "usage: mknfs --clients nfs_client --path nfs_path"\ + "[--options \"opt1,opt2,opt3...\"] [--sec sec_option] [-f]" + echo "\n-c, --clients\tNFS export client" + echo "-f, --force\tmake directory if it doesn't exist" + echo "-o, --options\tAdditional NFS export options - quoted and comma separated" + echo "-p, --path\tPath of directory to be exported - must be absolute" + echo "-s, --sec\tNFS security settings - defaults to sys" + echo "\nexample: mknfs --clients server.example.com --path /srv/nfs/backups"\ + "--options \"crossmnt,async\" --sec krb5p" + exit +} + +opts=$(getopt -o "c:,f,h,o:,p:,s:" -l "clients:,force, help,options:,path:,sec:" -- "$@") +eval set -- "$opts" +clients= +options="" +path= +sec="sys" +force=0 +while true +do + case "$1" in + '-c' | '--clients') clients="$2" shift 2; continue ;; + '-f' | '--force') force=1 shift; continue ;; + '-o' | '--options') options="$2" shift 2; continue ;; + '-p' | '--path') path="$2" shift 2; continue ;; + '-s' | '--sec') sec="$2" shift 2; continue ;; + '-h' | '--help') help ;; + '--') shift; break ;; + esac +done +[ -z "$clients" ] && help +[ -z "$path" ] && help + +# Validate path +[ "$(echo $path | cut -d'/' -f1)" != "" ] && + echo "error: path is not absolute" && exit 1 +[ ! -d $path -a $force -eq 0 ] && + echo "error: directory does not exist (use -f to create)" && exit 1 +[ ! -d $path -a $force -eq 1 ] && mkdir -p $path + +# Set some sane defaults if no options are specified +[ "$options" = "" ] && options="rw,sync,no_subtree_check" + +# Make sure security option is valid +[ $sec != "sys" -a $sec != "krb5" -a $sec != "krb5i" -a $sec != "krb5p" ] && + echo "error: invalid security option - must be one of sys,krb5,krb5i,krb5p" + +echo "$path\t$clients(sec=$sec,$options)" >> /etc/exports +exportfs -au +exportfs -ar -- cgit v1.2.3