summaryrefslogtreecommitdiff
path: root/mknfs
diff options
context:
space:
mode:
Diffstat (limited to 'mknfs')
-rwxr-xr-xmknfs56
1 files changed, 56 insertions, 0 deletions
diff --git a/mknfs b/mknfs
new file mode 100755
index 0000000..5b04a9f
--- /dev/null
+++ b/mknfs
@@ -0,0 +1,56 @@
1#!/bin/sh
2#
3# Configures and exports an NFS share
4
5help() {
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
18opts=$(getopt -o "c:,f,h,o:,p:,s:" -l "clients:,force, help,options:,path:,sec:" -- "$@")
19eval set -- "$opts"
20clients=
21options=""
22path=
23sec="sys"
24force=0
25while true
26do
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
36done
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
54echo "$path\t$clients(sec=$sec,$options)" >> /etc/exports
55exportfs -au
56exportfs -ar