aboutsummaryrefslogtreecommitdiff
path: root/scripts/hostname/nfs1
blob: 673c7a916d4e8d5e68e571d1cda96e65053be915 (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/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