blob: 6856c7213df586de321287b019fabd820260c07e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/usr/bin/env bash
playbook_add() {
pkg install nfs-utils
touch /etc/exports
playbook_sync
svc enable nfs
svc enable rpcbind
svc start nfs
svc start rpcbind
}
playbook_sync() {
local buffer="$(tmpfile)"
local exports="/etc/exports.d/kubernetes.exports"
local hash="$(file_hash "$exports")"
local root_options="ro,no_subtree_check"
local export_options="rw,no_root_squash,no_subtree_check"
local root_export="/mnt/exports"
local allowed_cidr=("10.57.0.0/16" "172.19.0.0/16")
local fsid
{
printf "%s" "$root_export"
for host in "${allowed_cidr[@]}"
do
printf " %s(fsid=%s,%s)" "$host" "0" "$export_options"
done
printf "\n"
for path in "$root_export"/*
do
fsid="$(config "$BASHTARD_PLAYBOOK.exports.$path.fsid" "")"
if [[ "$fsid" == "" ]]
then
warn "$BASHTARD_PLAYBOOK" "Generating fsid for $path"
fsid="$(uuidgen)"
$BASHTARD_BIN var "$BASHTARD_PLAYBOOK.exports.$path.fsid" "$fsid"
fi
printf "%s" "$path"
for host in "${allowed_cidr[@]}"
do
printf " %s(fsid=%s,%s)" "$host" "$fsid" "$export_options"
done
printf "\n"
unset fsid
done
} > "$buffer"
[[ "$(file_hash "$buffer")" == "$hash" ]] && return
mv -- "$buffer" "$exports"
[[ "$BASHTARD_ACTION" == "add" ]] && return
exportfs -rv
}
playbook_del() {
svc stop rpcbind
svc stop nfs
svc disable rpcbind
svc disable nfs
pkg uninstall nfs-utils
}
|