#!/bin/sh
nfs_mount_opts='-nfsv4,gssname=host,sec=krb5p'
default_priv_quota=250G
default_pub_quota=10G
# Add /home autofs map.
ldap_add "automountKey=/home,automountMapName=auto_master,${automount_basedn}" <<EOF
objectClass: automount
automountKey: /home
automountInformation: auto_home ${nfs_mount_opts}
EOF
ldap_add "automountMapName=auto_home,${automount_basedn}" <<EOF
objectClass: automountMap
automountMapName: auto_home
EOF
ldap_add "automountKey=*,automountMapName=auto_home,${automount_basedn}" <<EOF
objectClass: automount
automountKey: *
automountInformation: ${fqdn}:/user/&/priv
EOF
# Create /- (direct) autofs map
ldap_add "automountKey=/-,automountMapName=auto_master,${automount_basedn}" <<EOF
objectClass: automount
automountKey: /-
automountInformation: auto_direct ${nfs_mount_opts}
EOF
ldap_add "automountMapName=auto_direct,${automount_basedn}" <<EOF
objectClass: automountMap
automountMapName: auto_direct
EOF
# Create /nfs/user autofs map.
ldap_add "automountKey=/nfs/user,automountMapName=auto_master,${automount_basedn}" <<EOF
objectClass: automount
automountKey: /nfs/user
automountInformation: auto_user ${nfs_mount_opts}
EOF
ldap_add "automountMapName=auto_user,${automount_basedn}" <<EOF
objectClass: automountMap
automountMapName: auto_user
EOF
# Create user home directories.
for userquota in ${nfs_homedirs:-}; do
user=$(echo "$userquota" | awk -F: '{print $1}')
privquota=$(echo "$userquota" | awk -F: '{print $2}')
pubquota=$(echo "$userquota" | awk -F: '{print $3}')
create_dataset -p "${nfs_dataset}/user/${user}/priv"
create_dataset -p "${nfs_dataset}/user/${user}/pub"
zfs set "refquota=${privquota:-$default_priv_quota}" "${nfs_dataset}/user/${user}/priv"
zfs set "refquota=${pubquota:-$default_pub_quota}" "${nfs_dataset}/user/${user}/pub"
chown "${user}:${user}" \
"${nfs_root}/user/${user}/priv" \
"${nfs_root}/user/${user}/pub"
chmod 700 "${nfs_root}/user/${user}/priv"
chmod 755 "${nfs_root}/user/${user}/pub"
# Create user autofs key.
ldap_add "automountKey=${user},automountMapName=auto_user,${automount_basedn}" <<EOF
objectClass: automount
automountKey: ${user}
automountInformation: /priv ${fqdn}:/user/&/priv /pub ${fqdn}:/user/&/pub
EOF
done
# Add /nfs/group autofs map.
ldap_add "automountKey=/nfs/group,automountMapName=auto_master,${automount_basedn}" <<EOF
objectClass: automount
automountKey: /nfs/group
automountInformation: auto_group ${nfs_mount_opts}
EOF
ldap_add "automountMapName=auto_group,${automount_basedn}" <<EOF
objectClass: automountMap
automountMapName: auto_group
EOF
# Create group home directories.
for groupquota in ${nfs_groupdirs:-}; do
group=$(echo "$groupquota" | awk -F: '{print $1}')
privquota=$(echo "$groupquota" | awk -F: '{print $2}')
pubquota=$(echo "$groupquota" | awk -F: '{print $3}')
create_dataset -p "${nfs_dataset}/group/${group}/priv"
create_dataset -p "${nfs_dataset}/group/${group}/pub"
zfs set "refquota=${privquota:-$default_priv_quota}" "${nfs_dataset}/group/${group}/priv"
zfs set "refquota=${pubquota:-$default_pub_quota}" "${nfs_dataset}/group/${group}/pub"
chown "root:${group}" \
"${nfs_root}/group/${group}/priv" \
"${nfs_root}/group/${group}/pub"
chmod 770 "${nfs_root}/group/${group}/priv"
chmod 775 "${nfs_root}/group/${group}/pub"
# Create group autofs key.
ldap_add "automountKey=${group},automountMapName=auto_group,${automount_basedn}" <<EOF
objectClass: automount
automountKey: ${group}
automountInformation: /priv ${fqdn}:/group/&/priv /pub ${fqdn}:/group/&/pub
EOF
done
# Add /nfs/media autofs map.
ldap_add "automountMapName=auto_media,${automount_basedn}" <<EOF
objectClass: automountMap
automountMapName: auto_media
EOF
ldap_add "automountKey=/nfs/media,automountMapName=auto_master,${automount_basedn}" <<EOF
objectClass: automount
automountKey: /nfs/media
automountInformation: auto_media ${nfs_mount_opts}
EOF
# Create music dataset.
create_dataset -p "${nfs_dataset}/media/music"
# Set music ACLs.
chgrp media-admin "${nfs_root}/media/music"
chmod 770 "${nfs_root}/media/music"
# Create music autofs key.
ldap_add "automountKey=music,automountMapName=auto_media,${automount_basedn}" <<EOF
objectClass: automount
automountKey: music
automountInformation: ${fqdn}:/media/music
EOF