diff options
Diffstat (limited to 'mknfs')
| -rwxr-xr-x | mknfs | 56 |
1 files changed, 56 insertions, 0 deletions
| @@ -0,0 +1,56 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # Configures and exports an NFS share | ||
| 4 | |||
| 5 | help() { | ||
| 6 | echo "usage: mknfs --clients nfs_client --path nfs_path"\ | ||
| 7 | "[--options \"opt1,opt2,opt3...\"] [--sec sec_option] [-f]" | ||
| 8 | echo "\n-c, --clients\tNFS export client" | ||
| 9 | echo "-f, --force\tmake directory if it doesn't exist" | ||
| 10 | echo "-o, --options\tAdditional NFS export options - quoted and comma separated" | ||
| 11 | echo "-p, --path\tPath of directory to be exported - must be absolute" | ||
| 12 | echo "-s, --sec\tNFS security settings - defaults to sys" | ||
| 13 | echo "\nexample: mknfs --clients server.example.com --path /srv/nfs/backups"\ | ||
| 14 | "--options \"crossmnt,async\" --sec krb5p" | ||
| 15 | exit | ||
| 16 | } | ||
| 17 | |||
| 18 | opts=$(getopt -o "c:,f,h,o:,p:,s:" -l "clients:,force, help,options:,path:,sec:" -- "$@") | ||
| 19 | eval set -- "$opts" | ||
| 20 | clients= | ||
| 21 | options="" | ||
| 22 | path= | ||
| 23 | sec="sys" | ||
| 24 | force=0 | ||
| 25 | while true | ||
| 26 | do | ||
| 27 | case "$1" in | ||
| 28 | '-c' | '--clients') clients="$2" shift 2; continue ;; | ||
| 29 | '-f' | '--force') force=1 shift; continue ;; | ||
| 30 | '-o' | '--options') options="$2" shift 2; continue ;; | ||
| 31 | '-p' | '--path') path="$2" shift 2; continue ;; | ||
| 32 | '-s' | '--sec') sec="$2" shift 2; continue ;; | ||
| 33 | '-h' | '--help') help ;; | ||
| 34 | '--') shift; break ;; | ||
| 35 | esac | ||
| 36 | done | ||
| 37 | [ -z "$clients" ] && help | ||
| 38 | [ -z "$path" ] && help | ||
| 39 | |||
| 40 | # Validate path | ||
| 41 | [ "$(echo $path | cut -d'/' -f1)" != "" ] && | ||
| 42 | echo "error: path is not absolute" && exit 1 | ||
| 43 | [ ! -d $path -a $force -eq 0 ] && | ||
| 44 | echo "error: directory does not exist (use -f to create)" && exit 1 | ||
| 45 | [ ! -d $path -a $force -eq 1 ] && mkdir -p $path | ||
| 46 | |||
| 47 | # Set some sane defaults if no options are specified | ||
| 48 | [ "$options" = "" ] && options="rw,sync,no_subtree_check" | ||
| 49 | |||
| 50 | # Make sure security option is valid | ||
| 51 | [ $sec != "sys" -a $sec != "krb5" -a $sec != "krb5i" -a $sec != "krb5p" ] && | ||
| 52 | echo "error: invalid security option - must be one of sys,krb5,krb5i,krb5p" | ||
| 53 | |||
| 54 | echo "$path\t$clients(sec=$sec,$options)" >> /etc/exports | ||
| 55 | exportfs -au | ||
| 56 | exportfs -ar | ||
