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