#!/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