Repository navigation
Expand file tree
/
Copy pathcreateuser
More file actions
executable file
·170 lines (149 loc) · 5.48 KB
/
Copy pathcreateuser
File metadata and controls
executable file
·170 lines (149 loc) · 5.48 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -e
set -o nounset
export LC_ALL=C
cluster_name="${CLUSTER_NAME:-}"
SGE_ACL=""
slurm_account=""
function is_member_of () {
local user="$1"
local group="$2"
local groups
groups="$(groups "${user}" 2>&1)"
groups="${groups#*:}"
grep -F -qw "${group}" <<< "${groups}"
}
# Make sure we have a userid to create
if [[ "$#" -ne "1" ]];
then
echo "Run \"createuser userid\"" 1>&2
exit 1
fi
username="$1"
# Check that the userid starts with a letter and is alphanumeric, 7 chars
if echo "$username" | grep -qE '^[[:lower:]][[:lower:][:digit:]]{6}$' ;
then
echo "Valid user string: ${username}" 1>&2
else
echo "Invalid user string: ${username}" 1>&2
echo "Run \"createuser userid\"" 1>&2
exit 1
fi
# Work out where we are
if [[ -n "$cluster_name" ]]; then
# Allow overriding cluster_name for testing/whatever
echo "Warning: cluster name overridden as \"$cluster_name\"" >&2
elif [[ -x /shared/ucl/sysops/libexec/clustname ]]; then
cluster_name="$(/shared/ucl/sysops/libexec/clustname)"
elif [[ -r /shared/ucl/etc/cluster_name ]]; then
cluster_name="$(cat /shared/ucl/etc/cluster_name)"
else
echo "Error: could not find a way to determine cluster name." >&2
exit 1
fi
case "$cluster_name" in
"kathleen")
SGE_ACL="Open"
slurm_account="allusers"
pag="pag-archpc-kathleen"
;;
"myriad")
SGE_ACL="Open"
slurm_account="allusers"
pag="pag-archpc-myriad"
;;
dev-*)
slurm_account="allusers"
pag="pag-archpc-hydra"
;;
"michael"|"young")
echo "Error: this is not the correct way to add users to the Young and Michael clusters." >&2
exit 1
;;
*)
echo "Error: unknown cluster: $cluster_name" >&2
exit 1
;;
esac
echo "creating account for ${username}"
if command -v qconf >/dev/null; then
if [[ -z "$SGE_ACL" ]]; then
echo "Error: detected SGE, but this cluster is not supposed to run SGE." >&2
exit 1
fi
# add user to PAG, but only if needed
if is_member_of "${username}" "${pag}"; then
echo "${username} is already member of ${pag}"
else
# we need to be in the right AD group to do the next bit
if ! is_member_of "$(whoami)" 'rg-arc-rc-hpc-groupsadmin'; then
echo "Error: you don't have permission to add users to the AD group" >&2
exit 1
fi
echo "About to add ${username} to AD group ${pag}."
echo " If you are prompted for a password, enter your own AD password,"
echo " and consider setting up ~/.config/modgroup.yml with the role account."
/shared/ucl/apps/cluster-bin/modgroup add "${username}" "${pag}"
fi
qconf -au "${username}" "$SGE_ACL"
elif command -v sacctmgr >/dev/null; then
if [[ -z "${slurm_account}" ]]; then
echo "Error: detected Slurm, but this cluster is not supposed to run Slurm." >&2
exit 1
fi
# source common functions
. /apps/cluster-scripts/slurm/functions.sh
# we need to be a Slurm operator
if ! slurm_am_operator; then
echo "Error: you must be a Slurm operator to add users" >&2
exit 1
fi
# add user to PAG, but only if needed
if is_member_of "${username}" "${pag}"; then
echo "${username} is already member of ${pag}"
else
# we need to be in the right AD group to do the next bit
if ! is_member_of "$(whoami)" 'rg-arc-rc-hpc-groupsadmin'; then
echo "Error: you don't have permission to add users to the AD group" >&2
exit 1
fi
echo "About to add ${username} to AD group ${pag}."
echo " If you are prompted for a password, enter your own AD password,"
echo " and consider setting up ~/.config/modgroup.yml with the role account."
/apps/cluster-bin/modgroup add "${username}" "${pag}"
fi
# add user to Slurm account
sacctmgr --immediate --quiet add user name="${username}" defaultaccount="${slurm_account}"
else
echo "Error: no mechanism for adding users found." >&2
exit 1
fi
RECIPIENT="${username}@ucl.ac.uk"
echo "Emailing user ${RECIPIENT}"
/usr/sbin/sendmail -t<<EOF
From: rc-support@ucl.ac.uk
To: ${RECIPIENT}
Subject: ${cluster_name^} account
We are happy to confirm that your account to use the Research Computing ${cluster_name^}
HPC cluster is now active. You should be able to log in within 5 minutes of
receiving this email.
Please find below some information to help get you get started in your use of
the system.
GETTING HELP
Information to help you get started in using ${cluster_name^} is available at
https://www.rc.ucl.ac.uk/docs/
including a user guide covering all of our systems.
ANNOUNCEMENTS
Emails relating to planned outages, service changes etc will be sent to the
${cluster_name}-users@ucl.ac.uk email list. You have been subscribed to this
list using the email address associated with your main UCL userid - please
make sure that you read all notices sent to this address promptly and
observe the requests/guidelines they contain.
If you use a different email address for most of your correspondence, it is
a condition of your account that you configure your UCL email account to
have email redirected to an address of your choosing.
Please see https://www.ucl.ac.uk/isd/how-to/set-forwarding-using-outlook-web-access-owa
for further information on email forwarding.
If you have any queries relating to this information please email the
support address rc-support@ucl.ac.uk.
EOF