-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-user-add
executable file
·99 lines (75 loc) · 2.75 KB
/
cluster-user-add
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
#!/bin/bash
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run via sudo"
exit 1
fi
if [ $# -ne 2 ]
then
echo "Usage: $0 newusername MGBID"
exit 1
fi
if [[ $HOSTNAME != "mickey" ]]; then
echo "This script must be run on mickey."
exit 1
fi
if [[ ! "$1" =~ ^[a-z0-9]+$ ]]; then
echo "The input '$1' contains invalid characters."
exit 1
fi
if id "$1" &>/dev/null; then
echo "The id '$1' already exists."
exit 1
fi
U=$1
MGBID=$2
CMSH=/cm/local/apps/cmd/bin/cmsh
output=$(ldapsearch -y ~ddrucker/.ldpass -LLL -H ldap://ldap.partners.org:389 -D cn=so175,cn=users,dc=partners,dc=org -b"cn=users,dc=partners,dc=org" "(cn=$MGBID)" mail displayName)
if [ -z "$output" ]; then
displayName=NOT-FOUND
mail=NOT-FOUND
else
displayName=$(echo "$output" | grep -i displayName | sed 's/displayName: //')
mail=$(echo "$output" | grep -i mail | sed 's/mail: //' | tr 'A-Z' 'a-z')
fi
echo "Name: $displayName"
echo "Mail: $mail"
echo If these are incorrect, control-c now. Otherwise, hit return.
read
$CMSH -c "user; add ${U}; set loginshell /bin/tcsh; set email $mail ; set surname $MGBID ; set commonname \"$displayName\" ; set password; commit;"
chown -R $U:$U /home/$U
cp /home/proto/.cshrc /home/proto/.cshrc.local /home/$U
cp /home/proto/.bash_profile /home/$U
cp /home/proto/.bashrc /home/$U
chown $U:$U /home/$U/.cshrc* /home/$U/.bash*
## create nisaba dataset
API_KEY=$(cat ~ddrucker/truenas/apikey.txt)
API_URL="https://nisaba.mclean.harvard.edu/api/v2.0"
POOL_DATASET_PATH="Pool1/cluster-n/$U"
curl --insecure -H "Authorization: Bearer $API_KEY" -X POST "${API_URL}/pool/dataset" -d '{"name":"'${POOL_DATASET_PATH}'"}'
curl --insecure -H "Authorization: Bearer $API_KEY" -X POST "${API_URL}/sharing/nfs" \
-d '{
"paths": [ "/mnt/'${POOL_DATASET_PATH}'" ],
"hosts": [ "x5backup.mclean.harvard.edu" ],
"maproot_user": "root",
"networks": [ "172.16.4.0/24", "172.17.4.0/24" ]
}'
## mount nisaba dataset on mickey
MOUNT_POINT="/data/$U"
$CMSH -c "device; use mickey; fsmounts; add ${MOUNT_POINT} ; set device nisaba.cm.cluster:/mnt/${POOL_DATASET_PATH} ; set filesystem nfs; commit; commit"
while ! mount | grep "${POOL_DATASET_PATH} on"
do
echo waiting for mount of $U
sleep 5
done
chmod 770 ${MOUNT_POINT}
chown $U:$U ${MOUNT_POINT}
## mount on nodes
$CMSH -c "category ; foreach -v compute-2023-03-28 nogpu-20240316 (fsmounts; add ${MOUNT_POINT} ; set device nisaba.cm.cluster:/mnt/${POOL_DATASET_PATH} ; set filesystem nfs; commit; commit; commit;)"
## set up slurm
if getent group $U >/dev/null; then
echo Setting up slurm...
yes | sacctmgr add user $U Cluster=slurm Account=mic
yes | sacctmgr modify user $U set fairshare=100
fi
echo Now please run "su - $U" and make sure that worked.