-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmkhubgrp
executable file
·76 lines (64 loc) · 2.33 KB
/
mkhubgrp
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
#!/bin/bash
# This script makes a group for a thlj instance, that users can be added
# to to facilitate sharing of notebooks and documents.
#
# The group is named `hub_<grpname>`, where <grpname> is a one-word string
# passed to this command as its first and only argument.
#
# A group folder is created at `/opt/hubshare/<grpname>` and two subfolders
# are created:
# 1) `shared` any documents copied to this folder can be modified by all
# members of the group.
# 2) `published` documents created in subfolders of this folder can not be
# modified or deleted by other members of the group, only the owner.
# However, all members of the group can read and copy these documents.
# Documents should not be saved directly in the `published`
# folder because any member of the group can delete them, but not edit.
#
# This script needs to be run before adding users to the group `hub_<grpname>`
# and before running the script `lnhubgrp`, which makes the shared folder
# visible in each group members home directory.
#
# Jonathan Gutow <gutow@uwosh.edu>
# June 2020
# license: GPLV3+
GRP="hub_"$1
if [[ -z $1 ]]; then
echo "mkhubgrp takes one argument a name for the group with no spaces."
exit 1
fi
if [[ ! -d "/opt/hubshare" ]]; then
mkdir /opt/hubshare
chgrp jupyterhub-users /opt/hubshare
chmod u=rwx,g=rx,o=- /opt/hubshare
fi
if [[ -d "/opt/hubshare/$GRP" ]]; then
echo "The group "$GRP" already exists. Please choose another name."
exit 2
fi
# Now we can make the directories for sharing and publishing
# to the group.
GRPDIR="/opt/hubshare/"$1
SHARED=$GRPDIR"/shared"
PUBLISHED=$GRPDIR"/published"
mkdir $GRPDIR
mkdir $SHARED
mkdir $PUBLISHED
# make the group
groupadd $GRP
# Set permissions
chgrp $GRP $GRPDIR
chgrp $GRP $SHARED
chgrp $GRP $PUBLISHED
chmod u=rwx,g=rx,o=- $GRPDIR
chmod u=rwx,g=rwx,o=- $SHARED
chmod +s $SHARED # new subdirectories inherit permissions
setfacl -d -m g::rwX /$SHARED # new files are rwx for group.
chmod u=rwx,g=rwx,o=- $PUBLISHED
chmod +s $PUBLISHED # new subdirectories inherit permissions
echo "Created group: "$GRP
echo "Created group directory: "$GRPDIR
echo "Created directory for shared (group editable files): "$SHARED
echo "Created directory for group published files (creator only editable): "$PUBLISHED
echo "Add users to the group and a symlink in their home directory to allow use."
exit 0